Setting Up Test Data mor in a Unit way
This commit is contained in:
		@@ -10,7 +10,7 @@ class ExplorerTestCase(TestCase):
 | 
				
			|||||||
    def setUpTestData(self):
 | 
					    def setUpTestData(self):
 | 
				
			||||||
        User.objects.create_user(
 | 
					        User.objects.create_user(
 | 
				
			||||||
            username='testpeter',
 | 
					            username='testpeter',
 | 
				
			||||||
            
 | 
					            password='Develop123'
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_epxlorer_creation(self):
 | 
					    def test_epxlorer_creation(self):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,10 +7,11 @@ from django.test import TestCase
 | 
				
			|||||||
from django.db import models
 | 
					from django.db import models
 | 
				
			||||||
from django.core.files import File
 | 
					from django.core.files import File
 | 
				
			||||||
from django.conf import settings
 | 
					from django.conf import settings
 | 
				
			||||||
 | 
					from django.contrib.auth.models import User
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from lostplaces_app.models import PlaceImage, Place
 | 
					from lostplaces_app.models import PlaceImage, Place
 | 
				
			||||||
from lostplaces_app.tests.models import SubmittableTestCase
 | 
					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
 | 
					from easy_thumbnails.fields import ThumbnailerImageField
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,8 +20,22 @@ class TestPlaceImage(SubmittableTestCase, TestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def setUpTestData(cls):
 | 
					    def setUpTestData(cls):
 | 
				
			||||||
 | 
					        user = User.objects.create_user(
 | 
				
			||||||
        Place.setUpTestData()
 | 
					            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__))
 | 
					        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')):
 | 
					        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(current_dir, 'im_a_image.jpeg'),
 | 
				
			||||||
                os.path.join(settings.MEDIA_ROOT, 'im_a_image_copy.jpeg')
 | 
					                os.path.join(settings.MEDIA_ROOT, 'im_a_image_copy.jpeg')
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
        PlaceImage.objects.create(
 | 
					        PlaceImage.objects.create(
 | 
				
			||||||
            description='Im a description',
 | 
					            description='Im a description',
 | 
				
			||||||
            filename=os.path.join(settings.MEDIA_ROOT, 'im_a_image_copy.jpeg'),
 | 
					            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_when=datetime.datetime.now(),
 | 
				
			||||||
            submitted_by=User.objects.get(username='testpeter').explorer
 | 
					            submitted_by=user.explorer
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_description(self):
 | 
					    def test_description(self):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,13 +19,15 @@ class PlaceTestCase(SubmittableTestCase, TestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def setUpTestData(cls):
 | 
					    def setUpTestData(cls):
 | 
				
			||||||
 | 
					        user = User.objects.create_user(
 | 
				
			||||||
        BaseData.setUpTestData()
 | 
					            username='testpeter',
 | 
				
			||||||
 | 
					            password='Develop123'
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        place = Place.objects.create(
 | 
					        place = Place.objects.create(
 | 
				
			||||||
            name='Im a place',
 | 
					            name='Im a place',
 | 
				
			||||||
            submitted_when=datetime.datetime.now(),
 | 
					            submitted_when=datetime.datetime.now(),
 | 
				
			||||||
            submitted_by=User.objects.get(username='testpeter').explorer,
 | 
					            submitted_by=user.explorer,
 | 
				
			||||||
            location='Testtown',
 | 
					            location='Testtown',
 | 
				
			||||||
            latitude=50.5,
 | 
					            latitude=50.5,
 | 
				
			||||||
            longitude=7.0,
 | 
					            longitude=7.0,
 | 
				
			||||||
@@ -74,9 +76,9 @@ class PlaceTestCase(SubmittableTestCase, TestCase):
 | 
				
			|||||||
        of 10 places
 | 
					        of 10 places
 | 
				
			||||||
        '''
 | 
					        '''
 | 
				
			||||||
        place_list = []
 | 
					        place_list = []
 | 
				
			||||||
        place = Place.objects.get(id=1)
 | 
					 | 
				
			||||||
        place.id = None
 | 
					 | 
				
			||||||
        for i in range(10):
 | 
					        for i in range(10):
 | 
				
			||||||
 | 
					            place = Place.objects.get(id=1)
 | 
				
			||||||
 | 
					            place.id = None
 | 
				
			||||||
            place.latitude = i+1
 | 
					            place.latitude = i+1
 | 
				
			||||||
            place.longitude = i+10
 | 
					            place.longitude = i+10
 | 
				
			||||||
            place.save()
 | 
					            place.save()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,8 @@
 | 
				
			|||||||
 | 
					import datetime
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.test import TestCase, Client
 | 
					from django.test import TestCase, Client
 | 
				
			||||||
from django.urls import reverse_lazy
 | 
					from django.urls import reverse_lazy
 | 
				
			||||||
 | 
					from django.contrib.auth.models import User
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from lostplaces_app.models import Place
 | 
					from lostplaces_app.models import Place
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -7,6 +10,25 @@ from django.contrib.auth.models import User
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class TestIsAuthenticated(TestCase):
 | 
					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):
 | 
					    def setUp(self):
 | 
				
			||||||
        self. client = Client()
 | 
					        self. client = Client()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -33,6 +55,25 @@ class TestIsAuthenticated(TestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class TestIsPlaceSubmitter(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):
 | 
					    def setUp(self):
 | 
				
			||||||
        self. client = Client()
 | 
					        self. client = Client()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +1,32 @@
 | 
				
			|||||||
 | 
					import datetime
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.test import TestCase, Client
 | 
					from django.test import TestCase, Client
 | 
				
			||||||
from django.urls import reverse_lazy
 | 
					from django.urls import reverse_lazy
 | 
				
			||||||
 | 
					from django.contrib.auth.models import User
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from lostplaces_app.models import Place
 | 
					from lostplaces_app.models import Place
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestPlaceCreateView(TestCase):
 | 
					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):
 | 
					    def setUp(self):
 | 
				
			||||||
        self. client = Client()
 | 
					        self. client = Client()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user