Merge lp:~elopio/cloudspacesclient/remove_extra_root_fields into lp:cloudspacesclient

Proposed by Leo Arias
Status: Merged
Merged at revision: 25
Proposed branch: lp:~elopio/cloudspacesclient/remove_extra_root_fields
Merge into: lp:cloudspacesclient
Diff against target: 211 lines (+77/-16)
4 files modified
src/cloudspacesclient/schemas.py (+22/-6)
src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py (+19/-2)
src/cloudspacesclient/tests/unit/test_schemas.py (+35/-5)
src/cloudspacesclient/ubuntuone.py (+1/-3)
To merge this branch: bzr merge lp:~elopio/cloudspacesclient/remove_extra_root_fields
Reviewer Review Type Date Requested Status
Łukasz Czyżykowski (community) Needs Fixing
Review via email: mp+196606@code.launchpad.net

Commit message

Check that the fields that shouldn't be present on the root metadata are not present. Check that the filename is present.

To post a comment you must log in.
26. By Leo Arias

client-modified was duplicated.

27. By Leo Arias

Remove the debug print.;

28. By Leo Arias

Rename

29. By Leo Arias

Fixed pep8.

Revision history for this message
Łukasz Czyżykowski (lukasz-czyzykowski) wrote :

Small change needed, now that we have filename field too: http://paste.ubuntu.com/6478476/

review: Needs Fixing
Revision history for this message
Leo Arias (elopio) wrote :

Updated. I'm going to merge, thank you!

30. By Leo Arias

Updated the u1 root path.

31. By Leo Arias

Check the filename.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/cloudspacesclient/schemas.py'
2--- src/cloudspacesclient/schemas.py 2013-11-22 09:22:15 +0000
3+++ src/cloudspacesclient/schemas.py 2013-11-26 16:41:32 +0000
4@@ -55,23 +55,39 @@
5 'client_modified': {
6 'type': 'string',
7 # TODO ask what should be the date format. --elopio - 2013-11-21
8- 'format': 'date-time'
9+ 'format': 'date-time',
10+ 'required': False
11 },
12 'content_path': {'type': 'string'},
13+ 'contents': {
14+ 'type': 'array',
15+ 'required': False
16+ },
17+ 'filename': {'type': 'string'},
18 'is_deleted': {'type': 'boolean'},
19 'is_folder': {'type': 'boolean'},
20 'is_root': {'type': 'boolean'},
21 'node_id': {'type': 'string'},
22- 'parent_node_id': {'type': ['string', 'null']},
23+ 'parent_node_id': {
24+ 'type': 'string',
25+ 'required': False
26+ },
27 'path': {'type': 'string'},
28 'resource_path': {'type': 'string'},
29 'server_modified': {
30 'type': 'string',
31 # TODO ask what should be the date format. --elopio - 2013-11-21
32- 'format': 'date-time'
33- },
34- 'user_id': {'type': 'string'},
35- 'version': {'type': 'integer'},
36+ 'format': 'date-time',
37+ 'required': False
38+ },
39+ 'user_id': {
40+ 'type': 'string',
41+ 'required': False
42+ },
43+ 'version': {
44+ 'type': 'integer',
45+ 'required': False
46+ },
47 'volume_id': {'type': 'string'},
48 'x_attributes': {
49 'type': 'object',
50
51=== modified file 'src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py'
52--- src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py 2013-11-25 14:53:15 +0000
53+++ src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py 2013-11-26 16:41:32 +0000
54@@ -17,6 +17,7 @@
55
56 """Conformance tests for Cloudspaces API."""
57
58+import os
59 import unittest
60 import urlparse
61 from datetime import datetime
62@@ -93,19 +94,24 @@
63
64 def test_get_root_metadata(self):
65 user_rep = self.cloudspaces_api_client.get_user_representation().json()
66- node_id = self._get_root_volume(user_rep.get('volumes')).get('node_id')
67+ root_volume = self._get_root_volume(user_rep.get('volumes'))
68+ node_id = root_volume.get('node_id')
69+ filename = os.path.split(root_volume.get('name'))[-1]
70 response = self.cloudspaces_api_client.get_metadata(node_id)
71 self.assertTrue(response.ok)
72 response_json = response.json()
73 validictory.validate(
74 response_json, schemas.GET_METADATA_RESPONSE_SCHEMA)
75+ self._assert_normal_folder_keys_not_in_root(response_json)
76 self._assert_content_path(node_id, response_json.get('content_path'))
77 # TODO Check that the contents are not present because the folder is
78 # empty. --elopio - 2013-11-25
79 self.assertTrue(response_json.get('is_folder'))
80 self.assertFalse(response_json.get('is_deleted'))
81 self.assertTrue(response_json.get('is_root'))
82- # TODO Check the filename field. --elopio - 2013-11-25
83+ # TODO The spec doesn't include it in the filename in the examples.
84+ # --elopio - 2013-11-25
85+ self.assertEqual(response_json.get('filename'), filename)
86 self.assertEqual(response_json.get('node_id'), node_id)
87 # TODO The spec says the path shouldn't be returned on the root
88 # metadata, but I think it's useful. Should we change the spec?
89@@ -113,12 +119,23 @@
90 self.assertEqual(
91 response_json.get('path'), self.test_server.get_root_path())
92 self._assert_resource_path(node_id, response_json.get('resource_path'))
93+ # TODO Check the volume_id field. --elopio - 2013-11-25
94
95 def _get_root_volume(self, volumes):
96 # FIXME The first volume returned is not necessarily the root.
97 # --elopio - 2013-11-23
98 return volumes[0]
99
100+ def _assert_normal_folder_keys_not_in_root(self, response_json):
101+ normal_folder_keys_not_in_root = [
102+ 'client_modified', 'parent_node_id', 'server_modified', 'version',
103+ 'user_id'
104+ ]
105+ for key in normal_folder_keys_not_in_root:
106+ self.assertFalse(
107+ key in response_json,
108+ "The root folder shouldn't include the {} key".format(key))
109+
110 def _assert_content_path(self, node_id, content_path):
111 path = urlparse.urlparse(self.service_root).path
112 self.assertEqual(
113
114=== modified file 'src/cloudspacesclient/tests/unit/test_schemas.py'
115--- src/cloudspacesclient/tests/unit/test_schemas.py 2013-11-22 09:22:15 +0000
116+++ src/cloudspacesclient/tests/unit/test_schemas.py 2013-11-26 16:41:32 +0000
117@@ -72,9 +72,11 @@
118 _VALID_METADATA = {
119 'client_modified': '2013-11-20T05:45:13Z',
120 'content_path': '/api/content/538757639',
121+ 'contents': [],
122 'is_deleted': False,
123 'is_folder': True,
124 'is_root': False,
125+ 'filename': 'Documents',
126 'node_id': '538757639',
127 'parent_node_id': '0',
128 'path': '/Documents',
129@@ -91,19 +93,23 @@
130 'valid_object': _VALID_METADATA,
131 'required_properties': {
132 'content_path': 'string',
133+ 'filename': 'string',
134 'is_deleted': 'boolean',
135 'is_folder': 'boolean',
136 'is_root': 'boolean',
137 'node_id': 'string',
138- 'parent_node_id': 'string null',
139 'path': 'string',
140 'resource_path': 'string',
141+ 'volume_id': 'string'
142+ },
143+ 'optional_properties': {
144+ 'contents': 'array',
145+ 'client_modified': 'string',
146+ 'parent_node_id': 'string',
147 'server_modified': 'string',
148+ 'version': 'integer',
149 'user_id': 'string',
150- 'version': 'integer',
151- 'volume_id': 'string'
152 },
153- 'optional_properties': {},
154 'allows_x_attributes': True,
155 'allows_extra_attributes': False
156 }
157@@ -160,6 +166,27 @@
158 self.assert_raises_validation_error(self.json, self.schema)
159
160
161+class ObjectOptionalPropertiesTestCase(
162+ testscenarios.TestWithScenarios, ResponseSchemaTestCase):
163+
164+ scenarios = [
165+ ('{0} without {1}'.format(object_.get('name'), property_), dict(
166+ schema=object_.get('schema'),
167+ valid_object=object_.get('valid_object'),
168+ property_=property_))
169+ for object_ in _OBJECTS
170+ for property_ in object_.get('optional_properties')
171+ ]
172+
173+ def setUp(self):
174+ super(ObjectOptionalPropertiesTestCase, self).setUp()
175+ self.json = copy.deepcopy(self.valid_object)
176+
177+ def test_valid_json_without_optional_property(self):
178+ del self.json[self.property_]
179+ validictory.validate(self.json, self.schema)
180+
181+
182 _TYPES = types = {
183 'string': 'test string',
184 'integer': 1,
185@@ -195,7 +222,10 @@
186 property_=property_,
187 value=wrong_value))
188 for object_ in _OBJECTS
189- for property_, types in object_.get('required_properties').items()
190+ for property_, types in (
191+ object_.get('required_properties').items() +
192+ object_.get('optional_properties').items()
193+ )
194 for wrong_type, wrong_value in _get_wrong_types(types).items()
195 ]
196
197
198=== modified file 'src/cloudspacesclient/ubuntuone.py'
199--- src/cloudspacesclient/ubuntuone.py 2013-11-24 05:49:47 +0000
200+++ src/cloudspacesclient/ubuntuone.py 2013-11-26 16:41:32 +0000
201@@ -130,9 +130,7 @@
202
203 def get_root_path(self):
204 """Return the path to the root folder."""
205- # TODO ask why on the root path it has a trailing / and on the volume
206- # names it doesn't. --elopio - 2013-11-23
207- return '~/Ubuntu One/'
208+ return '~'
209
210 def get_new_user_volume_names(self):
211 """Return a list with the names of the volumes of a new user."""

Subscribers

People subscribed via source and target branches

to all changes: