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

Add factoryboy Project and Allocation unit tests #546

Merged
merged 8 commits into from
Jul 28, 2023

Conversation

claire-peters
Copy link
Contributor

This PR includes:

  • building out of the test_helpers/factory.py module, particularly Project and Allocation-related factories.
  • unit test utility functions
  • unit tests for Project models and views
  • unit tests for Allocation models and views

There are also a couple of minor changes made to the Allocation views:

  • remove login_url from AllocationChangeListView so the redirect when not logged in will be to '/user/login?next={page}'
  • add success message to AllocationCreateView post request (successful submission of an allocation creation request now includes a corresponding success message)

Looking forward to your comments!

class Meta:
model = ProjectUserStatusChoice
django_get_or_create = ('name',)
name = 'Active'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here the "name" value is hard-coded instead of taken from a list of possible values because it's the value that's most useful during testing. A different approach was used in ProjectStatusChoiceFactory (line 117), where possible choices were randomly assigned.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great idea!

from factory import SubFactory
### Default values and Faker provider setup ###

project_status_choice_names = ['New', 'Active', 'Archived']
Copy link
Contributor Author

@claire-peters claire-peters Jul 8, 2023

Choose a reason for hiding this comment

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

The hardcoding of the default values here repeats the default values that are listed in project.utils.add_project_status_choices and project.management.commands.add_default_project_choices. It seems like it could be useful to encode default values for model objects in one location in an app-level config.py file or something similar - happy to open an issue for this and then make the change in this or another PR if it sounds good.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I love this idea @claire-peters! I would definitely recommend we do this in another PR as long as @dsajdak and @aebruno agree as well.

@dsajdak dsajdak requested a review from rg663 July 11, 2023 19:47
Copy link
Collaborator

@rg663 rg663 left a comment

Choose a reason for hiding this comment

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

These look great, @claire-peters! I just left some small comments on some files pertaining to issue #541 about whether or not those were meant to go in this testing PR, or if they were supposed to go in a separate PR. Also, the changes to user/tests.py didn't seem to add any testing, so we could delete that unless the imports were placed there for a reason.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@claire-peters I was looking through the testing you added and it looks great! On this file (user/tests.py), I'm not seeing anything besides unused imports and some newlines that were added so I think we can safely discard changes to this file!

Copy link
Collaborator

Choose a reason for hiding this comment

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

If I'm understanding correctly, the changes on this file and templates/allocation/allocation_request_list.html appear to be addressing issue #541 rather than testing. Not sure if this was meant to be combined with this PR @claire-peters but just wanted to check!

Copy link
Collaborator

Choose a reason for hiding this comment

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

If I'm understanding correctly, the changes on this file and templates/allocation/allocation_change_list.html appear to be addressing issue #541 rather than testing. Not sure if this was meant to be combined with this PR @claire-peters but just wanted to check!

Copy link
Collaborator

Choose a reason for hiding this comment

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

If I'm understanding correctly, the changes on this file and the allocation templates above appear to be addressing issue #541 rather than testing. Not sure if this was meant to be combined with this PR @claire-peters but just wanted to check!

from factory import SubFactory
### Default values and Faker provider setup ###

project_status_choice_names = ['New', 'Active', 'Archived']
Copy link
Collaborator

Choose a reason for hiding this comment

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

I love this idea @claire-peters! I would definitely recommend we do this in another PR as long as @dsajdak and @aebruno agree as well.

class Meta:
model = ProjectUserStatusChoice
django_get_or_create = ('name',)
name = 'Active'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great idea!

Copy link
Collaborator

@rg663 rg663 left a comment

Choose a reason for hiding this comment

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

Small changes described in the comments!

@claire-peters
Copy link
Contributor Author

Thanks for catching the issues there - the parts for #541 should be in a separate PR, and I'm happy to put off any formatting changes to the user tests module until it can be paired with a more substantive contribution to said module. Just pushed my changes, let me know what you think.

Copy link
Collaborator

@rg663 rg663 left a comment

Choose a reason for hiding this comment

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

Changes look great! Thank you @claire-peters!

Copy link
Member

@aebruno aebruno left a comment

Choose a reason for hiding this comment

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

@claire-peters thanks so much for this PR. All looks great. Should all the tests be passing? When I just try running coldfront test I'm getting 3 failures:

1. FAIL: test_allocationchangelistview_access (coldfront.core.allocation.test_views.AllocationChangeListViewTest)

 AssertionError: '/?next=%2Fallocation%2Fchange-list' != '/user/login?next=%2Fallocation%2Fchange-list'
- /?next=%2Fallocation%2Fchange-list
+ /user/login?next=%2Fallocation%2Fchange-list
?  ++++++++++
 : Response redirected to '/?next=/allocation/change-list', expected '/user/login?next=/allocation/change-list'Expected '/?next=/allocation/change-list' to equal '/user/login?next=/allocation/change-list'.

2. FAIL: test_allocationcreateview_post (coldfront.core.allocation.test_views.AllocationCreateViewTest)
Test POST to the AllocationCreateView
----------------------------------------

AssertionError: False is not true : Couldn't find 'Allocation requested.' in response

3. FAIL: test_allocationcreateview_post_zeroquantity (coldfront.core.allocation.test_views.AllocationCreateViewTest)
Test POST to the AllocationCreateView

AssertionError: False is not true : Couldn't find 'Allocation requested.' in response

If these are expected failures I'm happy to merge. If not, perhaps we can get those passing?

@claire-peters
Copy link
Contributor Author

Whup, thanks for catching that. Added the changes to make the tests work - specifically, I made it so a success message would appear on the following page after an allocation request has been successfully submitted and I removed the line login_url = '/' from AllocationChangeListView. If there are any issues with this, just let me know.

Copy link
Member

@aebruno aebruno left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks!

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.

None yet

3 participants