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
=== modified file 'setup.py'
--- setup.py 2012-09-18 01:06:17 +0000
+++ setup.py 2012-10-16 16:49:18 +0000
@@ -28,7 +28,6 @@
28PACKAGES = [28PACKAGES = [
29 'sso_sst_helpers', 29 'sso_sst_helpers',
30 'sso_sst_helpers.actions', 30 'sso_sst_helpers.actions',
31 'sso_sst_helpers.data',
32 'sso_sst_helpers.utils'31 'sso_sst_helpers.utils'
33]32]
3433
3534
=== removed directory 'sso_sst_helpers/data'
=== added file 'sso_sst_helpers/data.py'
--- sso_sst_helpers/data.py 1970-01-01 00:00:00 +0000
+++ sso_sst_helpers/data.py 2012-10-16 16:49:18 +0000
@@ -0,0 +1,56 @@
1# -*- coding: utf-8 -*-
2
3# Copyright 2012 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU Lesser General Public License version 3, as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranties of
11# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12# PURPOSE. See the GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import uuid
18
19from django.conf import settings
20
21
22class User(object):
23
24 def __init__(self, full_name, email, password):
25 self.full_name = full_name
26 self.email = email
27 self.password = password
28
29 def __repr__(self):
30 return '%s(%r)' % (self.__class__, self.__dict__)
31
32 @classmethod
33 def make_from_configuration(cls, new_user=False):
34 """Return a user taking its credentials from the configuration files.
35
36 Keyword arguments:
37 new_user -- If True, the full name and email of the user will have a
38 UUID to make them practically unique. In this case, the email will
39 be formed with the value of the EMAIL_ADDRESS_PATTERN
40 configuration variable. If False, the full name and email will be
41 the values of the SSO_TEST_ACCOUNT_FULL_NAME and
42 SSO_TEST_ACCOUNT_EMAIL configuration variables, respectively. In
43 both cases, the password will be the value of the
44 SSO_TEST_ACCOUNT_PASSWORD configuration variable.
45 Default is False.
46
47 """
48 if new_user:
49 random_user_uuid = str(uuid.uuid1())
50 full_name = 'Test user ' + random_user_uuid
51 email = settings.EMAIL_ADDRESS_PATTERN % random_user_uuid
52 else:
53 full_name = settings.SSO_TEST_ACCOUNT_FULL_NAME
54 email = settings.SSO_TEST_ACCOUNT_EMAIL
55 password = settings.SSO_TEST_ACCOUNT_PASSWORD
56 return cls(full_name, email, password)
057
=== removed file 'sso_sst_helpers/data/__init__.py'
=== removed file 'sso_sst_helpers/data/factory.py'
--- sso_sst_helpers/data/factory.py 2012-10-15 20:38:20 +0000
+++ sso_sst_helpers/data/factory.py 1970-01-01 00:00:00 +0000
@@ -1,45 +0,0 @@
1# -*- coding: utf-8 -*-
2
3# Copyright 2012 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU Lesser General Public License version 3, as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranties of
11# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12# PURPOSE. See the GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import uuid
18
19from django.conf import settings
20
21from sso_sst_helpers.data.user import User
22
23
24def make_test_user(new_user=False):
25 test_user = None
26 if new_user:
27 test_user = _make_random_test_user_from_configuration()
28 else:
29 test_user = _make_test_user_from_configuration()
30 return test_user
31
32
33def _make_random_test_user_from_configuration():
34 random_user_uuid = str(uuid.uuid1())
35 full_name = 'Test user ' + random_user_uuid
36 email_address = settings.EMAIL_ADDRESS_PATTERN % random_user_uuid
37 password = settings.SSO_TEST_ACCOUNT_PASSWORD
38 return User(full_name, email_address, password)
39
40
41def _make_test_user_from_configuration():
42 full_name = settings.SSO_TEST_ACCOUNT_FULL_NAME
43 email_address = settings.SSO_TEST_ACCOUNT_EMAIL
44 password = settings.SSO_TEST_ACCOUNT_PASSWORD
45 return User(full_name, email_address, password)
460
=== removed file 'sso_sst_helpers/data/user.py'
--- sso_sst_helpers/data/user.py 2012-10-15 20:38:20 +0000
+++ sso_sst_helpers/data/user.py 1970-01-01 00:00:00 +0000
@@ -1,23 +0,0 @@
1# -*- coding: utf-8 -*-
2
3# Copyright 2012 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU Lesser General Public License version 3, as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranties of
11# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12# PURPOSE. See the GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18class User:
19
20 def __init__(self, full_name, email, password):
21 self.full_name = full_name
22 self.email = email
23 self.password = password

Subscribers

People subscribed via source and target branches

to all changes: