|
|
|
@ -1,3 +1,5 @@ |
|
|
|
|
|
|
|
import tempfile |
|
|
|
|
|
|
|
|
|
|
|
from django.test import TestCase |
|
|
|
from django.test import TestCase |
|
|
|
from storage.api import add_comment, delete_comment, update_comment, get_comment |
|
|
|
from storage.api import add_comment, delete_comment, update_comment, get_comment |
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile |
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile |
|
|
|
@ -6,10 +8,14 @@ from storage.models import Comment |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CommentTestCase(TestCase): |
|
|
|
class CommentTestCase(TestCase): |
|
|
|
|
|
|
|
|
|
|
|
def setUp(self): |
|
|
|
def setUp(self): |
|
|
|
self.first_comment = add_comment("first comment", "vasia@rambler.ru") |
|
|
|
self.first_comment = add_comment("first comment", "vasia@rambler.ru") |
|
|
|
self.second_comment = add_comment(text="Привет, отличная работа", email="artem4000@gmail.com") |
|
|
|
self.second_comment = add_comment(text="Привет, отличная работа", email="artem4000@gmail.com") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def tearDown(self): |
|
|
|
|
|
|
|
Comment.objects.all().delete() |
|
|
|
|
|
|
|
|
|
|
|
def test_comment_get(self): |
|
|
|
def test_comment_get(self): |
|
|
|
self.assertEqual(self.first_comment, get_comment(self.first_comment.key)) |
|
|
|
self.assertEqual(self.first_comment, get_comment(self.first_comment.key)) |
|
|
|
|
|
|
|
|
|
|
|
@ -22,12 +28,13 @@ class CommentTestCase(TestCase): |
|
|
|
token = 'fskjfskj' |
|
|
|
token = 'fskjfskj' |
|
|
|
comment1 = add_comment(text=token, email="artem4000@gmail.com") |
|
|
|
comment1 = add_comment(text=token, email="artem4000@gmail.com") |
|
|
|
self.assertEqual(comment1.text, token) |
|
|
|
self.assertEqual(comment1.text, token) |
|
|
|
file_for_upload = SimpleUploadedFile('1.txt', 'Я файл!'.encode('utf-8')) |
|
|
|
with tempfile.gettempdir() as dir_path: |
|
|
|
file_name = 'Клёвый файл' |
|
|
|
file_for_upload = SimpleUploadedFile(dir_path + '/1.txt', 'Я файл!'.encode('utf-8')) |
|
|
|
object_for_upload = {'original': file_for_upload, 'name': file_name} |
|
|
|
file_name = 'Клёвый файл' |
|
|
|
comment2 = add_comment(text=token, email="artem4000@gmail.com", files=[object_for_upload]) |
|
|
|
object_for_upload = {'original': file_for_upload, 'name': file_name} |
|
|
|
self.assertEqual(comment2.files.count(), 1) |
|
|
|
comment2 = add_comment(text=token, email="artem4000@gmail.com", files=[object_for_upload]) |
|
|
|
self.assertEqual(comment2.files.all()[0].name, file_name) |
|
|
|
self.assertEqual(comment2.files.count(), 1) |
|
|
|
|
|
|
|
self.assertEqual(comment2.files.all()[0].name, file_name) |
|
|
|
|
|
|
|
|
|
|
|
def test_comment_delete(self): |
|
|
|
def test_comment_delete(self): |
|
|
|
delete_comment(self.first_comment.key) |
|
|
|
delete_comment(self.first_comment.key) |
|
|
|
|