Setting Up Test Data mor in a Unit way
This commit is contained in:
		@@ -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()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user