Skip to content

Commit

Permalink
Removed unregistered users from newsletter lists. Closes #124.
Browse files Browse the repository at this point in the history
  • Loading branch information
fgaudin committed Feb 25, 2011
1 parent 6c50064 commit 2985a4f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
7 changes: 4 additions & 3 deletions autoentrepreneur/models.py
Expand Up @@ -44,6 +44,7 @@ def get_not_paid_subscription(self, user):

def get_users_with_paid_subscription(self):
return self.filter(expiration_date__gte=datetime.date.today(),
owner__is_active=True,
state=SUBSCRIPTION_STATE_PAID).values('owner__email',
'owner__first_name',
'owner__last_name').distinct()
Expand All @@ -58,9 +59,9 @@ def get_users_with_trial_subscription(self):
state=SUBSCRIPTION_STATE_TRIAL).distinct()

def get_users_with_expired_subscription(self):
return self.all().values('owner').annotate(max_date=Max('expiration_date')).values('owner__email',
'owner__first_name',
'owner__last_name').filter(max_date__lt=datetime.date.today()).distinct()
return self.filter(owner__is_active=True).values('owner').annotate(max_date=Max('expiration_date')).values('owner__email',
'owner__first_name',
'owner__last_name').filter(max_date__lt=datetime.date.today()).distinct()

class Subscription(OwnedObject):
state = models.IntegerField(choices=SUBSCRIPTION_STATE, verbose_name=_('State'))
Expand Down
37 changes: 37 additions & 0 deletions autoentrepreneur/tests.py
Expand Up @@ -402,6 +402,43 @@ def setUp(self):
state=SUBSCRIPTION_STATE_FREE,
expiration_date=datetime.date.today() + datetime.timedelta(10),
transaction_id='freeuser7')
# unregistered user in trial
self.user8 = User.objects.create_user('user8', 'user8@example.com', 'test')
self.user8.first_name = 'User 8'
self.user8.last_name = 'User 8'
self.user8.is_active = False
self.user8.save()
profile = self.user8.get_profile()
profile.unregister_datetime = datetime.datetime.now()
profile.save()
# unregistered user with paid subscription
self.user9 = User.objects.create_user('user9', 'user9@example.com', 'test')
self.user9.first_name = 'User 9'
self.user9.last_name = 'User 9'
self.user9.is_active = False
self.user9.save()
profile = self.user9.get_profile()
profile.unregister_datetime = datetime.datetime.now()
profile.save()
sub = Subscription.objects.get(owner=self.user9)
sub.expiration_date = datetime.date.today() - datetime.timedelta(10)
sub.save()
Subscription.objects.create(owner=self.user9,
state=SUBSCRIPTION_STATE_PAID,
expiration_date=datetime.date.today() + datetime.timedelta(10),
transaction_id='paiduser9')
# unregistered user with expired subscription
self.user10 = User.objects.create_user('user10', 'user10@example.com', 'test')
self.user10.first_name = 'User 10'
self.user10.last_name = 'User 10'
self.user10.is_active = False
self.user10.save()
profile = self.user10.get_profile()
profile.unregister_datetime = datetime.datetime.now()
profile.save()
sub = Subscription.objects.get(owner=self.user10)
sub.expiration_date = datetime.date.today() - datetime.timedelta(10)
sub.save()

def testTrialUser(self):
users = Subscription.objects.get_users_with_trial_subscription()
Expand Down
21 changes: 0 additions & 21 deletions newsletter/tests.py
@@ -1,23 +1,2 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".

Replace these with more appropriate tests for your application.
"""

from django.test import TestCase

class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)

__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

0 comments on commit 2985a4f

Please sign in to comment.