diff --git a/lostplaces/lostplaces_app/tests/models/test_explorer_model.py b/lostplaces/lostplaces_app/tests/models/test_explorer_model.py index 0b39171..489529f 100644 --- a/lostplaces/lostplaces_app/tests/models/test_explorer_model.py +++ b/lostplaces/lostplaces_app/tests/models/test_explorer_model.py @@ -10,7 +10,7 @@ class ExplorerTestCase(TestCase): def setUpTestData(self): User.objects.create_user( username='testpeter', - + password='Develop123' ) def test_epxlorer_creation(self): diff --git a/lostplaces/lostplaces_app/tests/models/test_place_image_model.py b/lostplaces/lostplaces_app/tests/models/test_place_image_model.py index f3d9f85..c0231b2 100644 --- a/lostplaces/lostplaces_app/tests/models/test_place_image_model.py +++ b/lostplaces/lostplaces_app/tests/models/test_place_image_model.py @@ -7,10 +7,11 @@ from django.test import TestCase from django.db import models from django.core.files import File from django.conf import settings +from django.contrib.auth.models import User from lostplaces_app.models import PlaceImage, Place from lostplaces_app.tests.models import SubmittableTestCase -from lostplaces_app.tests.models.test_place_model Test +from lostplaces_app.tests.models.test_place_model import PlaceTestCase from easy_thumbnails.fields import ThumbnailerImageField @@ -19,8 +20,22 @@ class TestPlaceImage(SubmittableTestCase, TestCase): @classmethod def setUpTestData(cls): - - Place.setUpTestData() + user = User.objects.create_user( + username='testpeter', + password='Develop123' + ) + + place = Place.objects.create( + name='Im a place', + submitted_when=datetime.datetime.now(), + submitted_by=User.objects.get(username='testpeter').explorer, + location='Testtown', + latitude=50.5, + longitude=7.0, + description='This is just a test, do not worry' + ) + place.tags.add('I a tag', 'testlocation') + place.save() 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')): @@ -28,12 +43,13 @@ class TestPlaceImage(SubmittableTestCase, TestCase): os.path.join(current_dir, 'im_a_image.jpeg'), os.path.join(settings.MEDIA_ROOT, 'im_a_image_copy.jpeg') ) + PlaceImage.objects.create( description='Im a description', filename=os.path.join(settings.MEDIA_ROOT, 'im_a_image_copy.jpeg'), - place=Place.objects.get(id=1), + place=place, submitted_when=datetime.datetime.now(), - submitted_by=User.objects.get(username='testpeter').explorer + submitted_by=user.explorer ) def test_description(self): diff --git a/lostplaces/lostplaces_app/tests/models/test_place_model.py b/lostplaces/lostplaces_app/tests/models/test_place_model.py index de34ec9..6a1b53f 100644 --- a/lostplaces/lostplaces_app/tests/models/test_place_model.py +++ b/lostplaces/lostplaces_app/tests/models/test_place_model.py @@ -19,13 +19,15 @@ class PlaceTestCase(SubmittableTestCase, TestCase): @classmethod def setUpTestData(cls): - - BaseData.setUpTestData() - + user = User.objects.create_user( + username='testpeter', + password='Develop123' + ) + place = Place.objects.create( name='Im a place', submitted_when=datetime.datetime.now(), - submitted_by=User.objects.get(username='testpeter').explorer, + submitted_by=user.explorer, location='Testtown', latitude=50.5, longitude=7.0, @@ -74,9 +76,9 @@ class PlaceTestCase(SubmittableTestCase, TestCase): of 10 places ''' place_list = [] - place = Place.objects.get(id=1) - place.id = None for i in range(10): + place = Place.objects.get(id=1) + place.id = None place.latitude = i+1 place.longitude = i+10 place.save() diff --git a/lostplaces/lostplaces_app/tests/views/test_base_views.py b/lostplaces/lostplaces_app/tests/views/test_base_views.py index ab6ae96..244d51f 100644 --- a/lostplaces/lostplaces_app/tests/views/test_base_views.py +++ b/lostplaces/lostplaces_app/tests/views/test_base_views.py @@ -1,5 +1,8 @@ +import datetime + from django.test import TestCase, Client from django.urls import reverse_lazy +from django.contrib.auth.models import User from lostplaces_app.models import Place @@ -7,6 +10,25 @@ from django.contrib.auth.models import User class TestIsAuthenticated(TestCase): + @classmethod + def setUpTestData(cls): + user = User.objects.create_user( + username='testpeter', + password='Develop123' + ) + + place = Place.objects.create( + name='Im a place', + submitted_when=datetime.datetime.now(), + submitted_by=User.objects.get(username='testpeter').explorer, + location='Testtown', + latitude=50.5, + longitude=7.0, + description='This is just a test, do not worry' + ) + place.tags.add('I a tag', 'testlocation') + place.save() + def setUp(self): self. client = Client() @@ -33,6 +55,25 @@ class TestIsAuthenticated(TestCase): class TestIsPlaceSubmitter(TestCase): + @classmethod + def setUpTestData(cls): + user = User.objects.create_user( + username='testpeter', + password='Develop123' + ) + + place = Place.objects.create( + name='Im a place', + submitted_when=datetime.datetime.now(), + submitted_by=user.explorer, + location='Testtown', + latitude=50.5, + longitude=7.0, + description='This is just a test, do not worry' + ) + place.tags.add('I a tag', 'testlocation') + place.save() + def setUp(self): self. client = Client() diff --git a/lostplaces/lostplaces_app/tests/views/test_place_views.py b/lostplaces/lostplaces_app/tests/views/test_place_views.py index 3ae6769..813b3b0 100644 --- a/lostplaces/lostplaces_app/tests/views/test_place_views.py +++ b/lostplaces/lostplaces_app/tests/views/test_place_views.py @@ -1,10 +1,32 @@ +import datetime + from django.test import TestCase, Client from django.urls import reverse_lazy +from django.contrib.auth.models import User from lostplaces_app.models import Place class TestPlaceCreateView(TestCase): - + + @classmethod + def setUpTestData(cls): + user = User.objects.create_user( + username='testpeter', + password='Develop123' + ) + + place = Place.objects.create( + name='Im a place', + submitted_when=datetime.datetime.now(), + submitted_by=user.explorer, + location='Testtown', + latitude=50.5, + longitude=7.0, + description='This is just a test, do not worry' + ) + place.tags.add('I a tag', 'testlocation') + place.save() + def setUp(self): self. client = Client()