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

MVJ-112: area search attachments: hide user and attachment path from API response in public #819

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

NC-jsAhonen
Copy link
Contributor

@NC-jsAhonen NC-jsAhonen commented Jan 24, 2025

With these changes, the API response to the POST requests will hide sensitive information about the attachments.

Copy link
Contributor

@henrinie-nc henrinie-nc left a comment

Choose a reason for hiding this comment

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

How about forms attachment?

@NC-jsAhonen NC-jsAhonen force-pushed the MVJ-112-api-does-not-give-file-url-in-response branch from 1a08571 to 7cde77f Compare January 27, 2025 08:58
@NC-jsAhonen NC-jsAhonen force-pushed the MVJ-112-api-does-not-give-file-url-in-response branch from 7cde77f to 9863eb9 Compare January 27, 2025 09:26
@NC-jsAhonen
Copy link
Contributor Author

How about forms attachment?

Now added.

@henrinie-nc
Copy link
Contributor

henrinie-nc commented Jan 27, 2025

Looks good! It could be useful to add a comment, or add the list of fields in a named variable to indicate what is being done and why

Copy link
Contributor

@henrinie-nc henrinie-nc left a comment

Choose a reason for hiding this comment

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

Changed the approve to request changes, realized that this should also include tests.

@NC-jsAhonen
Copy link
Contributor Author

Created variables for the excluded fields and commented. They turned out to be useful in the unit tests as well.



@pytest.mark.django_db
def test_area_search_attachment_post_public(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this test exist in the areasearch app?

):
example_file = SimpleUploadedFile(name="example.txt", content=b"Lorem lipsum")
payload = {
"field": Field.objects.all().first().id,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend creating the field with a factory here, so that the test has control over what the field is.

Copy link
Contributor

Choose a reason for hiding this comment

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

@henrinie-nc the fields are created by FieldFactory in the imported fixture basic_form. AFAIK there is no importance in this ID in this tests, the receiving model just requires it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a Field requires a Section, which in turn requires a Form, so might as well use a complete fixture to pull those.

Copy link
Contributor

Choose a reason for hiding this comment

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

Missed that detail, thanks - then it really makes sense like it is

response = admin_client.post(url, data=payload, content_type="application/json")

assert response.status_code == 201
assert Attachment.objects.filter(answer=response.json()["id"]).exists()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this also test that it doesn't return any unwanted fields?

@@ -430,6 +432,97 @@ def test_attachment_delete(
assert os.path.isfile(file_path) is False


@pytest.mark.django_db
def test_attachment_post_public(
Copy link
Contributor

Choose a reason for hiding this comment

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

The test name could clarify what is it testing for, and enhanced with comments. It is not very clear what is being tested, the name indicates it is just to test that the endpoint works

)
== 0
)

Copy link
Contributor

Choose a reason for hiding this comment

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

How about testing the areasearch endpoint, that it doesnt return the undesired fields?

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.

3 participants