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 endpoints to viewsets #163

Merged
merged 17 commits into from
Apr 30, 2021
Merged

Conversation

shea-maykinmedia
Copy link
Contributor

@shea-maykinmedia shea-maykinmedia commented Apr 12, 2021

Implements the API points of https://github.com/maykinmedia/open-forms/issues/138. The front end points will be done in a separate pull request.

@shea-maykinmedia shea-maykinmedia changed the title [WIP] Add endpoints to viewsets Add endpoints to viewsets Apr 14, 2021
@shea-maykinmedia
Copy link
Contributor Author

Not sure who I should mark as reviewers so I just marked you @sergei-maertens but feel free to add others and/or remove yourself :)

Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

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

Please review the remaining tests with the remarks so that they are corrected everywhere.

In short - you seem to be doing quite a lot "manually" in the code that is actually (mostly) handled by the frameworks and libraries already - use that to do more with less code!

Additionally, the way of writing tests deserves some more attention.

src/openforms/forms/api/permissions.py Outdated Show resolved Hide resolved
src/openforms/forms/api/serializers.py Outdated Show resolved Hide resolved
src/openforms/forms/api/serializers.py Outdated Show resolved Hide resolved
src/openforms/forms/api/serializers.py Outdated Show resolved Hide resolved
src/openforms/forms/api/validators.py Outdated Show resolved Hide resolved
src/openforms/forms/tests/test_api.py Outdated Show resolved Hide resolved
src/openforms/forms/tests/test_api.py Outdated Show resolved Hide resolved
src/openforms/forms/tests/test_api.py Outdated Show resolved Hide resolved
src/openforms/forms/tests/test_api.py Outdated Show resolved Hide resolved
src/openforms/forms/tests/test_api.py Outdated Show resolved Hide resolved
def create(self, validated_data):
validated_data["form"] = get_object_or_404(
Form, uuid=self.context["view"].kwargs["form_uuid"]
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the Form doesn't exist when trying to create a FormStep then this code would be reached since there didn't seem to be anywhere that validates a Form exists for a given uuid. This seemed the best place to raise a 404 in that case though I'm happy to hear other options. :)

Copy link
Member

Choose a reason for hiding this comment

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

yeah, it seems to be a limitation of the nested viewset library used in this project. Perhaps we should replace it with the one used in Open Zaak, that one seems to be more feature complete. So we can keep this for now.

It's just very nasty in this particular case (not your fault) that the serializer has to be aware of the view's URL keywords, that's violating two abstraction levels.

Comment on lines +214 to +217
# TODO: Axes requires HttpRequest, should we have that in the API at all?
assert self.client.login(
request=HttpRequest(), username=self.user.username, password="secret"
)
Copy link
Member

Choose a reason for hiding this comment

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

you can use self.client.force_authenticate to simplify this, we don't actually care about the particular credentials here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good to remember for the future :)

@sergei-maertens sergei-maertens merged commit 5a46feb into master Apr 30, 2021
@sergei-maertens sergei-maertens deleted the feature/add-form-endpoints branch April 30, 2021 13:46
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

2 participants