Browse Source

Merge branch 'fix-108-membershipfree-mandatory-date-fields' of daimrod/coin into master

jocelyn 8 years ago
parent
commit
43d3f0156f
2 changed files with 20 additions and 1 deletions
  1. 1 1
      coin/members/models.py
  2. 19 0
      coin/members/tests.py

+ 1 - 1
coin/members/models.py

@@ -428,7 +428,7 @@ class MembershipFee(models.Model):
                                     verbose_name='date du paiement')
 
     def clean(self):
-        if self.end_date is None:
+        if self.start_date is not None and self.end_date is None:
             self.end_date = self.start_date + datetime.timedelta(364)
 
     def __unicode__(self):

+ 19 - 0
coin/members/tests.py

@@ -509,3 +509,22 @@ class TestValidators(TestCase):
         chatroom_url_validator('irc://irc.example.com/#chan')
         with self.assertRaises(ValidationError):
             chatroom_url_validator('http://#faimaison@irc.geeknode.org')
+
+
+class MembershipFeeTests(TestCase):
+    def test_mandatory_start_date(self):
+        member = Member(first_name='foo', last_name='foo', password='foo', email='foo')
+        member.save()
+
+        # If there is no start_date clean_fields() should raise an
+        # error but not clean().
+        membershipfee = MembershipFee(member=member)
+        self.assertRaises(ValidationError, membershipfee.clean_fields)
+        self.assertIsNone(membershipfee.clean())
+
+        # If there is a start_date, everything is fine.
+        membershipfee = MembershipFee(member=member, start_date=date.today())
+        self.assertIsNone(membershipfee.clean_fields())
+        self.assertIsNone(membershipfee.clean())
+
+        member.delete()