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

Proposed by Leo Arias
Status: Merged
Merged at revision: 32
Proposed branch: lp:~elopio/cloudspacesclient/dev_server
Merge into: lp:cloudspacesclient
Diff against target: 143 lines (+82/-4)
4 files modified
src/cloudspacesclient/config/cloudspaces.conf (+1/-0)
src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py (+11/-4)
src/cloudspacesclient/tests/unit/test_ubuntuone.py (+55/-0)
src/cloudspacesclient/ubuntuone.py (+15/-0)
To merge this branch: bzr merge lp:~elopio/cloudspacesclient/dev_server
Reviewer Review Type Date Requested Status
Richard Huddie (community) Approve
Review via email: mp+196183@code.launchpad.net

Commit message

Get the server adapter class from the config file.
Added an adapter for UbuntuOne with an existing user instead of creating a new one.

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

Added tests for the ubuntuone with existent user adapter.

29. By Leo Arias

Added the missing test.

Revision history for this message
Richard Huddie (rhuddie) wrote :

Looks good.

review: Approve
30. By Leo Arias

Revert change on config.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/cloudspacesclient/config/cloudspaces.conf'
2--- src/cloudspacesclient/config/cloudspaces.conf 2013-12-04 14:35:17 +0000
3+++ src/cloudspacesclient/config/cloudspaces.conf 2013-12-04 14:54:10 +0000
4@@ -1,6 +1,7 @@
5 [cloudspaces]
6 cloudspaces_server_url = http://u1.local:8003
7 #cloudspaces_server_url = http://u1-precise.local:8003
8+cloudspaces_server_adapter = cloudspacesclient.ubuntuone.UbuntuOneServer
9
10 [ubuntuone]
11 sso_server_url = http://sso.local:8001
12
13=== modified file 'src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py'
14--- src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py 2013-12-04 14:34:33 +0000
15+++ src/cloudspacesclient/tests/conformance/test_cloudspaces_api.py 2013-12-04 14:54:10 +0000
16@@ -17,6 +17,7 @@
17
18 """Conformance tests for Cloudspaces API."""
19
20+import importlib
21 import os
22 import unittest
23 import urllib.parse
24@@ -27,7 +28,15 @@
25 import cloudspacer.errors
26 from dateutil import parser, tz
27
28-from cloudspacesclient import config, schemas, ubuntuone
29+from cloudspacesclient import config, schemas
30+
31+
32+def get_test_server_adapter():
33+ test_server_adapter = config.get(
34+ 'cloudspaces', 'cloudspaces_server_adapter').split('.')
35+ test_server_module_name = '.'.join(test_server_adapter[:-1])
36+ test_server_module = importlib.import_module(test_server_module_name)
37+ return getattr(test_server_module, test_server_adapter[-1])()
38
39
40 class CloudspacesAPITestCase(unittest.TestCase):
41@@ -38,9 +47,7 @@
42 def setUp(self):
43 super(CloudspacesAPITestCase, self).setUp()
44 self.start_datetime = self._get_now_datetime()
45- # TODO the server class should be defined in a config file, to make
46- # it easy to test different Cloudspaces servers.
47- self.test_server = ubuntuone.UbuntuOneServer()
48+ self.test_server = get_test_server_adapter()
49 self.test_user = self.test_server.create_test_user()
50 self.addCleanup(self.test_server.delete_test_user, self.test_user)
51
52
53=== modified file 'src/cloudspacesclient/tests/unit/test_ubuntuone.py'
54--- src/cloudspacesclient/tests/unit/test_ubuntuone.py 2013-11-29 08:43:04 +0000
55+++ src/cloudspacesclient/tests/unit/test_ubuntuone.py 2013-12-04 14:54:10 +0000
56@@ -175,6 +175,61 @@
57 str(e.exception), 'Failed to create U1 user. Test error')
58
59
60+class UbuntuOneServerWithExistingUserTestCase(unittest.TestCase):
61+
62+ def setUp(self):
63+ super(UbuntuOneServerWithExistingUserTestCase, self).setUp()
64+ self.server = ubuntuone.UbuntuOneServerWithExistingUser()
65+
66+ def test_create_test_user_should_not_create_unique_user(self):
67+ with mock.patch.object(
68+ ubuntuone.User, 'make_unique') as mock_make_user:
69+ self.server.create_test_user()
70+
71+ self.assertFalse(mock_make_user.called)
72+
73+ def test_create_test_user_should_not_register_user_in_sso(self):
74+ with mock.patch.object(
75+ ubuntuone.UbuntuOneServerWithExistingUser,
76+ '_register_test_user') as mock_register:
77+ self.server.create_test_user()
78+
79+ self.assertFalse(mock_register.called)
80+
81+ def test_create_test_user_should_not_create_user_in_u1(self):
82+ with mock.patch.object(
83+ ubuntuone.UbuntuOneServerWithExistingUser,
84+ '_create_user_in_u1') as mock_create_in_u1:
85+ self.server.create_test_user()
86+
87+ self.assertFalse(mock_create_in_u1.called)
88+
89+ def test_get_auth_session_should_return_values_from_config(self):
90+ def config_side_effect(section, option):
91+ if section == 'ubuntuone':
92+ test_options = {
93+ 'consumer_key': 'test consumer key',
94+ 'consumer_secret': 'test consumer secret',
95+ 'token_key': 'test token key',
96+ 'token_secret': 'test token secret'
97+ }
98+ return test_options.get(option)
99+
100+ with mock.patch('cloudspacesclient.config.get') as config_mock:
101+ config_mock.side_effect = config_side_effect
102+ session = self.server.get_auth_session('dummy')
103+
104+ self.assertIsInstance(session, requests_oauthlib.OAuth1Session)
105+ self.assertEqual(
106+ session._client.client.client_key, 'test consumer key')
107+ self.assertEqual(
108+ session._client.client.client_secret, 'test consumer secret')
109+ self.assertEqual(
110+ session._client.client.resource_owner_key, 'test token key')
111+ self.assertEqual(
112+ session._client.client.resource_owner_secret, 'test token secret')
113+
114+
115 class UbuntuOneAPITestCase(unittest.TestCase):
116
117 def setUp(self):
118
119=== modified file 'src/cloudspacesclient/ubuntuone.py'
120--- src/cloudspacesclient/ubuntuone.py 2013-11-29 08:43:57 +0000
121+++ src/cloudspacesclient/ubuntuone.py 2013-12-04 14:54:10 +0000
122@@ -136,6 +136,21 @@
123 return ['~/Ubuntu One']
124
125
126+class UbuntuOneServerWithExistingUser(UbuntuOneServer):
127+
128+ def create_test_user(self, unique_id=None):
129+ # Ignore this, we will use an existing user.
130+ pass
131+
132+ def get_auth_session(self, user):
133+ """Return the auth session of the existing user."""
134+ return requests_oauthlib.OAuth1Session(
135+ config.get('ubuntuone', 'consumer_key'),
136+ config.get('ubuntuone', 'consumer_secret'),
137+ config.get('ubuntuone', 'token_key'),
138+ config.get('ubuntuone', 'token_secret'))
139+
140+
141 class UbuntuOneAPIClient(object):
142
143 content_type = JSON_MIME_TYPE

Subscribers

People subscribed via source and target branches

to all changes: