def test_post_returns_body_of_response_if_return_bool_False( self, mock_request): mock_request.return_value = {"success": True} base_resource = BaseResource(Mock(), "test/{id}", {"id": "fake_id"}) response = base_resource.post(return_bool=False) self.assertEqual({"success": True}, response)
def test_constructor_logs_error_if_unable_to_unacamelize_definition( self, mock_logging_error, mock_uncamelize): mock_uncamelize.side_effect = Exception BaseResource(Mock(), "/some-uri", {"foo": "bar"}) mock_logging_error.assert_called_with( "Invalid response received for /some-uri")
def test_uri_for_joins_arguments_with_base_uri(self): base_resource = BaseResource(Mock(), "test/{id}", {"id": "fake_id"}) uri = base_resource._uri_for('some','other-resource') self.assertEqual("test/fake_id/some/other-resource", uri)
def test_post_returns_body_of_response_if_return_bool_False(self, mock_request): mock_request.return_value = {"success": True} base_resource = BaseResource(Mock(), "test/{id}", {"id": "fake_id"}) response = base_resource.post(return_bool=False) self.assertEqual({"success": True}, response)
def test_post_returns_false_if_success_is_false(self, mock_request): mock_request.return_value = {"nope": False} base_resource = BaseResource(Mock(), "test/{id}", {"id": "fake_id"}) response = base_resource.post() self.assertFalse(response)
def test_post_returns_boolean_by_default(self, mock_request): mock_request.return_value = {"success": True} base_resource = BaseResource(Mock(), "test/{id}", {"id": "fake_id"}) response = base_resource.post() self.assertTrue(response)
def test_delete_sends_delete_request_to_resource_base_uri(self, mock_request): base_resource = BaseResource(Mock(), "test/{id}", {"id": "fake_id"}) base_resource.delete() mock_request.assert_called_with('', method="DELETE")
def test_uri_for_joins_arguments_with_base_uri(self): base_resource = BaseResource(Mock(), "test/{id}", {"id": "fake_id"}) uri = base_resource._uri_for('some', 'other-resource') self.assertEqual("test/fake_id/some/other-resource", uri)
def test_constructor_logs_error_if_definition_is_empty_string( self, mock_logging_error): BaseResource(Mock(spec=[]), "/some-uri", "") mock_logging_error.assert_called_with( "Empty response received for /some-uri")
def test_delete_sends_delete_request_to_resource_base_uri( self, mock_request): base_resource = BaseResource(Mock(), "test/{id}", {"id": "fake_id"}) base_resource.delete() mock_request.assert_called_with('', method="DELETE")
def test_delete_returns_boolean(self, mock_request): mock_request.return_value = {"success": True} base_resource = BaseResource(Mock(), "test/{id}", {"id": "fake_id"}) response = base_resource.delete() self.assertEqual(True, response)