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', 'fake', 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 = "fake" model = Immutable.fetch("uuid") mock_send_request.assert_called_with("GET", "fake/uuid") 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 = 'fake' model = Immutable.fetch('uuid') mock_send_request.assert_called_with('GET', 'fake/uuid') self.assertIsInstance(model, Immutable) self.assertEqual('value', model.key) finally: if hasattr(Immutable, 'endpoint'): delattr(Immutable, 'endpoint')
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', 'fake', 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(tutum.TutumApiError, model.refresh, force=True) Immutable.endpoint = 'fake' model._detail_uri = 'fake/uuid' 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', 'fake/uuid') self.assertFalse(model.refresh(force=True)) mock_send_request.assert_called_with('GET', 'fake/uuid') 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(tutum.TutumApiError, model.refresh, force=True) Immutable.endpoint = "fake" model._detail_uri = "fake/uuid" 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", "fake/uuid") self.assertFalse(model.refresh(force=True)) mock_send_request.assert_called_with("GET", "fake/uuid") finally: if hasattr(Immutable, "endpoint"): delattr(Immutable, "endpoint")