Esempio n. 1
0
    def test_restful_setchanges(self):
        model = Restful()
        model.__setchanges__("abc")
        self.assertEqual("abc", model.__changedattrs__)

        model.__setchanges__(None)
        self.assertIsNone(model.__changedattrs__)
Esempio n. 2
0
    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__())
Esempio n. 3
0
    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__())
Esempio n. 4
0
    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'))
Esempio n. 5
0
    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"))
Esempio n. 6
0
    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'))
Esempio n. 7
0
    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")
Esempio n. 8
0
    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')
Esempio n. 9
0
    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')
Esempio n. 10
0
    def test_restful_setchanges(self):
        model = Restful()
        model.__setchanges__('abc')
        self.assertEqual('abc', model.__changedattrs__)

        model.__setchanges__(None)
        self.assertIsNone(model.__changedattrs__)
Esempio n. 11
0
    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__)
Esempio n. 12
0
    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__())
Esempio n. 13
0
 def test_restful_get_all_attributes(self):
     model = Restful()
     model.key = 'value'
     self.assertDictEqual({'key': 'value'}, model.get_all_attributes())
Esempio n. 14
0
    def test_restful_is_dirty(self):
        model = Restful()
        self.assertFalse(model.is_dirty)

        model.key = "value"
        self.assertTrue(model.is_dirty)
Esempio n. 15
0
 def test_restful_init(self):
     model = Restful(key1='value1', key2='value2')
     self.assertEqual('value1', model.key1)
     self.assertEqual('value2', model.key2)
Esempio n. 16
0
    def test_restful_getchanges(self):
        model = Restful()
        self.assertEqual([], model.__getchanges__())

        model.__changedattrs__ = ["tutum"]
        self.assertEqual(["tutum"], model.__getchanges__())
Esempio n. 17
0
 def test_restful_get_all_attributes(self):
     model = Restful()
     model.key = "value"
     self.assertDictEqual({"key": "value"}, model.get_all_attributes())
Esempio n. 18
0
    def test_restful_getchanges(self):
        model = Restful()
        self.assertEqual([], model.__getchanges__())

        model.__changedattrs__ = ['tutum']
        self.assertEqual(['tutum'], model.__getchanges__())
Esempio n. 19
0
    def test_restful_is_dirty(self):
        model = Restful()
        self.assertFalse(model.is_dirty)

        model.key = 'value'
        self.assertTrue(model.is_dirty)
Esempio n. 20
0
 def test_restful_pk(self):
     model = Restful()
     self.assertEqual(model.__class__._pk_key(), model.pk)
Esempio n. 21
0
 def test_restful_get_all_attributes(self):
     model = Restful()
     model.key = 'value'
     self.assertDictEqual({'key': 'value'}, model.get_all_attributes())