~elopio/+junk/cloudspaces

« back to all changes in this revision

Viewing changes to src/cloudspacesclient/ubuntuone.py

  • Committer: Leo Arias
  • Date: 2013-11-17 10:26:23 UTC
  • Revision ID: leo.arias@canonical.com-20131117102623-hyt7nd12tdgazdoa
Added more tests to the u1 server adapter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
    @classmethod
30
30
    def make_unique(cls, unique_id=None):
 
31
        """Return a unique user.
 
32
 
 
33
        :parameter unique_id: If a unique_id is passed, it will be used to
 
34
            uniquely identify the data of the new user. If None is passed as
 
35
            unique_id, then a uuid will be used. Default is None.
 
36
 
 
37
        """
31
38
        if unique_id is None:
32
39
            unique_id = str(uuid.uuid1())
33
40
        full_name = 'Test user {}'.format(unique_id)
38
45
 
39
46
class UbuntuOneServer(object):
40
47
 
41
 
    def create_test_user(self):
 
48
    def create_test_user(self, unique_id=None):
42
49
        """Create an Ubuntu One user.
43
50
 
44
51
        :return: An object with the user information.
45
52
 
46
53
        """
47
 
        user = User.make_unique()
 
54
        user = User.make_unique(unique_id)
48
55
        self._register_test_user(user)
49
56
        self._create_user_in_u1(user)
50
57
        return user
62
69
            urlparse.urljoin(SSO_SERVER_URL, 'api/v2'))
63
70
 
64
71
    def _create_user_in_u1(self, user):
65
 
        response = self._get_u1_api_client(user).get_account_info()
 
72
        response = self._get_u1_api_client(user).create_user()
66
73
        if response.status_code != 200:
67
74
            raise UbuntuOneServerException(
68
75
                'Failed to create U1 user. '
103
110
        self.service_root_url = service_root_url
104
111
        self.auth = auth
105
112
 
 
113
    def create_user(self):
 
114
        """Create the authenticated user in Ubuntu One, if it doesn't exist."""
 
115
        # Any call to the API will create the user if it doesn't exist.
 
116
        return self.get_account_info()
 
117
 
106
118
    def get_account_info(self):
 
119
        """Get the account information of the authenticated user."""
107
120
        url = urlparse.urljoin(self.service_root_url, 'account/')
108
121
        return requests.get(
109
122
            url, auth=self.auth, headers=self._get_headers())