def test_mutable_delete(self, mock_send_request): try: model = Mutable() self.assertRaises(dockercloud.ApiError, model.delete) Mutable.endpoint = "fake" model._detail_uri = "fake/uuid" mock_send_request.side_effect = [{"key": "value"}, None] self.assertTrue(model.delete()) self.assertEqual("value", model.key) mock_send_request.assert_called_with("DELETE", "fake/uuid") self.assertTrue(model.delete()) self.assertIsNone(model._detail_uri) self.assertFalse(model.is_dirty) finally: if hasattr(Mutable, "endpoint"): delattr(Mutable, "endpoint")
def test_mutable_delete(self, mock_send_request): try: model = Mutable() self.assertRaises(dockercloud.ApiError, model.delete) Mutable.endpoint = 'fake' model._detail_uri = 'fake/uuid' mock_send_request.side_effect = [{'key': 'value'}, None] self.assertTrue(model.delete()) self.assertEqual('value', model.key) mock_send_request.assert_called_with('DELETE', 'fake/uuid') self.assertTrue(model.delete()) self.assertIsNone(model._detail_uri) self.assertFalse(model.is_dirty) finally: if hasattr(Mutable, 'endpoint'): delattr(Mutable, 'endpoint')
def test_mutable_save(self, mock_send_request): try: self.assertTrue(Mutable().save()) model = Mutable() model.key = 'value' self.assertRaises(AssertionError, model.save) Mutable.endpoint = 'endpoint' Mutable.subsystem = 'subsystem' mock_send_request.return_value = None result = model.save() mock_send_request.assert_called_with( 'POST', 'api/subsystem/%s/endpoint' % Mutable._api_version, data=json.dumps({'key': 'value'})) self.assertFalse(result) mock_send_request.return_value = {'newkey': 'newvalue'} result = model.save() mock_send_request.assert_called_with( 'POST', 'api/subsystem/%s/endpoint' % Mutable._api_version, data=json.dumps({'key': 'value'})) self.assertTrue(result) self.assertEqual('newvalue', model.newkey) model.key = 'another value' mock_send_request.return_value = {'newkey2': 'newvalue2'} model._detail_uri = 'api/subsystem/%s/endpoint/uuid' % Immutable._api_version result = model.save() mock_send_request.assert_called_with( 'PATCH', 'api/subsystem/%s/endpoint/uuid' % Mutable._api_version, data=json.dumps({'key': 'another value'})) self.assertTrue(result) self.assertEqual('another value', model.key) self.assertEqual('newvalue2', model.newkey2) finally: if hasattr(Mutable, 'endpoint'): delattr(Mutable, 'endpoint')
def test_mutable_save(self, mock_send_request): try: self.assertTrue(Mutable().save()) model = Mutable() model.key = "value" self.assertRaises(AssertionError, model.save) Mutable.endpoint = "endpoint" Mutable.subsystem = "subsystem" mock_send_request.return_value = None result = model.save() mock_send_request.assert_called_with( "POST", "api/subsystem/%s/endpoint" % Mutable._api_version, data=json.dumps({"key": "value"}) ) self.assertFalse(result) mock_send_request.return_value = {"newkey": "newvalue"} result = model.save() mock_send_request.assert_called_with( "POST", "api/subsystem/%s/endpoint" % Mutable._api_version, data=json.dumps({"key": "value"}) ) self.assertTrue(result) self.assertEqual("newvalue", model.newkey) model.key = "another value" mock_send_request.return_value = {"newkey2": "newvalue2"} model._detail_uri = "api/subsystem/%s/endpoint/uuid" % Immutable._api_version result = model.save() mock_send_request.assert_called_with( "PATCH", "api/subsystem/%s/endpoint/uuid" % Mutable._api_version, data=json.dumps({"key": "another value"}), ) self.assertTrue(result) self.assertEqual("another value", model.key) self.assertEqual("newvalue2", model.newkey2) finally: if hasattr(Mutable, "endpoint"): delattr(Mutable, "endpoint")