def test_restful_perform_action(self, mock_send_request): model = Restful() self.assertRaises(dockercloud.ApiError, model._perform_action, 'action') model.endpoint = 'fake' model.subsystem = "subsystem" model.resource_uri = "/".join([ "api", model.subsystem, model._api_version, model.endpoint.lstrip("/"), model.pk ]) model._resource_uri = model.resource_uri mock_send_request.side_effect = [{'key': 'value'}, None] self.assertTrue( model._perform_action('action', params={'k': 'v'}, data={'key': 'value'})) self.assertEqual('value', model.key) mock_send_request.assert_called_with( 'POST', "/".join([model._resource_uri, "action"]), data={'key': 'value'}, params={'k': 'v'}) self.assertFalse(model._perform_action('action', {'key': 'value'}))
def test_restful_loaddict(self): model = Restful() model.endpoint = 'resource_uri' model.subsystem = "subsystem" resource_uri = "/".join([ "api", model.subsystem, model._api_version, model.endpoint.lstrip("/"), model.pk ]) model._loaddict({'key': 'value', "resource_uri": resource_uri}) self.assertEqual('value', model.key) self.assertEqual(resource_uri, model._resource_uri) self.assertEqual([], model.__getchanges__())
def test_restful_loaddict(self): model = Restful() self.assertRaises(AssertionError, model._loaddict, {"key": "value"}) model.endpoint = "endpoint" model.subsystem = "subsystem" model._loaddict({"key": "value"}) self.assertEqual("value", model.key) self.assertEqual( "/".join(["api", model.subsystem, model._api_version, model.endpoint.lstrip("/"), model.pk]), model._detail_uri, ) self.assertEqual([], model.__getchanges__())
def test_restful_loaddict(self): model = Restful() self.assertRaises(AssertionError, model._loaddict, {'key': 'value'}) model.endpoint = 'endpoint' model.subsystem = "subsystem" model._loaddict({'key': 'value'}) self.assertEqual('value', model.key) self.assertEqual( "/".join([ "api", model.subsystem, model._api_version, model.endpoint.lstrip("/"), model.pk ]), model._detail_uri) self.assertEqual([], model.__getchanges__())
def test_restful_perform_action(self, mock_send_request): try: model = Restful() self.assertRaises(dockercloud.ApiError, model._perform_action, "action") model.endpoint = "fake" model.subsystem = "subsystem" model._detail_uri = "/".join( ["api", model.subsystem, model._api_version, model.endpoint.lstrip("/"), model.pk] ) mock_send_request.side_effect = [{"key": "value"}, None] self.assertTrue(model._perform_action("action", params={"k": "v"}, data={"key": "value"})) self.assertEqual("value", model.key) mock_send_request.assert_called_with( "POST", "/".join([model._detail_uri, "action"]), data={"key": "value"}, params={"k": "v"} ) self.assertFalse(model._perform_action("action", {"key": "value"})) finally: if hasattr(Restful, "endpoint"): delattr(Restful, "endpoint")