def test_should_assign_email_to_promo_code_if_emails_does_not_exists(self): responses.add(**self.mock_kwargs) ser = PromoCodeSerializer(data={'email': '*****@*****.**'}) self.assertTrue(ser.is_valid()) new_pc = ser.save() self.assertEqual(new_pc.email, '*****@*****.**')
def test_should_return_success_message_on_success(self): responses.add(**self.mock_kwargs) ser = PromoCodeSerializer(data={'email': '*****@*****.**'}) self.assertTrue(ser.is_valid()) self.assertEqual( ser.data['success'], u'The code has been successfully sent', )
def test_should_not_assign_email_to_promo_code_if_email_exists(self): responses.add(**self.mock_kwargs) pc = mommy.make('promo_code.PromoCode', email='*****@*****.**') ser = PromoCodeSerializer(data={'email': '*****@*****.**'}) self.assertTrue(ser.is_valid()) new_pc = ser.save() self.assertEqual(pc.pk, new_pc.pk)
def test_should_raise_error_if_not_associated(self): self.mock_kwargs['body'] = '{"status": false}' responses.add(**self.mock_kwargs) ser = PromoCodeSerializer(data={'email': '*****@*****.**'}) self.assertFalse(ser.is_valid()) self.assertEqual( ser.errors['email'][0], u'E-mail is not valid associated email', )
def test_should_raise_third_party_error_if_connection_error(self): ser = PromoCodeSerializer(data={'email': '*****@*****.**'}) with patch.object(requests, 'get') as m: m.side_effect = requests.exceptions.ConnectionError self.assertFalse(ser.is_valid()) self.assertEqual( ser.errors['email'][0], u'Problem connecting with third party service', )