Browse Source

Fix billing tests
Move end date memship defautl value calcuation to an external method else django migration compute it at each makemigrations (and this change every day)

Fabs 10 years ago
parent
commit
f3be150f55

+ 2 - 2
coin/billing/models.py

@@ -72,8 +72,8 @@ class Invoice(models.Model):
 
     def has_owner(self, uid):
         "Check if passed uid (ex gmajax) is owner of the invoice"
-        return (self.member and self.member.ldap_cn and
-                self.member.ldap_cn == uid)
+        return (self.member and self.member.username and
+                self.member.username == uid)
 
     def __unicode__(self):
         return u'#%s %0.2f€ %s' % (self.number, self.amount(), self.date_due)

+ 19 - 19
coin/billing/tests.py

@@ -15,12 +15,12 @@ class BillingInvoiceCreationTests(TestCase):
     def setUp(self):
         # Créé une offre
         self.offer = Offer(name='Offre', billing_period=3, period_fees=30,
-                           initial_fees=50, type='dsl')
+                           initial_fees=50)
         self.offer.save()
         # Créé un membre
-        self.ldap_cn = MemberTestsUtils.get_random_ldap_cn()
+        self.username = MemberTestsUtils.get_random_username()
         self.member = Member(first_name='Balthazar', last_name='Picsou',
-                             ldap_cn=self.ldap_cn)
+                             username=self.username)
         self.member.save()
         # Créé un abonnement
         self.subscription = OfferSubscription(
@@ -31,7 +31,7 @@ class BillingInvoiceCreationTests(TestCase):
     
     def tearDown(self):
         # Supprime l'utilisateur LDAP créé
-        LdapUser.objects.get(pk=self.ldap_cn).delete()
+        LdapUser.objects.get(pk=self.username).delete()
 
     def test_first_subscription_invoice_has_initial_fees(self):
         """
@@ -117,11 +117,11 @@ class BillingPDFTests(TestCase):
         pdf
         """
         # Créé un membre
-        ldap_cn = MemberTestsUtils.get_random_ldap_cn()
+        username = MemberTestsUtils.get_random_username()
         member = Member(first_name='A', last_name='A',
-                        ldap_cn=ldap_cn)
+                        username=username)
+        member.set_password('1234')
         member.save()
-        member.change_password('1234')
 
         # Créé une facture
         invoice = Invoice(member=member)
@@ -129,12 +129,12 @@ class BillingPDFTests(TestCase):
 
         # Se connect en tant que le membre
         client = Client()
-        client.login(username=ldap_cn, password='1234')
+        client.login(username=username, password='1234')
         # Tente de télécharger la facture
         response = client.get('/billing/invoice/%i/pdf' % invoice.id)
         # Vérifie return code 200 et contient chaine %PDF-1.
         self.assertContains(response, '%PDF-1.', status_code=200, html=False)
-        LdapUser.objects.get(pk=ldap_cn).delete()
+        member.delete()
 
     def test_that_only_owner_of_invoice_can_download_it_as_pdf(self):
         """
@@ -144,20 +144,20 @@ class BillingPDFTests(TestCase):
         infructueuse
         """
         # Créé un membre A
-        member_a_login = MemberTestsUtils.get_random_ldap_cn()
+        member_a_login = MemberTestsUtils.get_random_username()
         member_a_pwd = '1234'
-        member_a = Member(first_name='A', last_name='A',
-                          ldap_cn=member_a_login)
+        member_a = Member(first_name='A', last_name='A', email='a@a.com',
+                          username=member_a_login)
+        member_a.set_password(member_a_pwd)
         member_a.save()
-        member_a.change_password(member_a_pwd)
 
         # Créé un membre B
-        member_b_login = MemberTestsUtils.get_random_ldap_cn()
+        member_b_login = MemberTestsUtils.get_random_username()
         member_b_pwd = '1234'
-        member_b = Member(first_name='B', last_name='B',
-                          ldap_cn=member_b_login)
+        member_b = Member(first_name='B', last_name='B', email='b@b.com',
+                          username=member_b_login)
+        member_b.set_password(member_b_pwd)
         member_b.save()
-        member_b.change_password(member_b_pwd)
 
         # Créé une facture pour le membre A
         invoice_a = Invoice(member=member_a)
@@ -179,5 +179,5 @@ class BillingPDFTests(TestCase):
         # Vérifie que B a reçu retour Forbidden 403
         self.assertEqual(response.status_code, 403)
 
-        LdapUser.objects.get(pk=member_a_login).delete()
-        LdapUser.objects.get(pk=member_b_login).delete()
+        member_a.delete()
+        member_b.delete()

+ 26 - 0
coin/members/migrations/0002_auto_20140920_1558.py

@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import coin
+import datetime
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('members', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='member',
+            name='email',
+            field=models.EmailField(max_length=75, verbose_name='email address'),
+        ),
+        migrations.AlterField(
+            model_name='membershipfee',
+            name='end_date',
+            field=models.DateField(default=coin.members.models.in_one_year, verbose_name=b'Date de fin de cotisation'),
+        ),
+    ]

+ 19 - 0
coin/members/migrations/0003_auto_20140920_1613.py

@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('members', '0002_auto_20140920_1558'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='member',
+            name='email',
+            field=models.EmailField(unique=True, max_length=75, verbose_name='email address'),
+        ),
+    ]

+ 4 - 1
coin/members/models.py

@@ -242,6 +242,9 @@ class CryptoKey(models.Model):
         verbose_name = 'clé'
 
 
+def in_one_year():
+    return datetime.date.today() + datetime.timedelta(365)
+
 class MembershipFee(models.Model):
     member = models.ForeignKey('Member', related_name='membership_fees',
                                verbose_name=u'Membre')
@@ -256,7 +259,7 @@ class MembershipFee(models.Model):
     end_date = models.DateField(
         null=False,
         blank=False,
-        default=datetime.date.today() + datetime.timedelta(365),
+        default=in_one_year,
         verbose_name='Date de fin de cotisation')
 
     def __unicode__(self):

+ 1 - 1
coin/members/tests.py

@@ -343,7 +343,7 @@ class MemberAdminTests(TestCase):
             '''<input id="id_username" />''',
                                html=True)
 
-        LdapUser.objects.get(pk=username).delete()
+        member.delete()
 
 
 class MemberTestsUtils(object):

+ 2 - 0
coin/offers/admin.py

@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 from django.contrib import admin
 from polymorphic.admin import PolymorphicChildModelAdmin
 
@@ -51,6 +52,7 @@ class OfferSubscriptionAdmin(admin.ModelAdmin):
     def get_inline_instances(self, request, obj=None):
         """
         Si en edition, alors affiche en inline le formulaire de la configuration
+        correspondant à l'offre choisie
         """
         ipsubnet_inline = [IPSubnetInline(self.model, self.admin_site)]