[1LP][RFR] Create test_import_tag and implement fixtures and functions it needs#10162
[1LP][RFR] Create test_import_tag and implement fixtures and functions it needs#10162jawatts merged 11 commits intoManageIQ:masterfrom
Conversation
|
I still might have some debugging to do in the csv file cleanup, but wanted to get the review started. |
cfme/tests/configure/test_tag.py
Outdated
|
|
||
| @pytest.fixture | ||
| def csv_tag_file(create_vm, category, tag): | ||
| file_name = 'test_import_' + fauxfactory.gen_alphanumeric(4) + ".csv" |
There was a problem hiding this comment.
I highly recommend using tempfile for this:
https://docs.python.org/3.7/library/tempfile.html
|
|
||
| @pytest.fixture | ||
| def csv_tag_file(create_vm, category, tag): | ||
| temp_file = tempfile.NamedTemporaryFile(suffix=".csv") |
There was a problem hiding this comment.
So, you can use tempfiles's context manager here to make this even simpler.
with tempfile.NamedTemporaryFile(suffix='.csv') as temp_file:
tempfile.write(csv_data)
yield temp_file.name
Note this is yielding the file name, not the file object, which is what the test actually needs anyway.
After the yield, the context manager exists and the file is deleted
There was a problem hiding this comment.
Updated as suggested. I was on the fence about returning the object or just name. I relaize I just use the name, but was thinking I might want to access the object if I used this fixture for another test. Using it in another test seems quite unlikely now.
There was a problem hiding this comment.
getting error trying to use tempfile: TypeError: expected str, bytes or os.PathLike object, not _TemporaryFileWrapper . Investigating.
There was a problem hiding this comment.
I was unable to get the shortened version to work. Tried a few things but was getting errors or creating empty files. Moving on to the asserts for the vm tag.
|
|
||
| Args: | ||
| file_name: Name of .csv file containing tag data. | ||
| By default file must be at cfme/tests/configure/ |
There was a problem hiding this comment.
Why must the file be at this location? tempfile should take care of the file location, and it shouldn't matter where the file is for the import in the UI.
There was a problem hiding this comment.
Removed the comment. his is where I was seeing the framework put the file. I guess it handles this location so we don't need to care about it.
| @pytest.fixture | ||
| def csv_tag_file(create_vm, category, tag): | ||
| temp_file = tempfile.NamedTemporaryFile(suffix=".csv") | ||
| csv_data = f'name,category,entry\n{create_vm.name},{category.display_name},{tag.display_name}' |
There was a problem hiding this comment.
Shouldn't you be using a random alphanumeric for the tag, instead of trying to import a tag that matches an existing one?
The tag fixture that you're using here is a random tag that has already been created on the category.
There was a problem hiding this comment.
yes. The import is to add the existing tag value to a VM. If the tag or category or VM do not exist, the upload fails. the terms here are confusing between a category, entry, tag etc. . I believe i have the bahavior ad it is in the BZ.
There was a problem hiding this comment.
Can you add to the docblock for the test case the description that you're importing tag mappings to a VM, and not just tag definitions.
cfme/tests/configure/test_tag.py
Outdated
| Bugzilla: | ||
| 1792185 | ||
| """ | ||
| category.import_tag_from_file(csv_tag_file.name) |
There was a problem hiding this comment.
I think some additional assertions are necessary here - you have the tag and category display names, you should be able to instantiate a Tag and assert that it exists.
Look at something like:
assert category.tags.instantiate(display_name=tag.display_name).exists
There was a problem hiding this comment.
If the tag does not exist the import will not work. The BZ issue was that an error gets displayed after "Upload" is clicked but before the apply. We are covering the BZ here. I guess I could add an assert that the tag exists on the VM?
There was a problem hiding this comment.
gotcha, that makes more sense - please update the docblock with more detailed description of what's being tested.
Also correct about the additional assertion of the tag on the VM. You should be able to call tag in create_vm.get_tags, as the tag has an __eq__ implementation.
There was a problem hiding this comment.
I put the assert against the vm tags in the category.import_tag_from_file() method.
I could have put it in the test case itself, but chose the method.
If I put it in the testcase I wouldn't need to pass down the extra 2 args to import_tag_from_file and could leave more flexibility in other tests to check results for an already existing tag (just comparing the display name strings) without having to create the tag object.
But how much more tagging tests are we going to write? And if we do write more, couldn't I just move the assert out then?
There was a problem hiding this comment.
I moved the validation of the tag on the VM out into the testcase.
|
I detected some fixture changes in commit 0438283 The local fixture
Please, consider creating a PRT run to make sure your fixture changes do not break existing usage 😃 |
john-dupuy
left a comment
There was a problem hiding this comment.
One question, otherwise LGTM 👍
Purpose or Intent
PRT Run
{{ pytest: --use-provider vsphere65-nested cfme/tests/configure/test_tag.py::test_import_tag }}