Trying to test deletion, wip
This commit is contained in:
parent
64ed38332f
commit
e655e1598a
@ -1,28 +1,39 @@
|
||||
import datetime
|
||||
import os
|
||||
import shutil
|
||||
from unittest import mock
|
||||
|
||||
from django.test import TestCase
|
||||
from django.db import models
|
||||
from django.core.files import File
|
||||
from django.conf import settings
|
||||
|
||||
from lostplaces_app.models import PlaceImage
|
||||
from lostplaces_app.tests.models import TestSubmittable
|
||||
from lostplaces_app.tests.models import SubmittableTestCase
|
||||
from lostplaces_app.tests import mock_user
|
||||
from lostplaces_app.tests.models import TestModel
|
||||
from lostplaces_app.tests.models.test_place_model import mock_place
|
||||
|
||||
from easy_thumbnails.fields import ThumbnailerImageField
|
||||
|
||||
def mock_place_image():
|
||||
return PlaceImage(
|
||||
description='Im a description',
|
||||
filename=mock.MagicMock(spec=File, name='FileMock'),
|
||||
place=mock_place(),
|
||||
submitted_when=datetime.datetime.now(),
|
||||
submitted_by=mock_user().explorer
|
||||
)
|
||||
all_place_images = PlaceImage.objects.all()
|
||||
if len(all_place_images) <= 0:
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
if not os.path.isfile(os.path.join(settings.MEDIA_ROOT, 'im_a_image_copy.jpeg')):
|
||||
shutil.copyfile(
|
||||
os.path.join(current_dir, 'im_a_image.jpeg'),
|
||||
os.path.join(settings.MEDIA_ROOT, 'im_a_image_copy.jpeg')
|
||||
)
|
||||
return PlaceImage.objects.create(
|
||||
description='Im a description',
|
||||
filename=os.path.join(settings.MEDIA_ROOT, 'im_a_image_copy.jpeg'),
|
||||
place=mock_place(),
|
||||
submitted_when=datetime.datetime.now(),
|
||||
submitted_by=mock_user().explorer
|
||||
)
|
||||
return all_place_images[0]
|
||||
|
||||
class TestPlaceImage(TestSubmittable, TestCase):
|
||||
class TestPlaceImage(SubmittableTestCase, TestCase):
|
||||
model_name = 'PlaceImage'
|
||||
|
||||
def setUp(self):
|
||||
@ -51,5 +62,18 @@ class TestPlaceImage(TestSubmittable, TestCase):
|
||||
)
|
||||
|
||||
def test_str(self):
|
||||
place_image = mock_place_image()
|
||||
self.assertEqual(str(place_image), ' '.join([place_image.place.name, str(place_image.pk)]))
|
||||
place_image = self.object
|
||||
self.assertTrue(place_image.place.name.lower() in str(place_image).lower(),
|
||||
msg='Expecting %s.__str__ to contain the name of the place' % (
|
||||
self.model_name
|
||||
)
|
||||
)
|
||||
|
||||
def test_deletion(self):
|
||||
# TODO
|
||||
path = self.object.filename.path
|
||||
self.object.delete()
|
||||
self.assertFalse(
|
||||
os.path.isfile(path),
|
||||
msg='Expecting the file of an place_image to be deleteed when an place_image is deleted'
|
||||
)
|
Loading…
Reference in New Issue
Block a user