Setting Up Test Data mor in a Unit way
This commit is contained in:
parent
18a597c726
commit
64c0c5f8e6
@ -10,7 +10,7 @@ class ExplorerTestCase(TestCase):
|
||||
def setUpTestData(self):
|
||||
User.objects.create_user(
|
||||
username='testpeter',
|
||||
|
||||
password='Develop123'
|
||||
)
|
||||
|
||||
def test_epxlorer_creation(self):
|
||||
|
@ -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):
|
||||
user = User.objects.create_user(
|
||||
username='testpeter',
|
||||
password='Develop123'
|
||||
)
|
||||
|
||||
Place.setUpTestData()
|
||||
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):
|
||||
|
@ -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 = []
|
||||
for i in range(10):
|
||||
place = Place.objects.get(id=1)
|
||||
place.id = None
|
||||
for i in range(10):
|
||||
place.latitude = i+1
|
||||
place.longitude = i+10
|
||||
place.save()
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user