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

Proposed by Leo Arias
Status: Merged
Merged at revision: 44
Proposed branch: lp:~elopio/cloudspacesclient/download_file_with_contents
Merge into: lp:cloudspacesclient
Diff against target: 97 lines (+33/-16)
1 file modified
src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py (+33/-16)
To merge this branch: bzr merge lp:~elopio/cloudspacesclient/download_file_with_contents
Reviewer Review Type Date Requested Status
Richard Huddie (community) Approve
Review via email: mp+198111@code.launchpad.net

Commit message

Added a test to download file with content

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

Fixed pep8.

46. By Leo Arias

Refactored existing tests.

47. By Leo Arias

Fixed pep8.

Revision history for this message
Richard Huddie (rhuddie) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py'
2--- src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py 2013-12-06 16:29:10 +0000
3+++ src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py 2013-12-06 18:45:35 +0000
4@@ -242,8 +242,7 @@
5 test_file_name = 'new_test_file.txt'
6 test_file_mimetype = 'text/plain'
7
8- metadata = self.cloudspaces_api_client.make_file(
9- self.root_node_id, test_file_name)
10+ metadata = self._make_file(self.root_node_id, test_file_name)
11
12 validictory.validate(
13 metadata, schemas.GET_FILE_METADATA_RESPONSE_SCHEMA)
14@@ -266,30 +265,35 @@
15 # TODO check the user_id. --elopio - 2013-11-27
16 # TODO Check the volume_id field. --elopio - 2013-11-27
17
18+ def _make_file(self, folder_node_id, file_name, contents=''):
19+ metadata = self.cloudspaces_api_client.make_file(
20+ folder_node_id, file_name)
21+ file_node_id = metadata.get('node_id')
22+ if contents:
23+ metadata = self.cloudspaces_api_client.put_file(
24+ file_node_id, contents)
25+ return metadata
26+
27 def test_upload_file(self):
28 test_file_name = 'file_to_upload.txt'
29 test_file_mimetype = 'text/plain'
30
31- new_file_metadata = self.cloudspaces_api_client.make_file(
32- self.root_node_id, test_file_name)
33- file_node_id = new_file_metadata.get('node_id')
34-
35- file_upload_metadata = self.cloudspaces_api_client.put_file(
36- file_node_id, 'test contents')
37+ metadata = self._make_file(
38+ self.root_node_id, test_file_name, 'test contents')
39
40 validictory.validate(
41- file_upload_metadata, schemas.GET_FILE_METADATA_RESPONSE_SCHEMA)
42+ metadata, schemas.GET_FILE_METADATA_RESPONSE_SCHEMA)
43
44 root_path = self.test_server.get_root_path()
45 expected = dict(
46 filename=test_file_name, is_deleted=False, is_folder=False,
47 mimetype=test_file_mimetype, parent_node_id=self.root_node_id,
48 path=root_path, size=13)
49- self._assert_json_object_values(expected, file_upload_metadata)
50+ self._assert_json_object_values(expected, metadata)
51
52 # Assert that the file has just been modified.
53 self.assert_datetime_limits(
54- parser.parse(file_upload_metadata.get('server_modified')),
55+ parser.parse(metadata.get('server_modified')),
56 self.start_datetime, self._get_now_datetime())
57 # TODO update the spec because it says checksum instead of hash.
58 # --elopio - 2013-11-27
59@@ -301,14 +305,27 @@
60 # --elopio - 2013-12-06
61
62 def test_download_empty_file(self):
63- test_file_name = 'test_file_to_download.txt'
64- create_metadata = self.cloudspaces_api_client.make_file(
65- self.root_node_id, test_file_name)
66+ test_file_name = 'test_empty_file_to_download.txt'
67+ create_metadata = self._make_file(self.root_node_id, test_file_name)
68 file_node_id = create_metadata.get('node_id')
69
70 contents = list(self.cloudspaces_api_client.get_file(file_node_id))
71 self.assertEqual(contents, [])
72
73+ def test_download_file_with_content(self):
74+ test_file_name = 'test_file_to_download.txt'
75+ test_file_content = 'content of test file to download.'
76+ create_metadata = self._make_file(
77+ self.root_node_id, test_file_name, test_file_content)
78+ file_node_id = create_metadata.get('node_id')
79+
80+ content = self.cloudspaces_api_client.get_file(file_node_id)
81+ self._assert_file_content(content, test_file_content)
82+
83+ def _assert_file_content(self, response, expected):
84+ content = list(response)
85+ self.assertEqual(b''.join(content).decode(), expected)
86+
87 def test_delete_file(self):
88 test_file_name = 'test_file_to_delete.txt'
89 test_file_mimetype = 'text/plain'
90@@ -484,5 +501,5 @@
91 parser.parse(metadata.get('server_modified')), self.start_datetime,
92 self._get_now_datetime())
93 # get the latest version and compare with expected content
94- content = list(self.cloudspaces_api_client.get_file(file_node_id))
95- self.assertEqual(b''.join(content).decode(), content_v2)
96+ content = self.cloudspaces_api_client.get_file(file_node_id)
97+ self._assert_file_content(content, content_v2)

Subscribers

People subscribed via source and target branches

to all changes: