-
Notifications
You must be signed in to change notification settings - Fork 115
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
[6.3 Feature] Canned Role Org Admin API stubs automated #5592
[6.3 Feature] Canned Role Org Admin API stubs automated #5592
Conversation
This PR is dependent on SatelliteQE/nailgun#458 |
Codecov Report
@@ Coverage Diff @@
## master #5592 +/- ##
==========================================
- Coverage 61.3% 61.25% -0.06%
==========================================
Files 33 33
Lines 3672 3680 +8
==========================================
+ Hits 2251 2254 +3
- Misses 1421 1426 +5
Continue to review full report at Codecov.
|
The test Run result:
|
@SatelliteQE/robottelo-automation , Please help this PR to get merge having 20 tests automated of Canned Role feature. This will help us in release criteria as 20 automated tests are being added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending comments. Please check all the tests as they're basically applicable to all of them, not only the places i've pointed to.
tests/foreman/api/test_role.py
Outdated
@@ -100,7 +100,48 @@ def test_positive_update(self): | |||
class CannedRoleTestCases(APITestCase): | |||
"""Implements Canned Roles tests from API""" | |||
|
|||
@stubbed() | |||
def create_org_admin(self, name=None, orgs=None, locs=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: personally my first guess when reading create_org_admin
is about admin user, not admin role. Maybe it's better to rename to create_org_admin_role
to avoid confusion?
tests/foreman/api/test_role.py
Outdated
""" | ||
name = gen_string('alpha') if not name else name | ||
orgs = [] if not orgs else orgs | ||
locs = [] if not locs else locs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's shorter form with no extra vars:
'role': {
'name': name,
'organization_ids': orgs or [],
'location_ids': locs or [],
}
If orgs or locs is None
- []
will be selected instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must only be careful when the var is a number because 0 will be evaluated to False and some times you just want to filter None. But in case of a list, this is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/foreman/api/test_role.py
Outdated
cls.loc1 = entities.Location(name=gen_string('alpha')).create() | ||
# These two will be used as filter taxonomies | ||
cls.org2 = entities.Organization(name=gen_string('alpha')).create() | ||
cls.loc2 = entities.Location(name=gen_string('alpha')).create() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: no need to provide names for orgs and locs explicitly, nailgun will generate them
@@ -115,8 +156,16 @@ def test_positive_create_role_with_taxonomies(self): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls remove :caseautomation: notautomated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I have taken care of that
@@ -131,8 +180,16 @@ def test_positive_create_role_without_taxonomies(self): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:caseautomation: notautomated
yet again. Pls check all the tests
tests/foreman/api/test_role.py
Outdated
self.assertEqual(role1.id, filter1.role.id) | ||
# Creating new Taxonomies | ||
org3 = entities.Organization(name=gen_string('alpha')).create() | ||
loc3 = entities.Location(name=gen_string('alpha')).create() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: no need to provide names for orgs and locs explicitly, nailgun will generate them
tests/foreman/api/test_role.py
Outdated
query={'search': u'name="Organization admin"'}) | ||
org_admin = self.create_org_admin() | ||
default_filters = entities.Role( | ||
id=default_org_admin[0].id).read_json()['filters'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls avoid using .read_json()
where it's possible. If filters
field is not present in entities.Role()
- then pls add that field and use regular .read()
tests/foreman/api/test_role.py
Outdated
user1 = entities.User( | ||
login=user1_login, | ||
password=user1_pass, | ||
auth_source=1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line looks weird, and, basically there's no need in it since auth source with id=1 is automatically populated by nailgun, you may remove this line.
tests/foreman/api/test_role.py
Outdated
'organization-id': self.org1.id, | ||
'location-id': self.loc1.id | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking no errors were risen is not enough - please also ensure there're some results returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, Its the test of user be able to access Domains, no matter if there is present anything. IF user doesnt have access to that org and location, it will return access error as HTTP error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, lemme rephrase - what if no errors are returned but the resulting list is always empty? Pretty often happens to CLI tests - if user doesn't have enough permissions some list
command may return him empty list instead of failing. That's what i'm trying to avoid and cover.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will create some entities and see if those are returned.
tests/foreman/api/test_role.py
Outdated
} | ||
) | ||
self.assertEqual(org_admin['name'], name) | ||
return org_admin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result which user is receiving after creating an entity is usually entity read from the server (by EntityName(id=#).read()
command), not some helper's raw output. Please read created entity and return it instead to avoid confusion and different styles like self.assertNotEqual(org_admin['id'], role.id)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, but check and fix @abalakh comments
tests/foreman/api/test_role.py
Outdated
location=[] | ||
).create() | ||
self.assertEqual(role1.name, role_name) | ||
self.assertEqual(role1.organization, []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I've never noticed that before. But I think asserting against an empty list is more explicit. assertFalse will pass for [], 0, '', None and empty dict. So one would need to execute the code to really know what's the type of role1.organization. Besides that the name role1.organizagion is odd. If a list is expected shouldn't the attribute be called "organizations"?
7b70997
to
19796bb
Compare
Results after Fixing comments:
|
19796bb
to
8a03c5a
Compare
Please review and merge -> SatelliteQE/nailgun#459 Then merge this one. |
I will try to check that PR today, please do not merge it till tomorrow |
@oshtaier , Anyways 2 people have already reviewed it. You can feel free to opt out. |
nope, I have some expertise in that subject, so please wait |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pending questions
tests/foreman/api/test_role.py
Outdated
@@ -30,6 +30,7 @@ | |||
tier3, | |||
upgrade | |||
) | |||
from fauxfactory import gen_netmask, gen_ipaddr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put alphabetically
tests/foreman/api/test_role.py
Outdated
} | ||
} | ||
) | ||
self.assertEqual(org_admin['name'], name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we usually do not put assertion into helper functions. We verified that clone work as it should in specific test cases, so here it should work by default
tests/foreman/api/test_role.py
Outdated
} | ||
) | ||
self.assertEqual(org_admin['name'], name) | ||
org_admin_role = entities.Role(id=org_admin['id']).read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return entities.Role(id=org_admin['id']).read()
tests/foreman/api/test_role.py
Outdated
""" | ||
super(CannedRoleTestCases, cls).setUpClass() | ||
# These two will be used as role taxonomies | ||
cls.org1 = entities.Organization().create() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so name it in that way:
cls.role_org
cls.role_loc
and
cls.filter_org
cls.filter_loc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot divide them as filter org and role orgs, because in some test cases I used 'filter_orgs or org2' as role orgs as well. E.g to update the role orgs or so. So lets stick to this
tests/foreman/api/test_role.py
Outdated
:CaseImportance: Critical | ||
""" | ||
role_name = gen_string('alpha') | ||
role1 = entities.Role( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use simple role =
tests/foreman/api/test_role.py
Outdated
subnet1_name = gen_string('alpha') | ||
subnet1 = entities.Subnet( | ||
name=subnet1_name, | ||
mask=gen_netmask(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'mask': entity_fields.NetmaskField(required=True),
'name': entity_fields.StringField(
required=True,
str_type='alpha',
length=(6, 12),
unique=True
),
'network': entity_fields.IPAddressField(required=True),
so
entities.Subnet(
organization=[self.org1.id], location=[self.loc1.id]).create()
will be enough
tests/foreman/api/test_role.py
Outdated
organization=[self.org1.id], | ||
location=[self.loc1.id], | ||
).create() | ||
self.assertEqual(subnet1_name, subnet1.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant assertion
tests/foreman/api/test_role.py
Outdated
organization=[self.org1.id], | ||
location=[self.loc1.id] | ||
).create() | ||
self.assertEqual(domain1_name, domain1.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant assertion
tests/foreman/api/test_role.py
Outdated
location=[self.loc1.id], | ||
).create() | ||
self.assertEqual(subnet1_name, subnet1.name) | ||
domain1_name = gen_string('alpha') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant variable
|
||
:expectedresults: Org Admin should not have access to create taxonomies | ||
1. Org Admin should not have access to create organizations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ 1. Org Admin should not have access to create organizations
+ 2. Org Admin should have access to create locations
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because Org Admin is 'admin for org' but he can create the location. Thats the behavior feature provides.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
8a03c5a
to
741bb0d
Compare
@oshtaier , I finished working on your comments, please revisit. |
741bb0d
to
7f87dd2
Compare
@oshtaier , I am still waiting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to spend double time just to check what I was asking and look into fixed code and that is not easy for >500 lines. Please, next time address comments in separate commits
and it is not only me waited as requested changes |
@oshtaier , I have addressed all your comments and raised a new commit. Please revisit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, couple of suggestions. Still pending @oshtaier approval
tests/foreman/api/test_role.py
Outdated
) | ||
self.assertIn( | ||
domain.id, | ||
[dom.id for dom in entities.Domain(sc).search()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why do you perform search for the second time here? You could just store results from lines above and ensure there's desired entity in output.
- The steps and check below are completely the same, you can use
for
loop to avoid duplication. Smth like that:
for login, password in (
(userone_login, userone_password),
(usertwo_login, usertwo_password)):
with self.subTest(login):
sc = ServerConfig(
auth=(login, password),
url=ServerConfig.get().url,
verify=False
)
[...]
That comment was not addressed
You created role with exactly one organization and location, so please, please, write proper assertions |
).create() | ||
self.assertEqual(role.name, role_name) | ||
dom_perm = entities.Permission(resource_type='Domain').search() | ||
filtr = entities.Filter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason to use word filtr
instead filter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI ... filter is reserved keyword in python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
ACK pending 2 comments and comment from @abalakh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK pending test results after all changes
@oshtaier , @abalakh , The logs after all the changes,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
20 much needed Canned Role and Org Admin feature stubs are automated from API end.