Exemplo 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__)
Exemplo n.º 2
0
    def test_restful_expand_attribute(self, mock_send_request):
        model = Restful()
        self.assertRaises(dockercloud.ApiError, 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(dockercloud.ApiError, model._expand_attribute,
                          'attribute')

        model._resource_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):

        model = Restful()
        self.assertRaises(dockercloud.ApiError, model._perform_action,
                          'action')

        model.endpoint = 'fake'
        model.subsystem = "subsystem"
        model.resource_uri = "/".join([
            "api", model.subsystem, model._api_version,
            model.endpoint.lstrip("/"), model.pk
        ])
        model._resource_uri = model.resource_uri
        mock_send_request.side_effect = [{'key': 'value'}, None]
        self.assertTrue(
            model._perform_action('action',
                                  params={'k': 'v'},
                                  data={'key': 'value'}))
        self.assertEqual('value', model.key)
        mock_send_request.assert_called_with(
            'POST',
            "/".join([model._resource_uri, "action"]),
            data={'key': 'value'},
            params={'k': 'v'})

        self.assertFalse(model._perform_action('action', {'key': 'value'}))
    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()
     model.endpoint = 'resource_uri'
     model.subsystem = "subsystem"
     resource_uri = "/".join([
         "api", model.subsystem, model._api_version,
         model.endpoint.lstrip("/"), model.pk
     ])
     model._loaddict({'key': 'value', "resource_uri": resource_uri})
     self.assertEqual('value', model.key)
     self.assertEqual(resource_uri, model._resource_uri)
     self.assertEqual([], model.__getchanges__())
    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__)
Exemplo n.º 8
0
    def test_restful_loaddict(self):
        model = Restful()
        self.assertRaises(AssertionError, model._loaddict, {'key': 'value'})

        model.endpoint = 'endpoint'
        model.subsystem = "subsystem"
        model._loaddict({'key': 'value'})
        self.assertEqual('value', model.key)
        self.assertEqual(
            "/".join([
                "api", model.subsystem, model._api_version,
                model.endpoint.lstrip("/"), model.pk
            ]), model._detail_uri)
        self.assertEqual([], model.__getchanges__())
Exemplo n.º 9
0
    def test_restful_loaddict(self):
        model = Restful()
        self.assertRaises(AssertionError, model._loaddict, {"key": "value"})

        model.endpoint = "endpoint"
        model.subsystem = "subsystem"
        model._loaddict({"key": "value"})
        self.assertEqual("value", model.key)
        self.assertEqual(
            "/".join(["api", model.subsystem, model._api_version, model.endpoint.lstrip("/"), model.pk]),
            model._detail_uri,
        )
        self.assertEqual([], model.__getchanges__())
Exemplo n.º 10
0
    def test_restful_perform_action(self, mock_send_request):
        try:
            model = Restful()
            self.assertRaises(dockercloud.ApiError, model._perform_action, "action")

            model.endpoint = "fake"
            model.subsystem = "subsystem"
            model._detail_uri = "/".join(
                ["api", model.subsystem, model._api_version, model.endpoint.lstrip("/"), model.pk]
            )
            mock_send_request.side_effect = [{"key": "value"}, None]
            self.assertTrue(model._perform_action("action", params={"k": "v"}, data={"key": "value"}))
            self.assertEqual("value", model.key)
            mock_send_request.assert_called_with(
                "POST", "/".join([model._detail_uri, "action"]), data={"key": "value"}, params={"k": "v"}
            )

            self.assertFalse(model._perform_action("action", {"key": "value"}))

        finally:
            if hasattr(Restful, "endpoint"):
                delattr(Restful, "endpoint")
 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_pk(self):
     model = Restful()
     self.assertEqual(model.__class__._pk_key(), model.pk)
Exemplo n.º 14
0
 def test_restful_get_all_attributes(self):
     model = Restful()
     model.key = "value"
     self.assertDictEqual({"key": "value"}, model.get_all_attributes())
Exemplo n.º 15
0
    def test_restful_getchanges(self):
        model = Restful()
        self.assertEqual([], model.__getchanges__())

        model.__changedattrs__ = ["dockercloud"]
        self.assertEqual(["dockercloud"], model.__getchanges__())
    def test_restful_getchanges(self):
        model = Restful()
        self.assertEqual([], model.__getchanges__())

        model.__changedattrs__ = ['dockercloud']
        self.assertEqual(['dockercloud'], model.__getchanges__())
 def test_restful_init(self):
     model = Restful(key1='value1', key2='value2')
     self.assertEqual('value1', model.key1)
     self.assertEqual('value2', model.key2)
Exemplo n.º 18
0
    def test_restful_is_dirty(self):
        model = Restful()
        self.assertFalse(model.is_dirty)

        model.key = "value"
        self.assertTrue(model.is_dirty)