def test_returns_false_with_no_creds(self): """Success is false if Account has no API credentials""" account = AccountFactory(user=UserFactory(username='******')) result = Fetcher(account=account).fetch() self.assertFalse(result['success']) self.assertIn('messages', result) self.assertEqual(result['account'], 'bob')
def test_with_unsaved_account(self): """If Account is unsaved, should set 'account' value appropriately.""" account = AccountFactory.build(user=None) result = Fetcher(account=account).fetch() self.assertFalse(result['success']) self.assertIn('messages', result) self.assertEqual(result['account'], 'Unsaved Account')
def test_account_with_no_user(self): """If Account has no user should set 'account' value appropriately.""" account = AccountFactory(user=None) result = Fetcher(account=account).fetch() self.assertFalse(result['success']) self.assertIn('messages', result) self.assertEqual(result['account'], 'Account: 1')
def test_failure_with_no_child_save_results(self, call_api): """Requires a child class to set its own _call_api().""" account = AccountFactory(user=UserFactory(username='******'), api_key='1234', api_secret='9876') result = Fetcher(account=account).fetch() self.assertFalse(result['success']) self.assertIn('messages', result)
def test_returns_true_with_creds(self, save_results, call_api): """Success is true if Account has API credentials""" account = AccountFactory(user=UserFactory(username='******'), api_key='1234', api_secret='9876') result = Fetcher(account=account).fetch() self.assertEqual(result['account'], 'terry') self.assertTrue(result['success']) self.assertEqual(result['fetched'], 0)
def test_returns_false_when_extra_data_fetching_fails( self, call_api, fetch_extra): fetch_extra.side_effect = FetchError('Oh dear') account = AccountFactory(user=UserFactory(username='******'), api_key='1234', api_secret='9876') result = Fetcher(account=account).fetch() self.assertFalse(result['success']) self.assertIn('Oh dear', result['messages'][0])
def test_requires_valid_account_object(self): with self.assertRaises(ValueError): result = Fetcher(account=None)
def test_requires_an_account_argument(self): with self.assertRaises(TypeError): result = Fetcher()