|
32 | 32 | from gitlab.mixins import * # noqa |
33 | 33 |
|
34 | 34 |
|
| 35 | +class TestObjectMixinsAttributes(unittest.TestCase): |
| 36 | + def test_access_request_mixin(self): |
| 37 | + class O(AccessRequestMixin): |
| 38 | + pass |
| 39 | + |
| 40 | + obj = O() |
| 41 | + self.assertTrue(hasattr(obj, 'approve')) |
| 42 | + |
| 43 | + def test_subscribable_mixin(self): |
| 44 | + class O(SubscribableMixin): |
| 45 | + pass |
| 46 | + |
| 47 | + obj = O() |
| 48 | + self.assertTrue(hasattr(obj, 'subscribe')) |
| 49 | + self.assertTrue(hasattr(obj, 'unsubscribe')) |
| 50 | + |
| 51 | + def test_todo_mixin(self): |
| 52 | + class O(TodoMixin): |
| 53 | + pass |
| 54 | + |
| 55 | + obj = O() |
| 56 | + self.assertTrue(hasattr(obj, 'todo')) |
| 57 | + |
| 58 | + def test_time_tracking_mixin(self): |
| 59 | + class O(TimeTrackingMixin): |
| 60 | + pass |
| 61 | + |
| 62 | + obj = O() |
| 63 | + self.assertTrue(hasattr(obj, 'time_stats')) |
| 64 | + self.assertTrue(hasattr(obj, 'time_estimate')) |
| 65 | + self.assertTrue(hasattr(obj, 'reset_time_estimate')) |
| 66 | + self.assertTrue(hasattr(obj, 'add_spent_time')) |
| 67 | + self.assertTrue(hasattr(obj, 'reset_spent_time')) |
| 68 | + |
| 69 | + |
35 | 70 | class TestMetaMixins(unittest.TestCase): |
36 | 71 | def test_retrieve_mixin(self): |
37 | 72 | class M(RetrieveMixin): |
@@ -352,3 +387,25 @@ def resp_cont(url, request): |
352 | 387 | with HTTMock(resp_cont): |
353 | 388 | mgr = M(self.gl) |
354 | 389 | mgr.delete(42) |
| 390 | + |
| 391 | + def test_save_mixin(self): |
| 392 | + class M(UpdateMixin, FakeManager): |
| 393 | + pass |
| 394 | + |
| 395 | + class O(SaveMixin, RESTObject): |
| 396 | + pass |
| 397 | + |
| 398 | + @urlmatch(scheme="http", netloc="localhost", path='/api/v4/tests/42', |
| 399 | + method="put") |
| 400 | + def resp_cont(url, request): |
| 401 | + headers = {'Content-Type': 'application/json'} |
| 402 | + content = '{"id": 42, "foo": "baz"}' |
| 403 | + return response(200, content, headers, None, 5, request) |
| 404 | + |
| 405 | + with HTTMock(resp_cont): |
| 406 | + mgr = M(self.gl) |
| 407 | + obj = O(mgr, {'id': 42, 'foo': 'bar'}) |
| 408 | + obj.foo = 'baz' |
| 409 | + obj.save() |
| 410 | + self.assertEqual(obj._attrs['foo'], 'baz') |
| 411 | + self.assertDictEqual(obj._updated_attrs, {}) |
0 commit comments