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

[1LP][RFR] Rewrite of test_infrastructure_hosts_crud for only single hosts #9761

Merged
merged 14 commits into from
May 6, 2020

Conversation

prichard77
Copy link
Contributor

@prichard77 prichard77 commented Dec 11, 2019

Purpose or Intent

  • Updating tests for infra hosts CRUD to make coverage more intuitive and manageable.

PRT Run

{{ pytest: --use-provider complete --long-running cfme/tests/infrastructure/test_host.py::test_infrastructure_hosts_crud }}

@prichard77
Copy link
Contributor Author

prichard77 commented Dec 12, 2019

I can add a wait and then check that a host is deleted. This will add a bit of time to the test.

@dajoRH dajoRH added lint-ok and removed needs-lint labels Dec 12, 2019
@prichard77
Copy link
Contributor Author

I moved the original crud test to PR#9762 where I will be adding additional coverage.

@prichard77 prichard77 changed the title [WIP] Rewrite of test_infrastructure_hosts_crud for only single hosts [WIPTEST] Rewrite of test_infrastructure_hosts_crud for only single hosts Dec 12, 2019
@dajoRH dajoRH added WIP-testing and removed WIP labels Dec 12, 2019
@prichard77 prichard77 changed the title [WIPTEST] Rewrite of test_infrastructure_hosts_crud for only single hosts [RFR] Rewrite of test_infrastructure_hosts_crud for only single hosts Dec 12, 2019
@mshriver mshriver self-assigned this Dec 13, 2019
pytest.fail("Abandon changes alert displayed, but no changes made.")
# TODO add additional crud functionality.
edit_view = provider.create_view(HostEditView)
stamp = datetime.now()
Copy link
Member

Choose a reason for hiding this comment

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

I'd use fauxfactory to get a random alphanumeric here, not rely on datetime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I updated to use fauxfactory. I am just curious as to why this is preferred to datetime. Is it just because datetime will take more processing (CPU cycles)?

edit_view.custom_ident.fill(edit_string)
edit_view.save_button.click()
# now verify the change is displayed.
host_view = provider.create_view(HostDetailsView)
Copy link
Member

Choose a reason for hiding this comment

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

I would assert that this view is displayed, if its the expected redirect after clicking save. You can pass wait=5 to create_view to trigger it calling wait_displayed() on the view class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated as suggested.

Copy link
Member

@mshriver mshriver left a comment

Choose a reason for hiding this comment

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

see comment

custom_id = host_view.entities.summary("Properties").get_text_of("Custom Identifier")
assert custom_id == edit_string
# edit host from host detail view
hosts_view.toolbar.configuration.item_select('Edit this item',
Copy link
Member

Choose a reason for hiding this comment

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

Please insert a line of whitespace before these comments so they're more visible blocks of the test function.

I would also explicitly navigate here, not rely on just creating the view from the prior assumption of redirection.

Tough call here on reducing the code duplication involved in filling/saving the form when there are only 2-3 things different between collection modify and details modify. Some test functions parametrize on this (from_details, from_collection)

One nuance here - the Host entity class includes Updateable - and the changes that you're making to the entity via these direct calls to navigation destinations and direct form filling are not being included in the actual entity.

This can cause issues with subsequent navigation - as the navigation steps may rely on the fields that have been modified in CFME.

Consider Host.exists uses a navigate to 'Details', and the step for navigating to details picks the entity in the table based on its custom_ident field.

If you modify that field in CFME, but still have the original instance of the host entity, this call will fail as CFME now has a different value than the entity in python.

In order to avoid this, updateable provides a context manager that updates the entity instance.

from cfme.utils.update import update

host = appliance.collections.hosts.all()[0]
new_value = fauxfactory.gen_alphanumeric()

with update(host):
    host.custom_ident = new_value

assert host.custom_ident == new_value
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of("Custom Identifier") == new_value

# both the entity instance and CFME have the same value.
# update context has taken care of updating the instance attributes, and has called edit on the instance.

Now, looking in detail at the Host entity code - its using the name attribute for navigation and identification, not custom_ident, so you should be okay with them not matching.

The update method also uses the entity's 'Edit' navigation destination, which only navigates via details page.

The choice/decision here is:

  1. Do you want to keep very explicit navigation/fill calls in the test, kind of decoupling the test from the framework methods, and making it require direct updates instead of updates in the framework when components of MIQ change.

  2. Update the framework methods/classes to provide: 'Edit' navigation via collection, allowing you to pass a kwarg through the update context manager to control how update executes.

I would advocate for choice #2, and add a kwarg to Host.update, maybe 'from_details' that takes a boolean and controls how it navigates to the edit form.

This would also allow you to move the flash message assertions out of the Host.update method, following our best practice for flash message checking in CRUD methods.

Then your test can be written like the above code example - just passing an extra kwarg to update context.

with update(host, from_detail=test_param_indicating_nav_path):
    host.custom_ident = something_random

Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course choice #2 is the way to go. Working on it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated as I believe you were suggesting. I am still working on a nav bug causing nav to details before select Edit even when testing from hosts, but wanted to get comments in the mean time.

@john-dupuy john-dupuy changed the title [RFR] Rewrite of test_infrastructure_hosts_crud for only single hosts [WIPTEST] Rewrite of test_infrastructure_hosts_crud for only single hosts Dec 16, 2019
@prichard77 prichard77 changed the title [WIPTEST] Rewrite of test_infrastructure_hosts_crud for only single hosts [RFR] Rewrite of test_infrastructure_hosts_crud for only single hosts Apr 23, 2020
@prichard77
Copy link
Contributor Author

I still have a bug with navigation to work out for a specific case, but wanted to keep the review going.

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.

1 small change, LGTM otherwise!

except UnexpectedAlertPresentException:
pytest.fail("Abandon changes alert displayed, but no changes made.")
# TODO add additional crud functionality.
from cfme.utils.update import update
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move this to the top of the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@john-dupuy john-dupuy changed the title [RFR] Rewrite of test_infrastructure_hosts_crud for only single hosts [1LP][WIPTEST] Rewrite of test_infrastructure_hosts_crud for only single hosts Apr 24, 2020
@prichard77
Copy link
Contributor Author

I included some additions to HostEditView that ended up not being used in my final implementation. I figured I'd leave them in as they have been tested and will probably be needed sometime in the future. I added a cancel button and is_displayed. This is ready for review again.

@prichard77 prichard77 changed the title [1LP][WIPTEST] Rewrite of test_infrastructure_hosts_crud for only single hosts [1LP][RFR] Rewrite of test_infrastructure_hosts_crud for only single hosts May 1, 2020
@dajoRH dajoRH removed the WIP-testing label May 1, 2020
@prichard77
Copy link
Contributor Author

1 change is requested from Mike. I have already made these updates. Mike, please let me know if I missed something.

with update(host, from_details=(crud_action == 'edit_from_details')):
host.custom_ident = new_custom_id

assert host.custom_ident == new_custom_id
Copy link
Member

Choose a reason for hiding this comment

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

Don't trust the update context manager I see... :)

@mshriver mshriver merged commit 2c5493d into ManageIQ:master May 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants