def test_get_not_found(self): """ Test that getting a non-existent infection raises a StrongarmHttpError. """ id = 'does-not-exist' msg = 'Not found.' responses.add(responses.GET, strongarm.host + Infection.endpoint + id + '/', status=404, content_type='application/json', body=json.dumps({'detail': msg})) with self.assertRaises(strongarm.StrongarmHttpError) as exp: Infection.get(id) self.assertEqual(len(responses.calls), 1) self.assertEqual(exp.exception.status_code, 404) self.assertEqual(exp.exception.detail, msg)
def test_list(self): """ Test that getting all infections returns a PaginatedResourceList with the right elements. """ responses.add(responses.GET, strongarm.host + Infection.endpoint, body=json.dumps(self.list_response), content_type='application/json') infections = Infection.all() self.assertEqual(len(responses.calls), 1) self.assertEqual(len(infections), self.list_response['count']) self.assertIsInstance(infections[0], Infection) self.assertEqual(infections[0].id, self.list_response['results'][0]['id'])
def test_get_exists(self): """ Test that getting an infection returns an instance of Infection with the right attributes. """ id = self.get_response['id'] responses.add(responses.GET, strongarm.host + Infection.endpoint + id + '/', body=json.dumps(self.get_response), content_type='application/json/') infection = Infection.get(id) self.assertEqual(len(responses.calls), 1) self.assertIsInstance(infection, Infection) self.assertEqual(infection.id, id)
def test_delete_success(self): """ Test that an Infection instance does not have a delete attribute. """ id = self.get_response['id'] responses.add(responses.GET, strongarm.host + Infection.endpoint + id + '/', body=json.dumps(self.get_response), content_type='application/json/') # Get the infection to be 'deleted'. infection = Infection.get(id) self.assertEqual(len(responses.calls), 1) self.assertIsInstance(infection, Infection) # Deletion is not possible. self.assertFalse(hasattr(infection, 'delete'))