Setting Up Test Data mor in a Unit way

This commit is contained in:
2020-09-12 08:39:06 +02:00
parent 18a597c726
commit 64c0c5f8e6
5 changed files with 94 additions and 13 deletions

View File

@@ -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()

View File

@@ -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()