Compare commits

...

8 Commits

9 changed files with 107 additions and 25 deletions

View File

@ -6,15 +6,15 @@
from django.contrib import admin from django.contrib import admin
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin from django.contrib.auth.admin import UserAdmin
from .models import * from lostplaces_app.models import *
from .forms import ExplorerCreationForm, ExplorerChangeForm from lostplaces_app.forms import ExplorerCreationForm, ExplorerChangeForm
# Register your models here. # Register your models here.
class VoucherAdmin(admin.ModelAdmin): class VoucherAdmin(admin.ModelAdmin):
fields = ['code', 'expires', 'created'] fields = ['code', 'expires_when', 'created_when']
readonly_fields = ['created'] readonly_fields = ['created_when']
admin.site.register(Explorer) admin.site.register(Explorer)
admin.site.register(Voucher, VoucherAdmin) admin.site.register(Voucher, VoucherAdmin)

View File

@ -33,7 +33,7 @@ class Explorer(models.Model):
) )
def __str__(self): def __str__(self):
return self.user.name return self.user.username
@receiver(post_save, sender=User) @receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs): def create_user_profile(sender, instance, created, **kwargs):
@ -54,11 +54,11 @@ class Voucher(models.Model):
""" """
code = models.CharField(unique=True, max_length=30) code = models.CharField(unique=True, max_length=30)
created = models.DateTimeField(auto_now_add=True) created_when = models.DateTimeField(auto_now_add=True)
expires = models.DateField() expires_when = models.DateTimeField()
def __str__(self): def __str__(self):
return "Voucher " + str(self.pk) return "Voucher " + str(self.code)
class Place (models.Model): class Place (models.Model):

View File

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

View File

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

View File

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

View File

@ -2,6 +2,7 @@ import datetime
from django.test import TestCase from django.test import TestCase
from django.db import models from django.db import models
from django.utils import timezone
from lostplaces_app.models import Voucher from lostplaces_app.models import Voucher
from lostplaces_app.tests.models import ModelTestCase from lostplaces_app.tests.models import ModelTestCase
@ -14,9 +15,9 @@ class VoucheTestCase(ModelTestCase, TestCase):
def setUpTestData(cls): def setUpTestData(cls):
Voucher.objects.create( Voucher.objects.create(
code='ayDraJCCwfhcFiYmSR5GrcjcchDfcahv', code='ayDraJCCwfhcFiYmSR5GrcjcchDfcahv',
expires=datetime.datetime.now() + datetime.timedelta(days=1) expires_when=timezone.now() + datetime.timedelta(days=1)
) )
def test_voucher_code(self): def test_voucher_code(self):
self._test_char_field( self._test_char_field(
'code', 'code',
@ -45,4 +46,4 @@ class VoucheTestCase(ModelTestCase, TestCase):
msg='Expecting %s.__str__ to contain the voucher code' % ( msg='Expecting %s.__str__ to contain the voucher code' % (
self.model_name self.model_name
) )
) )

View File

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

View File

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

View File

@ -1,5 +1,5 @@
from django.urls import path from django.urls import path
from .views import ( from lostplaces_app.views import (
HomeView, HomeView,
PlaceDetailView, PlaceDetailView,
PlaceListView, PlaceListView,