|
1 | 1 | from unittest import TestCase
|
| 2 | +from unittest.mock import call, patch |
| 3 | +from requests import HTTPError |
2 | 4 |
|
3 | 5 | from exceptions import NotFoundError
|
4 | 6 | from metabase.metabase import Metabase
|
5 | 7 | from metabase.resource import CreateResource, DeleteResource, GetResource, ListResource, Resource, UpdateResource
|
| 8 | +from missing import MISSING |
6 | 9 |
|
7 | 10 | from tests.helpers import IntegrationTestCase
|
8 | 11 |
|
@@ -92,6 +95,27 @@ class Collection(CreateResource, GetResource, UpdateResource):
|
92 | 95 | # metabase was updated
|
93 | 96 | self.assertEqual("My New Collection", Collection.get(collection.id).name)
|
94 | 97 |
|
| 98 | + def test_update_missing(self): |
| 99 | + """Ensure UpdateResource.update() ignores arguments equal to MISSING.""" |
| 100 | + class Collection(UpdateResource): |
| 101 | + ENDPOINT = "/api/collection" |
| 102 | + |
| 103 | + test_matrix = [ |
| 104 | + ({"a": "A", "b": "B"}, {"a": "A", "b": "B"}), |
| 105 | + ({"a": "A", "b": MISSING}, {"a": "A"}), |
| 106 | + ({"a": MISSING, "b": MISSING}, {}), |
| 107 | + ] |
| 108 | + |
| 109 | + for kwargs, expected in test_matrix: |
| 110 | + with patch("metabase.resource.Metabase.put") as mock: |
| 111 | + try: |
| 112 | + Collection(id=1).update(**kwargs) |
| 113 | + except HTTPError: |
| 114 | + pass |
| 115 | + |
| 116 | + self.assertTrue(mock.called) |
| 117 | + self.assertIsNone(mock.assert_called_with("/api/collection/1", json=expected)) |
| 118 | + |
95 | 119 |
|
96 | 120 | class DeleteResourceTests(IntegrationTestCase):
|
97 | 121 | def test_delete(self):
|
|
0 commit comments