def test(self): factory = UserFactory() factory.graph_api_class = mock.Mock() factory.graph_api_class.return_value.get.return_value = {'id': '123'} user = factory.get_user("123") self.assertEqual(123, user.user_id) factory = UserFactory() factory.graph_api_class = mock.Mock() factory.graph_api_class.return_value.get.side_effect = [ FacebookError("msg", 1), FacebookError("msg", 1), {'id': '123'}] user = factory.get_user("123") self.assertEqual(123, user.user_id) factory = UserFactory() factory.graph_api_class = mock.Mock() factory.graph_api_class.return_value.get.side_effect = [ FacebookError("msg", 1), FacebookError("msg", 1), FacebookError("msg", 1), {'id': '123'}] self.assertEqual(None, factory.get_user("123"))
def test_no_email(self): profile = { 'id': '1', 'first_name': '', 'last_name': '', } UserFactory()._product_user('', profile).save()
def test_success_in_retry(self, get_graph): factory = UserFactory() get_graph.return_value.get.side_effect = [ FacebookError("msg", 1), FacebookError("msg", 1), {'id': '123'}] user = factory.get_user("123") self.assertEqual(123, user.user_id)
def test_failure(self, get_graph): factory = UserFactory() get_graph.return_value.get.side_effect = [ FacebookError("msg", 1), FacebookError("msg", 1), FacebookError("msg", 1), {'id': '123'}] with self.assertRaises(FacebookError): factory.get_user("123")
def test_to_long(self): profile = { 'id': '1', 'first_name': 'a' * 1000, 'last_name': 'a' * 1000, 'email': 'a' * 1000 } user = UserFactory()._product_user('', profile) user.save() def get_length(field): return user._meta.get_field_by_name(field)[0].max_length self.assertEqual(user.first_name, 'a' * get_length('first_name')) self.assertEqual(user.last_name, 'a' * get_length('last_name')) self.assertEqual(user.email, '')
def test_success(self, get_graph): factory = UserFactory() get_graph.return_value.get.return_value = {'id': '123'} user = factory.get_user("123") self.assertEqual(123, user.user_id)