Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

[RFR] Test provision approval deny #10019

Merged
merged 1 commit into from
Mar 27, 2020
Merged

[RFR] Test provision approval deny #10019

merged 1 commit into from
Mar 27, 2020

Conversation

jarovo
Copy link
Contributor

@jarovo jarovo commented Mar 25, 2020

This adds checking denying of provisioning request. The code was not written in compact way so I did some generalization of the code for checking emails. It is now not waiting for some count of emails but just waits until all expected subjects are present.

For checking different approval actions I used something like strategy design pattern.

Looking at the PR lines stats... removing 98 lines and adding 67 while adding tests ... Is this not awesome?

{{pytest: cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval --use-provider complete --long-running -v}}

local results

There are networking/container issues with prt. thus I had to run the 9d06718 locally. All passed:

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.5-edit] 
Trying to set up provider vsphere65-nested

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.5-edit] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.5-approve] 
Trying to set up provider vsphere65-nested

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.5-approve] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.5-deny] 
Trying to set up provider vsphere65-nested

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.5-deny] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.7-edit] 
Removing extra providers: vsphere65-nested
Trying to set up provider vsphere67-nested

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.7-edit] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.7-approve] 
Trying to set up provider vsphere67-nested

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.7-approve] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.7-deny] 
Trying to set up provider vsphere67-nested

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[virtualcenter-6.7-deny] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.2-edit] 
Removing extra providers: vsphere67-nested
Trying to set up provider rhv42

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.2-edit] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.2-approve] 
Trying to set up provider rhv42

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.2-approve] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.2-deny] 
Trying to set up provider rhv42

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.2-deny] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.3-edit] 
Removing extra providers: rhv42
Trying to set up provider rhv43

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.3-edit] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.3-approve] 
Trying to set up provider rhv43

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.3-approve] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.3-deny] 
Trying to set up provider rhv43

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[rhevm-4.3-deny] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[openstack-13-edit] 
Removing extra providers: rhv43
Trying to set up provider env-rhos13

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[openstack-13-edit] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[openstack-13-approve] 
Trying to set up provider env-rhos13

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[openstack-13-approve] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[openstack-13-deny] 
Trying to set up provider env-rhos13

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[openstack-13-deny] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[ec2-edit] 
Removing extra providers: env-rhos13
Trying to set up provider ec2west

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[ec2-edit] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[ec2-approve] 
Trying to set up provider ec2west

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[ec2-approve] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[ec2-deny] 
Trying to set up provider ec2west

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[ec2-deny] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[azure-common-edit] 
Removing extra providers: ec2west
Trying to set up provider azure

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[azure-common-edit] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[azure-common-approve] 
Trying to set up provider azure

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[azure-common-approve] PASSEDFinishing ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[azure-common-deny] 
Trying to set up provider azure

Threads started ...

cfme/tests/cloud_infra_common/test_provisioning.py::test_provision_approval[azure-common-deny] PASSEDFinishing ...

@dajoRH dajoRH added the lint-ok label Mar 25, 2020
@jarovo jarovo changed the title Test provision approval deny [RFR] Test provision approval deny Mar 25, 2020
@john-dupuy john-dupuy added the test-cleanup Test removal, collection changes, re-organization label Mar 27, 2020
Copy link
Contributor

@john-dupuy john-dupuy left a comment

Choose a reason for hiding this comment

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

Nice PR @JaryN, just a few comments!

"""
pass
def check_subjects():
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional since this is an internal method

Suggested change
def check_subjects():
def _check_subjects():

Copy link
Contributor Author

@jarovo jarovo Mar 27, 2020

Choose a reason for hiding this comment

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

yeah it is internal -- not really accessible from outside and I think that makes clear it is "private-ish" in Java terms. So I am not sure what the underscore helps with, but I have no problems to change it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is just preference for me, which is why I made it optional. Though in python there are no truly private methods, I still think it is good practice to mark internal/private methods with the pre-pended _

Comment on lines +162 to +167
for subject in expected_subjects:
if not any(subject in r_sub for r_sub in subjects):
logger.info('Subject {subjects} not found in the received emails yet.')
return False
logger.info('All expected subjects found in the received email list.')
return True
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: Could you do?

Suggested change
for subject in expected_subjects:
if not any(subject in r_sub for r_sub in subjects):
logger.info('Subject {subjects} not found in the received emails yet.')
return False
logger.info('All expected subjects found in the received email list.')
return True
return subjects in expected_subjects

Copy link
Contributor

Choose a reason for hiding this comment

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

From what you have now, it looks like subjects and expected_subjects are not exactly of the same structure, is there someway you could enforce that to simplify the logic of this method?

Copy link
Contributor Author

@jarovo jarovo Mar 27, 2020

Choose a reason for hiding this comment

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

From what you have now, it looks like subjects and expected_subjects are not exactly of the same structure, is there someway you could enforce that to simplify the logic of this method?

I was thinking about the same... the code looks strange as it is and I though why it is not written the way as you suggest. I am quite sure the reason is that we need to check the subject to be just a substring of the strings in expected_subjects. Note "foo" in "barfoobar" is True.

Perhaps it is something worthy to check and comment on it in the code or change the code for this to be more clear.

Note I also discovered that the smtp_test "mock" provides a subject_like argument, but I figured out I cannot use it and keep the behaviour same enough for my liking.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, I think a comment explaining this will suffice for now. Then we can evaluate whether to cleanup this logic a bit later.

provision_request = appliance.collections.requests.instantiate(cells=cells)
if edit:

def action_edit():
Copy link
Contributor

Choose a reason for hiding this comment

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

To keep the test structure more transparent, I think it'd be helpful if these action_ function were defined out of the test case itself. What do you think?

Copy link
Contributor Author

@jarovo jarovo Mar 27, 2020

Choose a reason for hiding this comment

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

I am not sure what is better but I have not much against putting them out except that I will surely need to pass more arguments to them.

I kept those actions_* inside as I didn't think they are reusable anywhere else.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I'm fine with keeping them in the test function, I'd consider my comment optional

Copy link
Member

Choose a reason for hiding this comment

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

Agreed @john-dupuy, but I think this is optional to this PR.

@mshriver mshriver self-assigned this Mar 27, 2020
@mshriver mshriver merged commit 569d94e into ManageIQ:master Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lint-ok test-cleanup Test removal, collection changes, re-organization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants