Compare commits
No commits in common. "86fbee4116e8fb5a4a72e606d4560a57bbf6f136" and "76b514e1e67a5a04e1e5a58ed281bdcee285b95f" have entirely different histories.
86fbee4116
...
76b514e1e6
@ -1,22 +0,0 @@
|
|||||||
# Generated by Django 3.1.1 on 2020-10-04 19:37
|
|
||||||
# Edited by reverend
|
|
||||||
|
|
||||||
import datetime
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.utils.timezone
|
|
||||||
from django.utils.timezone import utc
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('lostplaces', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.DeleteModel(
|
|
||||||
name='Voucher'
|
|
||||||
),
|
|
||||||
migrations.DeleteModel(
|
|
||||||
name='Expireable'
|
|
||||||
)
|
|
||||||
]
|
|
@ -1,25 +0,0 @@
|
|||||||
# Generated by Django 3.1.1 on 2020-10-04 19:52
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('lostplaces', '0002_reomve_vouchers'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Voucher',
|
|
||||||
fields=[
|
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('created_when', models.DateTimeField(auto_now_add=True)),
|
|
||||||
('expires_when', models.DateTimeField()),
|
|
||||||
('code', models.CharField(max_length=30, unique=True)),
|
|
||||||
],
|
|
||||||
options={
|
|
||||||
'abstract': False,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
from django.utils import timezone
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||||
|
|
||||||
@ -56,14 +55,7 @@ class Submittable(models.Model):
|
|||||||
|
|
||||||
class Expireable(models.Model):
|
class Expireable(models.Model):
|
||||||
"""
|
"""
|
||||||
Base class for things that can expire, i.e. Vouchers
|
Base class for things that can expire, i.e. VouchersAv
|
||||||
"""
|
"""
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
created_when = models.DateTimeField(auto_now_add=True)
|
created_when = models.DateTimeField(auto_now_add=True)
|
||||||
expires_when = models.DateTimeField()
|
expires_when = models.DateTimeField()
|
||||||
|
|
||||||
@property
|
|
||||||
def is_expired(self):
|
|
||||||
return timezone.now() > self.expires_when
|
|
@ -50,10 +50,6 @@ class Voucher(Expireable):
|
|||||||
|
|
||||||
code = models.CharField(unique=True, max_length=30)
|
code = models.CharField(unique=True, max_length=30)
|
||||||
|
|
||||||
@property
|
|
||||||
def valid(self):
|
|
||||||
return not self.is_expired
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Voucher " + str(self.code)
|
return "Voucher " + str(self.code)
|
||||||
|
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
from django.core.exceptions import FieldDoesNotExist
|
|
||||||
|
|
||||||
class FormTestCase(TestCase):
|
|
||||||
'''
|
|
||||||
Base class for FormTests.
|
|
||||||
Parameters:
|
|
||||||
- form : Form to test
|
|
||||||
'''
|
|
||||||
form = None
|
|
||||||
|
|
||||||
def assertField(self, field_name, field_class, must_have={}, must_not_have={}):
|
|
||||||
'''
|
|
||||||
Tests if a field exists under the given name and
|
|
||||||
if the field is of the right type.
|
|
||||||
Also checks if the field has the given must_have attributes
|
|
||||||
and does not have any of the must_not_have attributes. If you
|
|
||||||
dont care about the value of the attribute you can just set it to
|
|
||||||
something that fullfills value == False (i.e. '' or 0)
|
|
||||||
'''
|
|
||||||
try:
|
|
||||||
field = self.form.base_fields[field_name]
|
|
||||||
except FieldDoesNotExist:
|
|
||||||
self.fail(
|
|
||||||
'Expecting %s to have a field named \'%s\'' % (
|
|
||||||
self.form.__name__,
|
|
||||||
field_name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
type(field), field_class,
|
|
||||||
msg='Expecting type of %s to be %s' % (
|
|
||||||
str(field),
|
|
||||||
field_class.__name__
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
for key, value in must_have.items():
|
|
||||||
if value:
|
|
||||||
self.assertEqual(
|
|
||||||
getattr(field, key), value,
|
|
||||||
msg='Expeting the value of %s %s to be \'%s\'' % (
|
|
||||||
str(field),
|
|
||||||
key,
|
|
||||||
value
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.assertTrue(
|
|
||||||
hasattr(field, key),
|
|
||||||
msg='Expeting %s to have \'%s\'' % (
|
|
||||||
str(field),
|
|
||||||
key
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
for key, value in must_not_have.items():
|
|
||||||
if value:
|
|
||||||
self.assertTrue(
|
|
||||||
getattr(field, key) != value,
|
|
||||||
msg='Expeting the value of %s %s to not be \'%s\'' % (
|
|
||||||
str(field),
|
|
||||||
key,
|
|
||||||
value
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.assertFalse(
|
|
||||||
hasattr(field, value),
|
|
||||||
msg='Expeting %s to not have \'%s\'' % (
|
|
||||||
str(field),
|
|
||||||
key
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return field
|
|
@ -1,59 +0,0 @@
|
|||||||
import datetime
|
|
||||||
|
|
||||||
from django import forms
|
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
from lostplaces.tests.forms import FormTestCase
|
|
||||||
from lostplaces.forms import ExplorerCreationForm
|
|
||||||
from lostplaces.models.models import Voucher
|
|
||||||
|
|
||||||
class ExplorerCreationFormTestCase(FormTestCase):
|
|
||||||
"""
|
|
||||||
This test case only tests for the voucher since all other aspects don't realy matter
|
|
||||||
to this project and are already tested by django
|
|
||||||
"""
|
|
||||||
form = ExplorerCreationForm
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setUpTestData(cls):
|
|
||||||
Voucher.objects.create(
|
|
||||||
code='Imacode123',
|
|
||||||
expires_when=timezone.now() + datetime.timedelta(minutes=1)
|
|
||||||
)
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.post_data = {
|
|
||||||
'voucher': 'Imacode123',
|
|
||||||
'username': 'testpeter',
|
|
||||||
'email': 'testpeter@example.org',
|
|
||||||
'password1': 'Develop123',
|
|
||||||
'password2': 'Develop123'
|
|
||||||
}
|
|
||||||
|
|
||||||
def test_voucher_field(self):
|
|
||||||
self.assertField(
|
|
||||||
field_name='voucher',
|
|
||||||
field_class=forms.CharField
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_validation_valid(self):
|
|
||||||
form = ExplorerCreationForm(self.post_data)
|
|
||||||
self.assertTrue(
|
|
||||||
form.is_valid(),
|
|
||||||
msg='Expecting the %s to validate' % (
|
|
||||||
self.form.__name__
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_validation_invalid(self):
|
|
||||||
self.post_data = {
|
|
||||||
'voucher': 'Imanotacode123'
|
|
||||||
}
|
|
||||||
form = ExplorerCreationForm(self.post_data)
|
|
||||||
self.assertFalse(
|
|
||||||
form.is_valid(),
|
|
||||||
msg='Expecting the %s to not validate' % (
|
|
||||||
self.form.__name__
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
@ -2,9 +2,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from django.core.exceptions import FieldDoesNotExist
|
from django.core.exceptions import FieldDoesNotExist
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Creating a test user
|
||||||
|
|
||||||
class ModelTestCase(TestCase):
|
class ModelTestCase(TestCase):
|
||||||
'''
|
'''
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
from django.utils import timezone
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
@ -13,8 +10,7 @@ from lostplaces.models import (
|
|||||||
Mapable,
|
Mapable,
|
||||||
Submittable,
|
Submittable,
|
||||||
PlaceAsset,
|
PlaceAsset,
|
||||||
Expireable,
|
Expireable
|
||||||
Voucher
|
|
||||||
)
|
)
|
||||||
from lostplaces.tests.models import ModelTestCase
|
from lostplaces.tests.models import ModelTestCase
|
||||||
|
|
||||||
@ -117,33 +113,3 @@ class PlaceAssetTestCase(ModelTestCase):
|
|||||||
|
|
||||||
class ExpireableTestCase(ModelTestCase):
|
class ExpireableTestCase(ModelTestCase):
|
||||||
model = Expireable
|
model = Expireable
|
||||||
|
|
||||||
def test_fields(self):
|
|
||||||
self.assertField(
|
|
||||||
field_name='created_when',
|
|
||||||
field_class=models.DateTimeField,
|
|
||||||
must_have={'auto_now_add': True}
|
|
||||||
)
|
|
||||||
self.assertField(
|
|
||||||
field_name='expires_when',
|
|
||||||
field_class=models.DateTimeField
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_is_expired(self):
|
|
||||||
valid_voucher = Voucher.objects.create(
|
|
||||||
code='Test123',
|
|
||||||
expires_when=timezone.now() + datetime.timedelta(minutes=2)
|
|
||||||
)
|
|
||||||
self.assertFalse(
|
|
||||||
valid_voucher.is_expired,
|
|
||||||
msg='Expecing the expirable object to not be expired'
|
|
||||||
)
|
|
||||||
|
|
||||||
invalid_voucher = Voucher.objects.create(
|
|
||||||
code='Test1234',
|
|
||||||
expires_when=timezone.now() - datetime.timedelta(minutes=2)
|
|
||||||
)
|
|
||||||
self.assertTrue(
|
|
||||||
invalid_voucher.is_expired,
|
|
||||||
msg='Expecing the expirable object to be expired'
|
|
||||||
)
|
|
2
setup.py
2
setup.py
@ -8,7 +8,7 @@ with open('Readme.md') as f:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='django-lostplaces',
|
name='django-lostplaces',
|
||||||
version='0.1.2 HotFix',
|
version='0.1.a5',
|
||||||
description='A django app to manage lost places',
|
description='A django app to manage lost places',
|
||||||
author='Reverend',
|
author='Reverend',
|
||||||
author_email='reverend@reverend2048.de',
|
author_email='reverend@reverend2048.de',
|
||||||
|
Loading…
Reference in New Issue
Block a user