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)
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'])
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'])
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'])
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'])
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'])
def _save(self, sub): """Save the subscriber""" adapter = SubscriberAdapter(sub) actual = adapter.save_subscriber() return actual