def test_immutable_list(self, mock_send_request): self.assertRaises(AssertionError, Immutable.list) try: kwargs = {'key': 'value'} ret_json = { "meta": { "limit": 25, "next": None, "offset": 0, "previous": None, "total_count": 1 }, "objects": [{ "key": "value1" }, { "key": "value2" }] } mock_send_request.return_value = ret_json Immutable.endpoint = 'fake' models = Immutable.list(**kwargs) mock_send_request.assert_called_with('GET', 'api/subsystem/%s/fake' % Immutable._api_version, params=kwargs) self.assertEqual(2, len(models)) self.assertIsInstance(models[0], Immutable) self.assertEqual('value1', models[0].key) self.assertIsInstance(models[1], Immutable) self.assertEqual('value2', models[1].key) finally: if hasattr(Immutable, 'endpoint'): delattr(Immutable, 'endpoint')
def test_immutable_fetch(self, mock_send_request): self.assertRaises(AssertionError, Immutable.fetch, "uuid") try: ret_json = {"key": "value"} mock_send_request.return_value = ret_json Immutable.endpoint = "endpoint" Immutable.subsystem = "subsystem" model = Immutable.fetch("uuid") mock_send_request.assert_called_with("GET", "api/subsystem/%s/endpoint/uuid" % Immutable._api_version) self.assertIsInstance(model, Immutable) self.assertEqual("value", model.key) finally: if hasattr(Immutable, "endpoint"): delattr(Immutable, "endpoint")
def test_immutable_fetch(self, mock_send_request): self.assertRaises(AssertionError, Immutable.fetch, 'uuid') try: ret_json = {"key": "value"} mock_send_request.return_value = ret_json Immutable.endpoint = 'endpoint' Immutable.subsystem = "subsystem" model = Immutable.fetch('uuid') mock_send_request.assert_called_with( 'GET', 'api/subsystem/%s/endpoint/uuid' % Immutable._api_version) self.assertIsInstance(model, Immutable) self.assertEqual('value', model.key) finally: if hasattr(Immutable, 'endpoint'): delattr(Immutable, 'endpoint')
def test_immutable_refresh(self, mock_send_request): model = Immutable() model.key = 'value' self.assertFalse(model.refresh(force=False)) self.assertRaises(dockercloud.ApiError, model.refresh, force=True) Immutable.endpoint = 'resource_uri' Immutable.subsystem = 'subsystem' model.resource_uri = 'api/subsystem/%s/resource_uri/uuid' % Immutable._api_version model._resource_uri = model.resource_uri mock_send_request.side_effect = [{'newkey': 'newvalue'}, None] self.assertTrue(model.refresh(force=True)) self.assertEqual('newvalue', model.newkey) mock_send_request.assert_called_with('GET', model._resource_uri) self.assertFalse(model.refresh(force=True)) mock_send_request.assert_called_with('GET', model._resource_uri)
def test_immutable_fetch(self, mock_send_request): try: delattr(Immutable, 'endpoint') delattr(Immutable, 'subsystem') except: pass self.assertRaises(AssertionError, Immutable.fetch, 'uuid') ret_json = {"key": "value"} mock_send_request.return_value = ret_json Immutable.endpoint = 'resource_uri' Immutable.subsystem = "subsystem" model = Immutable.fetch('uuid') mock_send_request.assert_called_with( 'GET', 'api/subsystem/%s/resource_uri/uuid' % Immutable._api_version) self.assertIsInstance(model, Immutable) self.assertEqual('value', model.key)
def test_immutable_list(self, mock_send_request): self.assertRaises(AssertionError, Immutable.list) try: kwargs = {"key": "value"} ret_json = { "meta": {"limit": 25, "next": None, "offset": 0, "previous": None, "total_count": 1}, "objects": [{"key": "value1"}, {"key": "value2"}], } mock_send_request.return_value = ret_json Immutable.endpoint = "fake" models = Immutable.list(**kwargs) mock_send_request.assert_called_with("GET", "api/subsystem/%s/fake" % Immutable._api_version, params=kwargs) self.assertEqual(2, len(models)) self.assertIsInstance(models[0], Immutable) self.assertEqual("value1", models[0].key) self.assertIsInstance(models[1], Immutable) self.assertEqual("value2", models[1].key) finally: if hasattr(Immutable, "endpoint"): delattr(Immutable, "endpoint")
def test_immutable_refresh(self, mock_send_request): try: model = Immutable() model.key = "value" self.assertFalse(model.refresh(force=False)) self.assertRaises(dockercloud.ApiError, model.refresh, force=True) Immutable.endpoint = "endpoint" Immutable.subsystem = "subsystem" model._detail_uri = "api/subsystem/%s/endpoint/uuid" % Immutable._api_version mock_send_request.side_effect = [{"newkey": "newvalue"}, None] self.assertTrue(model.refresh(force=True)) self.assertEqual("newvalue", model.newkey) mock_send_request.assert_called_with("GET", model._detail_uri) self.assertFalse(model.refresh(force=True)) mock_send_request.assert_called_with("GET", model._detail_uri) finally: if hasattr(Immutable, "endpoint"): delattr(Immutable, "endpoint")