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

reworked import test+ worked on fresh branch #246

Merged
merged 4 commits into from
Feb 6, 2024
Merged

Conversation

Mudiwa66
Copy link
Contributor

@Mudiwa66 Mudiwa66 commented Feb 5, 2024

Fixed the import test. Check the db state as opposed to comparing the input and output files directly. Also switched to new branch since the old one got too messy.

@Mudiwa66
Copy link
Contributor Author

Mudiwa66 commented Feb 5, 2024

This took longer than anticipated.

@Mudiwa66 Mudiwa66 requested a review from jerith February 5, 2024 14:13
def test_ContentPageIndex_required_fields(self, csv_impexp: ImportExport) -> None:
"""
Importing an CSV file with only the required fields shoud not break

Copy link
Member

Choose a reason for hiding this comment

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

No need for these empty lines at the end of the docstrings.

content = csv_impexp.export_content()
src, dst = csv_impexp.csvs2dicts(csv_bytes, content)

content_pages = ContentPageIndex.objects.all()
Copy link
Member

Choose a reason for hiding this comment

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

Since we know what the source data is, we can be a lot more explicit with the assertions:

[main_menu] = ContentPageIndex.objects.all()
assert main_menu.slug == "main-menu"

The first line will fail if we don't have exactly one ContentPageIndex, and the second will fail if the slug doesn't match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept this line since I use that to check how many pages/ indexes we have, but I could find a work around to get that data directly from csv_bytes, not sure.

Copy link
Member

Choose a reason for hiding this comment

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

Comparing the original and re-exported CSVs will ensure that the line/page counts are the same, and the [main_menu] = ... assignment will raise an exception if the sequence on the right doesn't have exactly one element. 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, I brought back the part that compares the imported and exported files. I had to clean it up the exported file a bit because the exporter adds extra fields we don't want to check for.


content_pages = list(ContentPageIndex.objects.all()) + list(
ContentPage.objects.all()
)
Copy link
Member

Choose a reason for hiding this comment

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

As with the previous test, we can be a lot more explicit:

[main_menu] = ContentPageIndex.objects.all()
[first_time_user, health_info, self_help] = ContentPage.objects.all()
# And then a slug assertion for each page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, I kept the line that defines content_pages so checking the sum a a bit cleaner.

Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to assert on the sum if we already get an exception when any of the queries returns the wrong number of results?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, no need for that check, removed.

content = csv_impexp.export_content()
src, dst = csv_impexp.csvs2dicts(csv_bytes, content)

# the importer adds extra fields, so we fikter for the ones we want
Copy link
Member

Choose a reason for hiding this comment

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

Tyop in this comment (and the one below): fikter -> filter.

@Mudiwa66 Mudiwa66 merged commit 08d2e18 into main Feb 6, 2024
4 checks passed
@Mudiwa66 Mudiwa66 deleted the min-import-fields branch February 6, 2024 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants