Exemplo n.º 1
0
    def test_mutable_save(self, mock_send_request):
        try:
            self.assertTrue(Mutable().save())

            model = Mutable()
            model.key = "value"
            self.assertRaises(AssertionError, model.save)

            Mutable.endpoint = "fake"
            mock_send_request.return_value = None
            result = model.save()
            mock_send_request.assert_called_with("POST", "fake", data=json.dumps({"key": "value"}))
            self.assertFalse(result)

            mock_send_request.return_value = {"newkey": "newvalue"}
            result = model.save()
            mock_send_request.assert_called_with("POST", "fake", data=json.dumps({"key": "value"}))
            self.assertTrue(result)
            self.assertEqual("newvalue", model.newkey)

            model.key = "another value"
            mock_send_request.return_value = {"newkey2": "newvalue2"}
            model._detail_uri = "fake/uuid"
            result = model.save()
            mock_send_request.assert_called_with("PATCH", "fake/uuid", data=json.dumps({"key": "another value"}))
            self.assertTrue(result)
            self.assertEqual("another value", model.key)
            self.assertEqual("newvalue2", model.newkey2)
        finally:
            if hasattr(Mutable, "endpoint"):
                delattr(Mutable, "endpoint")
Exemplo n.º 2
0
    def test_mutable_save(self, mock_send_request):
        try:
            self.assertTrue(Mutable().save())

            model = Mutable()
            model.key = 'value'
            self.assertRaises(AssertionError, model.save)

            Mutable.endpoint = 'fake'
            mock_send_request.return_value = None
            result = model.save()
            mock_send_request.assert_called_with('POST', 'fake', data=json.dumps({'key': 'value'}))
            self.assertFalse(result)

            mock_send_request.return_value = {'newkey': 'newvalue'}
            result = model.save()
            mock_send_request.assert_called_with('POST', 'fake', data=json.dumps({'key': 'value'}))
            self.assertTrue(result)
            self.assertEqual('newvalue', model.newkey)

            model.key = 'another value'
            mock_send_request.return_value = {'newkey2': 'newvalue2'}
            model._detail_uri = 'fake/uuid'
            result = model.save()
            mock_send_request.assert_called_with('PATCH', 'fake/uuid', data=json.dumps({'key': 'another value'}))
            self.assertTrue(result)
            self.assertEqual('another value', model.key)
            self.assertEqual('newvalue2', model.newkey2)
        finally:
            if hasattr(Mutable, 'endpoint'):
                delattr(Mutable, 'endpoint')
Exemplo n.º 3
0
    def test_mutable_delete(self, mock_send_request):
        try:
            model = Mutable()
            self.assertRaises(tutum.TutumApiError, model.delete)

            Mutable.endpoint = "fake"
            model._detail_uri = "fake/uuid"
            mock_send_request.side_effect = [{"key": "value"}, None]
            self.assertTrue(model.delete())
            self.assertEqual("value", model.key)
            mock_send_request.assert_called_with("DELETE", "fake/uuid")

            self.assertTrue(model.delete())
            self.assertIsNone(model._detail_uri)
            self.assertFalse(model.is_dirty)
        finally:
            if hasattr(Mutable, "endpoint"):
                delattr(Mutable, "endpoint")
Exemplo n.º 4
0
    def test_mutable_delete(self, mock_send_request):
        try:
            model = Mutable()
            self.assertRaises(tutum.TutumApiError, model.delete)

            Mutable.endpoint = 'fake'
            model._detail_uri = 'fake/uuid'
            mock_send_request.side_effect = [{'key': 'value'}, None]
            self.assertTrue(model.delete())
            self.assertEqual('value', model.key)
            mock_send_request.assert_called_with('DELETE', 'fake/uuid')

            self.assertTrue(model.delete())
            self.assertIsNone(model._detail_uri)
            self.assertFalse(model.is_dirty)
        finally:
            if hasattr(Mutable, 'endpoint'):
                delattr(Mutable, 'endpoint')
Exemplo n.º 5
0
    def test_mutable_delete(self, mock_send_request):
        try:
            model = Mutable()
            self.assertRaises(tutum.TutumApiError, model.delete)

            Mutable.endpoint = 'fake'
            model._detail_uri = 'fake/uuid'
            mock_send_request.side_effect = [{'key': 'value'}, None]
            self.assertTrue(model.delete())
            self.assertEqual('value', model.key)
            mock_send_request.assert_called_with('DELETE', 'fake/uuid')

            self.assertTrue(model.delete())
            self.assertIsNone(model._detail_uri)
            self.assertFalse(model.is_dirty)
        finally:
            if hasattr(Mutable, 'endpoint'):
                delattr(Mutable, 'endpoint')
Exemplo n.º 6
0
    def test_mutable_save(self, mock_send_request):
        try:
            self.assertTrue(Mutable().save())

            model = Mutable()
            model.key = 'value'
            self.assertRaises(AssertionError, model.save)

            Mutable.endpoint = 'fake'
            mock_send_request.return_value = None
            result = model.save()
            mock_send_request.assert_called_with('POST',
                                                 'fake',
                                                 data=json.dumps(
                                                     {'key': 'value'}))
            self.assertFalse(result)

            mock_send_request.return_value = {'newkey': 'newvalue'}
            result = model.save()
            mock_send_request.assert_called_with('POST',
                                                 'fake',
                                                 data=json.dumps(
                                                     {'key': 'value'}))
            self.assertTrue(result)
            self.assertEqual('newvalue', model.newkey)

            model.key = 'another value'
            mock_send_request.return_value = {'newkey2': 'newvalue2'}
            model._detail_uri = 'fake/uuid'
            result = model.save()
            mock_send_request.assert_called_with('PATCH',
                                                 'fake/uuid',
                                                 data=json.dumps(
                                                     {'key': 'another value'}))
            self.assertTrue(result)
            self.assertEqual('another value', model.key)
            self.assertEqual('newvalue2', model.newkey2)
        finally:
            if hasattr(Mutable, 'endpoint'):
                delattr(Mutable, 'endpoint')