Skip to content

Commit 68f4114

Browse files
author
Gauvain Pocentek
committed
tests for objects mixins
1 parent b776c5e commit 68f4114

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

gitlab/tests/test_mixins.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,41 @@
3232
from gitlab.mixins import * # noqa
3333

3434

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+
3570
class TestMetaMixins(unittest.TestCase):
3671
def test_retrieve_mixin(self):
3772
class M(RetrieveMixin):
@@ -352,3 +387,25 @@ def resp_cont(url, request):
352387
with HTTMock(resp_cont):
353388
mgr = M(self.gl)
354389
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

Comments
 (0)