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

60: add form creation #72

Merged
merged 2 commits into from
May 2, 2024
Merged

Conversation

lindsay-stevens
Copy link
Contributor

Closes #60

Adds method client.forms.create. There is a parameter for ignore_warnings which defaults to False. The publish parameter is hard coded to True as per #60. The form ID logic is slightly different, as follows - since pyODK has a form_id param and potentially a file path it seemed sensible to prioritise those before a uuid-based form ID fallback.

form_id defaults behaviour for create/update:

  • was:
    • form_id in the file (assuming Central reads and prioritises that)
    • definition file_path.stem
  • now:
    • form_id in the file (assuming Central reads and prioritises that)
    • form_id (or default) provided to pyodk
    • definition file_path.stem
    • random UUID

Also since I anticipated this being used in pyxform-http or similar I made create/update accept bytes. So you could read in the request and send it off without writing to a file. I didn't add that for attachments but it could be done as well. I also had in mind Sam from HOT's recent request for pyxform to support passing in bytes in addition to paths.

What has been done to verify that this works as intended?

Unit tests and E2E tests. Manually verified valid forms were uploaded.

Why is this the best possible solution? Were any other approaches considered?

If the bytes thing seems too much, it's pretty much contained to 36fe156 so that could be dropped if preferred.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

New method to create forms. For update, the definition kwarg now accepts PathLike or bytes in addition to a string path.

Do we need any specific form for testing your changes? If so, please attach one.

No, this PR pulls in xlwt as a dependency for XLS files so we can steadfastly not add binary test fixtures. On the XLS topic, I vendorised (but credited in comments) an external XLS detection function.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

The auto-generated docs would show the new methods.

Before submitting this PR, please make sure you have:

  • included test cases for core behavior and edge cases in tests
  • run python -m unittest and verified all tests pass
  • run ruff format pyxform tests and ruff check pyxform tests to lint code
  • verified that any code or assets from external sources are properly credited in comments

- chg: form_id defaults behaviour for create/update:
  - was:
    - form_id in the file
    - definition file_path.stem
  - now:
    - form_id in the file,
    - form_id (or default) provided to pyodk
    - definition file_path.stem
    - random UUID
- handy if a user already has the file into memory (e.g. because it
  was received in something like pyxform-http, or a test case, or
  because it was created in memory) which saves writing it to a file.
- not implemented for attachments but could do the same there.
- added unit tests for each case of get_definition_data which
  does most of the heavy lifting.
Copy link
Member

@lognaturel lognaturel 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! Nice additions. 👍

We didn't have this in the original issue but I'm realizing it'd be nice to be able to specify attachments in the same way as with an update. Right now to add updates you'd have to first create and then update which is fine but would be great to avoid. That can be in a follow-up PR or in this one, @lindsay-stevens

@lognaturel lognaturel mentioned this pull request Apr 29, 2024
@lindsay-stevens lindsay-stevens merged commit 3ebdba7 into getodk:master May 2, 2024
4 checks passed
@lindsay-stevens lindsay-stevens deleted the pyodk-60 branch May 2, 2024 07:10
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.

Add form creation
2 participants