Esempio n. 1
0
    def test_subscription_counter(self):
        """Test subscription counter retrieval"""
        sub = Subscriber()
        sub.lastname = 'toto'
        sub.save()
        sub = Subscriber()
        sub.lastname = 'titi'
        sub.save()
        sub = Subscriber()
        sub.lastname = 'tata'
        sub.save()

        self.assertEqual(3, Subscriber.get_count())
Esempio n. 2
0
 def test_subscriber_without_remaining_issue(self):
     """Test if a subscriber that has no issue left will not receive a free
     number :)"""
     subscriber = Subscriber()
     subscriber.lastname = 'toto'
     subscriber.issues_to_receive = 1
     subscriber.save()
     subscriber = Subscriber()
     subscriber.lastname = 'tata'
     subscriber.issues_to_receive = 0
     subscriber.save()
     self.exporter.do_export()
     self.__test_presence_toto_tata()
Esempio n. 3
0
    def test_field_length(self):
        """test if the fields in the output file does not exceed character limits"""
        big_string = ''.join(['b' for i in xrange(1, 40)])
        subscriber = Subscriber()
        subscriber.lastname = big_string
        subscriber.firstname = big_string
        subscriber.company = big_string
        a = Address()
        a.address1 = big_string
        a.address2 = big_string
        a.post_code = 123456 
        a.city = big_string
        subscriber.address = a
        subscriber.issues_to_receive = 10
        subscriber.save()
        line = self.export_and_get_first_line()

        splitted_line = line.split('\t')
        self.assertTrue(len(splitted_line[0]) <= 20)
        self.assertTrue(len(splitted_line[1]) <= 12)
        self.assertTrue(len(splitted_line[2]) <= 32)
        self.assertTrue(len(splitted_line[3]) <= 20)
        self.assertTrue(len(splitted_line[4]) <= 32)
        self.assertTrue(len(splitted_line[5]) <= 32)
        self.assertTrue(len(splitted_line[6]) <= 32)
        self.assertTrue(len(splitted_line[7]) <= 32)
        self.assertTrue(len(splitted_line[8]) <= 5)
        self.assertTrue(len(splitted_line[9]) <= 26)
        self.assertTrue(len(splitted_line[10]) <= 8)
        self.assertTrue(len(splitted_line[11]) <= 3)
        self.assertTrue(len(splitted_line[12]) <= 32)
        self.assertTrue(len(splitted_line[13]) <= 32)
        self.assertTrue(len(splitted_line[14]) <= 32)
        self.assertTrue(len(splitted_line[15]) <= 32)
Esempio n. 4
0
    def test_subscription_info_by_lastname(self):
        """Test subscription info fields retrieved by the adapter"""
        sub = Subscriber()
        sub.lastname = 'toto'
        sub.subscription_date = date(2011, 10, 10)
        sub.issues_to_receive = 5
        sub.subs_beginning_issue = 32
        sub.subscription_price = 31.50
        sub.membership_price = 50.25
        sub.hors_serie1 = 1
        sub.ordering_type = 'pp'
        sub.comment = 'blahblah'
        sub.save()

        dict_list = SubscriberAdapter.get_subscribers_from_lastname('toto')
        new_sub = dict_list[0]
        self.assertEquals('10/10/2011', new_sub['subscription_date'])
        self.assertEquals('5', new_sub['issues_to_receive'])
        self.assertEquals('32', new_sub['subs_beginning_issue'])
        self.assertEquals('31,50', new_sub['subscription_price'])
        self.assertEquals('50,25', new_sub['membership_price'])
        self.assertEquals('1', new_sub['hors_serie1'])
        self.assertEquals('pp', new_sub['ordering_type'])
        self.assertEquals('blahblah', new_sub['comment'])
        self.assertEquals(sub.identifier, new_sub['subscriber_id'])
Esempio n. 5
0
 def test_non_ascii_char(self):
     subscriber = Subscriber()
     subscriber.lastname = u'Toto°°'
     subscriber.issues_to_receive = 1
     subscriber.save()
     line = get_first_line()
     self.assertTrue(line is not None)
Esempio n. 6
0
    def test_first_line(self):
        """Test if the first line of generated file is well written"""

        subs = Subscriber()
        subs.lastname = 'Debelle'
        subs.firstname = 'Anne'
        a = Address()
        a.address1 = 'rue dupre 63'
        a.address2 = 'Bruxelles 1090'
        a.city = 'belgique'
        subs.address = a
        subs.issues_to_receive = 1
        subs.save()

        line = self.export_and_get_first_line()

        self.assertTrue(line is not None)

        splitted_line = line.split('\t')
        self.assertEquals(splitted_line[2], u'DEBELLE')
        self.assertEquals(splitted_line[3], u'ANNE')
        self.assertEquals(splitted_line[4], u'')
        self.assertEquals(splitted_line[5], u'')
        self.assertEquals(splitted_line[6], u'RUE DUPRE 63')
        self.assertEquals(splitted_line[7], u'BRUXELLES 1090')
        self.assertEquals(splitted_line[8], u'')
        self.assertEquals(splitted_line[9], u'BELGIQUE')
        self.assertEquals(splitted_line[10], u'')
        self.assertEquals(splitted_line[11], u'')
        self.assertEquals(splitted_line[12], u'')
        self.assertEquals(splitted_line[13], u'')
        self.assertEquals(splitted_line[14], u'')
        self.assertEquals(splitted_line[15], u'\n')
Esempio n. 7
0
    def test_update_mail_sent(self):
        sub = Subscriber()
        sub.lastname = 'toto'
        sub.issues_to_receive = 0
        sub.save()
        sub = Subscriber()
        sub.lastname = 'tata'
        sub.issues_to_receive = 1
        sub.save()

        Subscriber.update_mail_sent()

        toto = Subscriber.get_subscribers_from_lastname('toto')[0]
        tata = Subscriber.get_subscribers_from_lastname('tata')[0]

        self.assertEqual(1, toto.mail_sent)
        self.assertEqual(0, tata.mail_sent)
Esempio n. 8
0
    def test_export_for_special_issues(self):
        """Test the function to export subscriber list to send special issue"""
        subscriber = Subscriber()
        subscriber.lastname = 'toto'
        subscriber.hors_serie1 = 1
        subscriber.hors_serie2 = 0
        subscriber.hors_serie3 = 0
        subscriber.save()
        subscriber = Subscriber()
        subscriber.lastname = 'tata'
        subscriber.hors_serie1 = 0
        subscriber.hors_serie2 = 1
        subscriber.hors_serie3 = 0
        subscriber.save()

        self.exporter.do_export_special_issue()

        self.__test_presence_toto_tata()
Esempio n. 9
0
 def test_noexception_with_emtpy_string_postcode(self):
     """Test that former empty postcode leads to no export error exception"""
     subscriber = Subscriber()
     subscriber.lastname = 'toto'
     subscriber.issues_to_receive = 1
     a = Address()
     a.post_code = 0
     subscriber.address = a
     subscriber.save()
     line = self.export_and_get_first_line()
     self.assertEqual(line.split('\t')[8], '')
Esempio n. 10
0
 def test_null_post_code_format(self):
     """Test the postcode format when a null postcode is in db: 00000 is
     ugly"""
     sub = Subscriber()
     sub.lastname = 'toto'
     address = Address()
     address.post_code = 0
     sub.address = address
     sub.save()
     dict_list = SubscriberAdapter.get_subscribers_from_lastname('toto')
     new_sub = dict_list[0]
     self.assertEquals('', new_sub['post_code'])
Esempio n. 11
0
 def test_subscriber_with_wrong_pricing_info(self):
     """Tests what happens when Subscriber has wrong or empty pricing
     info"""
     sub = Subscriber()
     sub.lastname = 'toto'
     sub.subscription_price = 'foo'
     sub.membership_price = 'bar'
     sub.save()
     dict_list = SubscriberAdapter.get_subscribers_from_lastname('toto')
     new_sub = dict_list[0]
     self.assertEquals('0,00', new_sub['subscription_price'])
     self.assertEquals('0,00', new_sub['membership_price'])
Esempio n. 12
0
 def set_regular_subscriber(self):
     sub = Subscriber()
     sub.lastname = 'Nom'
     sub.firstname = 'Prenom'
     sub.name_addition = 'NameAddition'
     a = Address()
     a.address1 = 'Adresse'
     a.address2 = 'Addition'
     a.post_code = 12345
     a.city = 'Ville'
     sub.address = a
     return sub
Esempio n. 13
0
    def test_create_and_delete_subscriber(self):
        sub = Subscriber()
        sub.lastname = 'toto'
        sub.save()
        ident = sub.identifier

        SubscriberAdapter.delete_from_id(ident)

        actual_result_count = len(
                Subscriber.get_subscribers_from_lastname('toto')
                )

        self.assertEqual(0, actual_result_count)
Esempio n. 14
0
    def test_mail_sent_updated_special_issue(self):
        sub = Subscriber()
        sub.lastname = 'toto'
        sub.issues_to_receive = 0
        sub.hors_serie1 = 0
        sub.mail_sent = 1
        sub.save()

        self.assertEqual(1, sub.mail_sent)

        sub.hors_serie1 = 1
        sub.save()
        self.assertEqual(0, sub.mail_sent)
Esempio n. 15
0
    def test_when_mail_already_sent(self):
        """Tests that a subscriber is not exported when he has already reveived
        a resubscription mail and has not re subscribed"""
        sub = Subscriber()
        sub.lastname = 'toto'
        sub.issues_to_receive = 0
        sub.hors_serie1 = 0
        sub.mail_sent = 1
        sub.save()

        self.exporter.do_export()
        f = open_test_file()
        self.assertEquals(1, len(f.readlines()))
Esempio n. 16
0
    def test_subscriber_address(self):
        sub = Subscriber()
        address = Address()
        sub.lastname = 'toto'
        address.address1 = '11 rue bilou'
        address.address2 = 'batiment 1'
        address.post_code = '66066'
        address.city = 'NYC'
        sub.address = address
        sub.save()

        retrieved_sub = Subscriber.get_subscribers_from_lastname('toto')[0]
        retieved_address = retrieved_sub.address
        self.assertEqual('NYC', retieved_address.city)
Esempio n. 17
0
 def save_basic_subscriber(self):
     sub = Subscriber()
     sub.lastname = 'Doe'
     sub.firstname = 'John'
     sub.company = 'Apave'
     a = Address()
     a.city = 'Rouen'
     sub.address = a
     sub.issues_to_receive = 5
     sub.hors_serie1 = 6
     sub.subscription_price = 20
     sub.membership_price = 30
     sub.subscription_date = datetime.date(2011, 07, 12)
     sub.save()
Esempio n. 18
0
    def test_get_subs_by_lastname(self):
        """Test subscriber by lastname retrieval using the adapter"""
        sub = Subscriber()
        sub.lastname = 'toto'
        sub.firstname = 'tata'
        sub.email_address = '*****@*****.**'
        sub.name_addition = 'foobar'
        sub.save()

        dict_list = SubscriberAdapter.get_subscribers_from_lastname('toto')
        new_sub = dict_list[0]
        self.assertEquals('toto', new_sub['lastname'])
        self.assertEquals('tata', new_sub['firstname'])
        self.assertEquals('*****@*****.**', new_sub['email_address'])
        self.assertEquals('foobar', new_sub['name_addition'])
        self.assertEquals(sub.identifier, new_sub['subscriber_id'])
Esempio n. 19
0
 def test_handle_name_addition(self):
     """Tests that if we have a name_addition, it goes in the first address
     field"""
     subscriber = Subscriber()
     subscriber.issues_to_receive = 1
     subscriber.lastname = 'Dupond'
     subscriber.firstname = 'Toto'
     subscriber.name_addition = 'Chez lulu'
     a = Address()
     a.address1 = '14 Rue lalala'
     subscriber.address = a
     subscriber.save()
     line = self.export_and_get_first_line()
     splitted = line.split('\t')
     self.assertEqual('CHEZ LULU', splitted[5])
     self.assertEqual('14 RUE LALALA', splitted[6])
Esempio n. 20
0
    def test_get_subs_address_by_lastname(self):
        """Tests address fields on dict retrieved by the adapter"""
        sub = Subscriber()
        sub.lastname = 'toto'
        address = Address()
        address.address1 = '42 rue truc'
        address.address2 = 'bat B'
        address.post_code = 38100
        address.city = 'Paris'
        sub.address = address
        sub.save()

        dict_list = SubscriberAdapter.get_subscribers_from_lastname('toto')
        new_sub = dict_list[0]
        self.assertEquals('42 rue truc', new_sub['address'])
        self.assertEquals('bat B', new_sub['address_addition'])
        self.assertEquals('38100', new_sub['post_code'])
        self.assertEquals('Paris', new_sub['city'])
Esempio n. 21
0
    def test_subscriber_with_id(self):
        db_sub = Subscriber()
        db_sub.lastname = 'toto'
        db_sub.firstname = 'tata'
        db_sub.save()
        ident = db_sub.identifier
        sub = {
                'subscriber_id': ident,
                'lastname': 'toto',
                'firstname': 'titi'
                }
        actual = self._save(sub)
        self.assertEquals(ident, actual['subscriber_id'])

        subs_list = Subscriber.get_subscribers_from_lastname('toto')
        self.assertEqual(len(subs_list), 1)

        retrieved_sub = subs_list[0]
        self.assertEquals(ident, retrieved_sub.identifier)
Esempio n. 22
0
 def save_wrong_date_subscriber(self):
     sub = Subscriber()
     sub.lastname = 'Doe'
     sub.firstname = 'John'
     sub.subscription_date = datetime.date(211, 07, 12)
     sub.save()
Esempio n. 23
0
 def save_accent_subscriber(self):
     sub = Subscriber()
     sub.lastname = u'Yé'
     sub.firstname = u'Bébé'
     sub.save()