Merge lp:~elopio/osqa-sst-helpers/data into lp:~online-services-qa/osqa-sst-helpers/canonical-identity-provider

Proposed by Leo Arias
Status: Merged
Merged at revision: 36
Proposed branch: lp:~elopio/osqa-sst-helpers/data
Merge into: lp:~online-services-qa/osqa-sst-helpers/canonical-identity-provider
Diff against target: 152 lines (+56/-69)
4 files modified
setup.py (+0/-1)
sso_sst_helpers/data.py (+56/-0)
sso_sst_helpers/data/factory.py (+0/-45)
sso_sst_helpers/data/user.py (+0/-23)
To merge this branch: bzr merge lp:~elopio/osqa-sst-helpers/data
Reviewer Review Type Date Requested Status
Vincent Ladeuil (community) Approve
Review via email: mp+129056@code.launchpad.net

Commit message

Refactored data to remove the factory.

Description of the change

Refactored the data to remove the factory.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

Vincent, why do you name the parameter klass?

Revision history for this message
Vincent Ladeuil (vila) wrote :

> Vincent, why do you name the parameter klass?

It's an idiom chosen because 'class' is a python reserved keyword so it can't be used. 'klass' is unambiguous and close enough.

Revision history for this message
Vincent Ladeuil (vila) wrote :
Download full text (4.1 KiB)

Some naming remarks:

50 + def make_for_test(klass, new_user=False):

Well, we know it's for test since the whole class is for tests.

53 + test_user = klass._make_random_test_user_from_configuration()

55 + test_user = klass._make_test_user_from_configuration()

Since all use cases are from configuration, I'd rather name this method 'make_from_configuration'.

58 + @classmethod
59 + def _make_random_test_user_from_configuration(klass):
60 + random_user_uuid = str(uuid.uuid1())
61 + full_name = 'Test user ' + random_user_uuid
62 + email_address = settings.EMAIL_ADDRESS_PATTERN % random_user_uuid
63 + password = settings.SSO_TEST_ACCOUNT_PASSWORD
64 + return klass(full_name, email_address, password)
65 +
66 + @classmethod
67 + def _make_test_user_from_configuration(klass):
68 + full_name = settings.SSO_TEST_ACCOUNT_FULL_NAME
69 + email_address = settings.SSO_TEST_ACCOUNT_EMAIL
70 + password = settings.SSO_TEST_ACCOUNT_PASSWORD
71 + return klass(full_name, email_address, password)

I think having these methods hurt readability and make for more duplication:

49 + @classmethod
58 + @classmethod
66 + @classmethod

63 + password = settings.SSO_TEST_ACCOUNT_PASSWORD
64 + return klass(full_name, email_address, password)

70 + password = settings.SSO_TEST_ACCOUNT_PASSWORD
71 + return klass(full_name, email_address, password)

So I'd rather go with these methods inlined in
'make_from_configuration'. This way the reader can focus on the still short
enough 'make_from_configuration'.

An additional trap in your implementation is that the two methods are not in
the order they are used (so, as a reader, if I don't pay attention enough I
won't notice and read the wrong method when reading 'make_for_test').

'_make_random_test_user_from_configuration' and
'_make_test_user_from_configuration' being this long (note that I can't cite
them both on a 80 chars long line), it's hard to spot the differing
'random', that's, for me, an example of why names too long hurt readability
instead of helping it. Rmeebmer that popele are good at recgniozing words
based on the first and last letetr even if the letters inside the words are
suhffled (you managed to read this sentence without too much trouble aren't
you ? ;).

I.e.:

....

wth, I cannot branch lp:osqa-sst-helpers ? What is this project about ? 8-/
(that was rhetorical, the development focus needs to be set in lp).

anyway:

=== modified file 'sso_sst_helpers/data.py'
--- sso_sst_helpers/data.py 2012-10-10 21:07:11 +0000
+++ sso_sst_helpers/data.py 2012-10-11 07:47:48 +0000
@@ -30,25 +30,13 @@
         return '%s(%r)' % (self.__class__, self.__dict__)

     @classmethod
- def make_for_test(klass, new_user=False):
+ def make_from_configuration(klass, new_user=False):
         test_user = None
         if new_user:
- test_user = klass._make_random_test_user_from_configuration()
+ full_name = settings.SSO_TEST_ACCOUNT_FULL_NAME
+ email_address = settings.SSO_TEST_ACCOUNT_EMAIL
         else:
- test_user = klass._make_test_user_from_configuration()
- return test_user
-
- @classmethod
- def _make_random_test_user_from_configuration(klass):
- random_u...

Read more...

review: Needs Fixing
lp:~elopio/osqa-sst-helpers/data updated
39. By Leo Arias

Added the docstring.
Renamed the factory function to make_from_configuration.
Refactored following Vincent's suggetions.

40. By Leo Arias

Fixed the comments identation.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Excellent !

There are some conventions for formatting docstrings but that can wait (and I'll have to search the reference anyway ;)

review: Approve
Revision history for this message
Leo Arias (elopio) wrote :
lp:~elopio/osqa-sst-helpers/data updated
41. By Leo Arias

Merged with trunk.

42. By Leo Arias

Fixed style error.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'setup.py'
2--- setup.py 2012-09-18 01:06:17 +0000
3+++ setup.py 2012-10-16 16:49:18 +0000
4@@ -28,7 +28,6 @@
5 PACKAGES = [
6 'sso_sst_helpers',
7 'sso_sst_helpers.actions',
8- 'sso_sst_helpers.data',
9 'sso_sst_helpers.utils'
10 ]
11
12
13=== removed directory 'sso_sst_helpers/data'
14=== added file 'sso_sst_helpers/data.py'
15--- sso_sst_helpers/data.py 1970-01-01 00:00:00 +0000
16+++ sso_sst_helpers/data.py 2012-10-16 16:49:18 +0000
17@@ -0,0 +1,56 @@
18+# -*- coding: utf-8 -*-
19+
20+# Copyright 2012 Canonical Ltd.
21+#
22+# This program is free software: you can redistribute it and/or modify it
23+# under the terms of the GNU Lesser General Public License version 3, as
24+# published by the Free Software Foundation.
25+#
26+# This program is distributed in the hope that it will be useful, but
27+# WITHOUT ANY WARRANTY; without even the implied warranties of
28+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
29+# PURPOSE. See the GNU Lesser General Public License for more details.
30+#
31+# You should have received a copy of the GNU General Public License along
32+# with this program. If not, see <http://www.gnu.org/licenses/>.
33+
34+import uuid
35+
36+from django.conf import settings
37+
38+
39+class User(object):
40+
41+ def __init__(self, full_name, email, password):
42+ self.full_name = full_name
43+ self.email = email
44+ self.password = password
45+
46+ def __repr__(self):
47+ return '%s(%r)' % (self.__class__, self.__dict__)
48+
49+ @classmethod
50+ def make_from_configuration(cls, new_user=False):
51+ """Return a user taking its credentials from the configuration files.
52+
53+ Keyword arguments:
54+ new_user -- If True, the full name and email of the user will have a
55+ UUID to make them practically unique. In this case, the email will
56+ be formed with the value of the EMAIL_ADDRESS_PATTERN
57+ configuration variable. If False, the full name and email will be
58+ the values of the SSO_TEST_ACCOUNT_FULL_NAME and
59+ SSO_TEST_ACCOUNT_EMAIL configuration variables, respectively. In
60+ both cases, the password will be the value of the
61+ SSO_TEST_ACCOUNT_PASSWORD configuration variable.
62+ Default is False.
63+
64+ """
65+ if new_user:
66+ random_user_uuid = str(uuid.uuid1())
67+ full_name = 'Test user ' + random_user_uuid
68+ email = settings.EMAIL_ADDRESS_PATTERN % random_user_uuid
69+ else:
70+ full_name = settings.SSO_TEST_ACCOUNT_FULL_NAME
71+ email = settings.SSO_TEST_ACCOUNT_EMAIL
72+ password = settings.SSO_TEST_ACCOUNT_PASSWORD
73+ return cls(full_name, email, password)
74
75=== removed file 'sso_sst_helpers/data/__init__.py'
76=== removed file 'sso_sst_helpers/data/factory.py'
77--- sso_sst_helpers/data/factory.py 2012-10-15 20:38:20 +0000
78+++ sso_sst_helpers/data/factory.py 1970-01-01 00:00:00 +0000
79@@ -1,45 +0,0 @@
80-# -*- coding: utf-8 -*-
81-
82-# Copyright 2012 Canonical Ltd.
83-#
84-# This program is free software: you can redistribute it and/or modify it
85-# under the terms of the GNU Lesser General Public License version 3, as
86-# published by the Free Software Foundation.
87-#
88-# This program is distributed in the hope that it will be useful, but
89-# WITHOUT ANY WARRANTY; without even the implied warranties of
90-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
91-# PURPOSE. See the GNU Lesser General Public License for more details.
92-#
93-# You should have received a copy of the GNU General Public License along
94-# with this program. If not, see <http://www.gnu.org/licenses/>.
95-
96-import uuid
97-
98-from django.conf import settings
99-
100-from sso_sst_helpers.data.user import User
101-
102-
103-def make_test_user(new_user=False):
104- test_user = None
105- if new_user:
106- test_user = _make_random_test_user_from_configuration()
107- else:
108- test_user = _make_test_user_from_configuration()
109- return test_user
110-
111-
112-def _make_random_test_user_from_configuration():
113- random_user_uuid = str(uuid.uuid1())
114- full_name = 'Test user ' + random_user_uuid
115- email_address = settings.EMAIL_ADDRESS_PATTERN % random_user_uuid
116- password = settings.SSO_TEST_ACCOUNT_PASSWORD
117- return User(full_name, email_address, password)
118-
119-
120-def _make_test_user_from_configuration():
121- full_name = settings.SSO_TEST_ACCOUNT_FULL_NAME
122- email_address = settings.SSO_TEST_ACCOUNT_EMAIL
123- password = settings.SSO_TEST_ACCOUNT_PASSWORD
124- return User(full_name, email_address, password)
125
126=== removed file 'sso_sst_helpers/data/user.py'
127--- sso_sst_helpers/data/user.py 2012-10-15 20:38:20 +0000
128+++ sso_sst_helpers/data/user.py 1970-01-01 00:00:00 +0000
129@@ -1,23 +0,0 @@
130-# -*- coding: utf-8 -*-
131-
132-# Copyright 2012 Canonical Ltd.
133-#
134-# This program is free software: you can redistribute it and/or modify it
135-# under the terms of the GNU Lesser General Public License version 3, as
136-# published by the Free Software Foundation.
137-#
138-# This program is distributed in the hope that it will be useful, but
139-# WITHOUT ANY WARRANTY; without even the implied warranties of
140-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
141-# PURPOSE. See the GNU Lesser General Public License for more details.
142-#
143-# You should have received a copy of the GNU General Public License along
144-# with this program. If not, see <http://www.gnu.org/licenses/>.
145-
146-
147-class User:
148-
149- def __init__(self, full_name, email, password):
150- self.full_name = full_name
151- self.email = email
152- self.password = password

Subscribers

People subscribed via source and target branches

to all changes: