Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests : User Tracker creation of user with minimal values #181

Closed
wants to merge 2 commits into from

Conversation

gkaihorodova
Copy link
Contributor

@gkaihorodova gkaihorodova commented Oct 24, 2016

Fix provide possibility to create user-add test with minimal values,
where uid is not specified, to provide better coverage
https://fedorahosted.org/freeipa/ticket/6126

@@ -76,6 +76,7 @@ def __init__(self, default_version=None):
self.api = api
self.default_version = default_version or API_VERSION
self._dn = None
self.attrs = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not create conflict with PR #148

@mirielka
Copy link
Contributor

The same minimal values apply for stageuser-add command, can you please modify the stageuser tracker as well? Also adding testcases for these changes would be nice.

@gkaihorodova
Copy link
Contributor Author

Yes, It's a valid point to add testcases for these changes . Will do. Thank you.

@mirielka
Copy link
Contributor

Having "None" default values for obligatory arguments does not seem to be a good idea. If the method was called with default values, it would fail. It would be best if obligatory arguments ("givenname" and "sn") were provided as positional arguments and voluntary "name" as keyword argument. Please note that such a change will cause failure of existing tests that use this tracker, therefore it's necessary to fix them as well - include this in separate commit of this PR. Also please don't forget to add testcases for which this PR was created originally - creating user without the "name" argument (both positive and negative testcases).

@apophys
Copy link
Contributor

apophys commented Nov 21, 2016

I think in this case we can go with keyword arguments only. Most of the uses of the tracker in the tests do it already. What I will need in the case of keyword arguments is an explicit check for some non-empty unicode string for the required attributes in the init method.

All of this applies to StageUserTracker in #210 as well

in the init method """

if not isinstance(givenname, (str, unicode)) and len(givenname) > 0:
raise ValueError("No name provided: %s" % givenname)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition does not fit the description, it should contain some more parentheses:
if not (isinstance(givenname, (str, unicode)) and len(givenname) > 0):
Also you can use 'basestring' instead of '(str, unicode)'.
Please change the error message so that it would unambiguously tell which value is incorrect (e.g. "No or invalid first name provided").

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • basestring doesn't work with Py3, please use six.string_types
  • I agree with @mirielka the if statement looks suspicious
  • please use and givenname instead of and len(givenname) > 0, empty string is automatically False
  • please use %r in error message to get more information about object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for review, will check it and do required changes.

if not isinstance(givenname, (str, unicode)) and len(givenname) > 0:
raise ValueError("No name provided: %s" % givenname)
if not isinstance(sn, (str, unicode)) and len(sn) > 0:
raise ValueError("No name provided: %s" % sn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@mirielka
Copy link
Contributor

mirielka commented Dec 6, 2016

Please check inline comments. Also suggestion for more test cases:

  • try to create a user whose automatically generated uid would be too long (>32 characters)
  • try to create a user whose automatically generated uid would contain invalid characters (other than letters, numbers, _, -, . and $).
    Also goes for PR Tests: Stage User Tracker implementation #210

@martbab
Copy link
Contributor

martbab commented Dec 12, 2016

Bump for review.

@mirielka mirielka added the ack Pull Request approved, can be merged label Dec 15, 2016
@MartinBasti
Copy link
Contributor

PR needs rebase

@gkaihorodova
Copy link
Contributor Author

will do, but before let me do small changes that was requested by @stlaz in #210, to use str.format() instead of " %r "

@MartinBasti MartinBasti removed the ack Pull Request approved, can be merged label Jan 5, 2017
@MartinBasti
Copy link
Contributor

Then, @stlaz must give final ACK

@stlaz
Copy link
Contributor

stlaz commented Jan 6, 2017

The changes introduce different behavior than in the previous change where repr() of the given strings would have been printed. To have repr() of the given string, use '{!r}' instead of '{}' in string format if that is what's desired. CondACK if it's not but please tell :) Same for #210

@gkaihorodova
Copy link
Contributor Author

Yes, the intention was to have repr() of the given string , so I'll use ''{!r} instead of '{}', and apply that change to #210 also. Thank you.

@stlaz stlaz added the ack Pull Request approved, can be merged label Jan 9, 2017
@stlaz
Copy link
Contributor

stlaz commented Jan 9, 2017

Thank you for the changes!

@gkaihorodova
Copy link
Contributor Author

Thank you for review!

@MartinBasti
Copy link
Contributor

This PR still needs rebase, it is not possible to apply patch without 3way merge, please pull the latest master and do rebase, we merge only patches that can be merged without 3-way merge

$ hub am https://github.com/freeipa/freeipa/pull/181 -3
Applying: Unaccessible variable self.attrs in Tracker
Using index info to reconstruct a base tree...
M	ipatests/test_xmlrpc/tracker/base.py
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
Applying: User Tracker: creation of user with minimal values
Using index info to reconstruct a base tree...
M	ipatests/test_xmlrpc/tracker/user_plugin.py
Falling back to patching base and 3-way merge...
Auto-merging ipatests/test_xmlrpc/tracker/user_plugin.py
Applying: User Tracker: Test to create user with minimal values

Fix provide possibility to create user-add test with minimal values,
where uid is not specified, to provide better coverage. Also provide
check for non-empty unicode string for attributes required in init method

https://fedorahosted.org/freeipa/ticket/6126
Test to create user with minimal values, where uid is not specified

https://fedorahosted.org/freeipa/ticket/6126
@gkaihorodova
Copy link
Contributor Author

@mbasti-rh done. hope now it's fine

@MartinBasti
Copy link
Contributor

@gkaihorodova you haven't pushed the changes to github repo

git push <github-remote> --force

@MartinBasti MartinBasti added the pushed Pull Request has already been pushed label Jan 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ack Pull Request approved, can be merged pushed Pull Request has already been pushed
Projects
None yet
6 participants