def test_restful_setchanges(self): model = Restful() model.__setchanges__("abc") self.assertEqual("abc", model.__changedattrs__) model.__setchanges__(None) self.assertIsNone(model.__changedattrs__)
def test_restful_loaddict(self): model = Restful() self.assertRaises(AssertionError, model._loaddict, {'key': 'value'}) model.endpoint = 'fake' model._loaddict({'key': 'value'}) self.assertEqual('value', model.key) self.assertEqual('fake/uuid', model._detail_uri) self.assertEqual([], model.__getchanges__())
def test_restful_loaddict(self): model = Restful() self.assertRaises(AssertionError, model._loaddict, {"key": "value"}) model.endpoint = "fake" model._loaddict({"key": "value"}) self.assertEqual("value", model.key) self.assertEqual("fake/uuid", model._detail_uri) self.assertEqual([], model.__getchanges__())
def test_restful_expand_attribute(self, mock_send_request): model = Restful() self.assertRaises(tutum.TutumApiError, model._expand_attribute, 'attribute') model._detail_uri = 'fake/uuid' mock_send_request.side_effect = [{'key': 'value'}, None] self.assertEqual('value', model._expand_attribute('key')) self.assertIsNone(model._expand_attribute('key'))
def test_restful_expand_attribute(self, mock_send_request): model = Restful() self.assertRaises(tutum.TutumApiError, model._expand_attribute, "attribute") model._detail_uri = "fake/uuid" mock_send_request.side_effect = [{"key": "value"}, None] self.assertEqual("value", model._expand_attribute("key")) self.assertIsNone(model._expand_attribute("key"))
def test_restful_perform_action(self, mock_send_request): try: model = Restful() self.assertRaises(tutum.TutumApiError, model._perform_action, "action") Restful.endpoint = "fake" model._detail_uri = "fake/uuid" mock_send_request.side_effect = [{"key": "value"}, None] self.assertTrue(model._perform_action("action", {"key": "value"})) self.assertEqual("value", model.key) mock_send_request.assert_called_with("POST", "fake/uuid/action", data={"key": "value"}) self.assertFalse(model._perform_action("action", {"key": "value"})) finally: if hasattr(Restful, "endpoint"): delattr(Restful, "endpoint")
def test_restful_perform_action(self, mock_send_request): try: model = Restful() self.assertRaises(tutum.TutumApiError, model._perform_action, 'action') Restful.endpoint = 'fake' model._detail_uri = 'fake/uuid' mock_send_request.side_effect = [{'key': 'value'}, None] self.assertTrue(model._perform_action('action', {'key': 'value'})) self.assertEqual('value', model.key) mock_send_request.assert_called_with('POST', 'fake/uuid/action', data={'key': 'value'}) self.assertFalse(model._perform_action('action', {'key': 'value'})) finally: if hasattr(Restful, 'endpoint'): delattr(Restful, 'endpoint')
def test_restful_setchanges(self): model = Restful() model.__setchanges__('abc') self.assertEqual('abc', model.__changedattrs__) model.__setchanges__(None) self.assertIsNone(model.__changedattrs__)
def test_restful_setattr(self): model = Restful() setattr(model, 'key', 'value') self.assertEqual('value', model.key) self.assertEqual(['key'], model.__changedattrs__) setattr(model, 'key', 'other value') self.assertEqual('other value', model.key) self.assertEqual(['key'], model.__changedattrs__) setattr(model, 'another_key', 'another_value') self.assertEqual('another_value', model.another_key) self.assertEqual(['key', 'another_key'], model.__changedattrs__)
def test_restful_get_all_attributes(self): model = Restful() model.key = 'value' self.assertDictEqual({'key': 'value'}, model.get_all_attributes())
def test_restful_is_dirty(self): model = Restful() self.assertFalse(model.is_dirty) model.key = "value" self.assertTrue(model.is_dirty)
def test_restful_init(self): model = Restful(key1='value1', key2='value2') self.assertEqual('value1', model.key1) self.assertEqual('value2', model.key2)
def test_restful_getchanges(self): model = Restful() self.assertEqual([], model.__getchanges__()) model.__changedattrs__ = ["tutum"] self.assertEqual(["tutum"], model.__getchanges__())
def test_restful_get_all_attributes(self): model = Restful() model.key = "value" self.assertDictEqual({"key": "value"}, model.get_all_attributes())
def test_restful_getchanges(self): model = Restful() self.assertEqual([], model.__getchanges__()) model.__changedattrs__ = ['tutum'] self.assertEqual(['tutum'], model.__getchanges__())
def test_restful_is_dirty(self): model = Restful() self.assertFalse(model.is_dirty) model.key = 'value' self.assertTrue(model.is_dirty)
def test_restful_pk(self): model = Restful() self.assertEqual(model.__class__._pk_key(), model.pk)