-
Notifications
You must be signed in to change notification settings - Fork 81
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
Fix #1018: Make project details editing work again #1019
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -935,6 +935,8 @@ class ProjectEditDetailsTest(ViewTestCase, UserTestCase, | |
|
||
def setup_models(self): | ||
self.project = ProjectFactory.create(current_questionnaire='abc') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take note that this project creation does not actually create any valid |
||
self.questionnaire = QuestionnaireFactory.create(project=self.project, | ||
id='abc') | ||
|
||
def setup_url_kwargs(self): | ||
return { | ||
|
@@ -945,7 +947,11 @@ def setup_url_kwargs(self): | |
def setup_template_context(self): | ||
return {'project': self.project, | ||
'object': self.project, | ||
'form': forms.ProjectEditDetails(instance=self.project)} | ||
'form': forms.ProjectEditDetails( | ||
instance=self.project, | ||
initial={'questionnaire': self.questionnaire.xls_form.url, | ||
'original_file': self.questionnaire.original_file} | ||
)} | ||
|
||
def test_get_with_authorized_user(self): | ||
user = UserFactory.create() | ||
|
@@ -956,6 +962,20 @@ def test_get_with_authorized_user(self): | |
assert response.content == self.expected_content | ||
assert 'Select the questionnaire' in self.expected_content | ||
|
||
def test_get_empty_questionnaire_with_authorized_user(self): | ||
user = UserFactory.create() | ||
assign_policies(user) | ||
|
||
self.project.current_questionnaire = '' | ||
self.project.save() | ||
|
||
form = forms.ProjectEditDetails(instance=self.project) | ||
|
||
response = self.request(user=user) | ||
assert response.status_code == 200 | ||
assert response.content == self.render_content(form=form) | ||
assert 'Select the questionnaire' in self.expected_content | ||
|
||
def test_get_with_blocked_questionnaire_upload(self): | ||
user = UserFactory.create() | ||
assign_policies(user) | ||
|
@@ -1010,6 +1030,7 @@ def test_post_with_authorized_user(self): | |
self.project.refresh_from_db() | ||
assert self.project.name == self.post_data['name'] | ||
assert self.project.description == self.post_data['description'] | ||
assert self.project.current_questionnaire == '' | ||
|
||
def test_post_with_blocked_questionnaire_upload(self): | ||
SpatialUnitFactory.create(project=self.project) | ||
|
@@ -1023,6 +1044,20 @@ def test_post_with_blocked_questionnaire_upload(self): | |
assert self.project.description != self.post_data['description'] | ||
assert self.project.current_questionnaire == 'abc' | ||
|
||
def test_post_empty_questionnaire_with_blocked_questionnaire_upload(self): | ||
SpatialUnitFactory.create(project=self.project) | ||
user = UserFactory.create() | ||
assign_policies(user) | ||
response = self.request(user=user, method='POST', | ||
post_data={'questionnaire': None}) | ||
|
||
assert response.status_code == 302 | ||
assert self.expected_success_url in response.location | ||
self.project.refresh_from_db() | ||
assert self.project.name == self.post_data['name'] | ||
assert self.project.description == self.post_data['description'] | ||
assert self.project.current_questionnaire == 'abc' | ||
|
||
def test_post_invalid_form(self): | ||
question = self.get_form('xls-form-invalid') | ||
user = UserFactory.create() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with this. We should still test that the view does not update the questionnaire if the project has data. So we should write a test that rejects the update, even though with the current template it's not possible to upload a new questionnaire. My rationale behind it is that if we change the template for some reason and accidentally enable to update the questionnaire, the update will still be rejected from the view, no matter hat the template looks like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense. But as I mentioned in another comment, neither the form nor the view does any rejection. So we would need to add that rejection functionality before we can test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, it seems that the original line of code (
ProjectFactory.create(current_questionnaire='abc')
) does not actually create a project with a valid questionnaire. We would need to create aQuestionnaire
instance too insetup_models
.