mirror of
https://github.com/Hopiu/django-tos.git
synced 2026-04-22 20:14:42 +00:00
Fixed breaking logins due to initial_data
- Removed initial_data fixture in favor of a post_syncdb
signal to add the initial 'blank' TOS
This commit is contained in:
parent
f6916c0254
commit
693d3aeb9d
5 changed files with 32 additions and 19 deletions
|
|
@ -1,12 +0,0 @@
|
|||
[
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "tos.termsofservice",
|
||||
"fields": {
|
||||
"active": true,
|
||||
"content": "blank terms of service",
|
||||
"modified": "2010-06-21 10:37:26",
|
||||
"created": "2010-06-21 10:37:26"
|
||||
}
|
||||
}
|
||||
]
|
||||
15
tos/management/__init__.py
Normal file
15
tos/management/__init__.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from django.db.models.signals import post_syncdb
|
||||
import tos.models
|
||||
|
||||
def create_default_tos_on_sync(sender, **kwargs):
|
||||
""" Create a default TOS is an active one does not exist """
|
||||
|
||||
try:
|
||||
active_tos = tos.models.TermsOfService.objects.get(active=True)
|
||||
except tos.models.TermsOfService.DoesNotExist:
|
||||
new_tos = tos.models.TermsOfService.objects.create(
|
||||
active = True,
|
||||
content = 'blank terms of service'
|
||||
)
|
||||
|
||||
post_syncdb.connect(create_default_tos_on_sync, sender=tos.models)
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
class NoActiveTermsOfService(ValidationError): pass
|
||||
|
|
@ -66,4 +65,4 @@ def has_user_agreed_latest_tos(user):
|
|||
if UserAgreement.objects.filter(terms_of_service=TermsOfService.objects.get_current_tos(),user=user):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.test import TestCase
|
||||
from django.db.models.signals import post_syncdb
|
||||
|
||||
from tos.models import TermsOfService, UserAgreement, has_user_agreed_latest_tos
|
||||
|
||||
|
|
@ -21,8 +22,9 @@ class TestModels(TestCase):
|
|||
)
|
||||
|
||||
def test_terms_of_service(self):
|
||||
|
||||
self.assertEquals(TermsOfService.objects.count(),2)
|
||||
|
||||
tos_objects = TermsOfService.objects.all()
|
||||
self.assertEquals(TermsOfService.objects.count(),3)
|
||||
|
||||
# order is by -created
|
||||
latest = TermsOfService.objects.latest()
|
||||
|
|
@ -77,4 +79,13 @@ class TestModels(TestCase):
|
|||
self.assertTrue(has_user_agreed_latest_tos(self.user1))
|
||||
self.assertFalse(has_user_agreed_latest_tos(self.user2))
|
||||
self.assertTrue(has_user_agreed_latest_tos(self.user3))
|
||||
|
||||
|
||||
class TestSyncDBSignal(TestCase):
|
||||
"""
|
||||
Test to ensure our post_syncdb signal is working.
|
||||
"""
|
||||
|
||||
def test_syncdb(self):
|
||||
found_tos = TermsOfService.objects.filter(active=True)
|
||||
self.assertEqual(len(found_tos), 1)
|
||||
|
||||
|
|
|
|||
|
|
@ -89,4 +89,4 @@ class TestViews(TestCase):
|
|||
response = self.client.post(url, {'accept':'accept'})
|
||||
|
||||
self.assertTrue(has_user_agreed_latest_tos(self.user1))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue