@@ -26,7 +26,7 @@ def _get_target_class():
2626 def _make_one(self, *args, **kw):
2727 return self._get_target_class()(*args, **kw)
2828
29- def _derivedClass(self, path=None):
29+ def _derivedClass(self, path=None, user_project=None ):
3030
3131 class Derived(self._get_target_class()):
3232
@@ -36,30 +36,67 @@ class Derived(self._get_target_class()):
3636 def path(self):
3737 return path
3838
39+ @property
40+ def user_project(self):
41+ return user_project
42+
3943 return Derived
4044
4145 def test_path_is_abstract(self):
4246 mixin = self._make_one()
43- self.assertRaises(NotImplementedError, lambda: mixin.path)
47+ with self.assertRaises(NotImplementedError):
48+ mixin.path
4449
4550 def test_client_is_abstract(self):
4651 mixin = self._make_one()
47- self.assertRaises(NotImplementedError, lambda: mixin.client)
52+ with self.assertRaises(NotImplementedError):
53+ mixin.client
54+
55+ def test_user_project_is_abstract(self):
56+ mixin = self._make_one()
57+ with self.assertRaises(NotImplementedError):
58+ mixin.user_project
4859
4960 def test_reload(self):
5061 connection = _Connection({'foo': 'Foo'})
5162 client = _Client(connection)
5263 derived = self._derivedClass('/path')()
53- # Make sure changes is not a set, so we can observe a change.
64+ # Make sure changes is not a set instance before calling reload
65+ # (which will clear / replace it with an empty set), checked below.
66+ derived._changes = object()
67+ derived.reload(client=client)
68+ self.assertEqual(derived._properties, {'foo': 'Foo'})
69+ kw = connection._requested
70+ self.assertEqual(len(kw), 1)
71+ self.assertEqual(kw[0], {
72+ 'method': 'GET',
73+ 'path': '/path',
74+ 'query_params': {'projection': 'noAcl'},
75+ '_target_object': derived,
76+ })
77+ self.assertEqual(derived._changes, set())
78+
79+ def test_reload_w_user_project(self):
80+ user_project = 'user-project-123'
81+ connection = _Connection({'foo': 'Foo'})
82+ client = _Client(connection)
83+ derived = self._derivedClass('/path', user_project)()
84+ # Make sure changes is not a set instance before calling reload
85+ # (which will clear / replace it with an empty set), checked below.
5486 derived._changes = object()
5587 derived.reload(client=client)
5688 self.assertEqual(derived._properties, {'foo': 'Foo'})
5789 kw = connection._requested
5890 self.assertEqual(len(kw), 1)
59- self.assertEqual(kw[0]['method'], 'GET')
60- self.assertEqual(kw[0]['path'], '/path')
61- self.assertEqual(kw[0]['query_params'], {'projection': 'noAcl'})
62- # Make sure changes get reset by reload.
91+ self.assertEqual(kw[0], {
92+ 'method': 'GET',
93+ 'path': '/path',
94+ 'query_params': {
95+ 'projection': 'noAcl',
96+ 'userProject': user_project,
97+ },
98+ '_target_object': derived,
99+ })
63100 self.assertEqual(derived._changes, set())
64101
65102 def test__set_properties(self):
@@ -87,11 +124,42 @@ def test_patch(self):
87124 self.assertEqual(derived._properties, {'foo': 'Foo'})
88125 kw = connection._requested
89126 self.assertEqual(len(kw), 1)
90- self.assertEqual(kw[0]['method'], 'PATCH')
91- self.assertEqual(kw[0]['path'], '/path')
92- self.assertEqual(kw[0]['query_params'], {'projection': 'full'})
93- # Since changes does not include `baz`, we don't see it sent.
94- self.assertEqual(kw[0]['data'], {'bar': BAR})
127+ self.assertEqual(kw[0], {
128+ 'method': 'PATCH',
129+ 'path': '/path',
130+ 'query_params': {'projection': 'full'},
131+ # Since changes does not include `baz`, we don't see it sent.
132+ 'data': {'bar': BAR},
133+ '_target_object': derived,
134+ })
135+ # Make sure changes get reset by patch().
136+ self.assertEqual(derived._changes, set())
137+
138+ def test_patch_w_user_project(self):
139+ user_project = 'user-project-123'
140+ connection = _Connection({'foo': 'Foo'})
141+ client = _Client(connection)
142+ derived = self._derivedClass('/path', user_project)()
143+ # Make sure changes is non-empty, so we can observe a change.
144+ BAR = object()
145+ BAZ = object()
146+ derived._properties = {'bar': BAR, 'baz': BAZ}
147+ derived._changes = set(['bar']) # Ignore baz.
148+ derived.patch(client=client)
149+ self.assertEqual(derived._properties, {'foo': 'Foo'})
150+ kw = connection._requested
151+ self.assertEqual(len(kw), 1)
152+ self.assertEqual(kw[0], {
153+ 'method': 'PATCH',
154+ 'path': '/path',
155+ 'query_params': {
156+ 'projection': 'full',
157+ 'userProject': user_project,
158+ },
159+ # Since changes does not include `baz`, we don't see it sent.
160+ 'data': {'bar': BAR},
161+ '_target_object': derived,
162+ })
95163 # Make sure changes get reset by patch().
96164 self.assertEqual(derived._changes, set())
97165
0 commit comments