Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
 
Answered
How can unit tests be written and ran for periodic entrypoints?

For regular SDK extensions, there are clear instructions and templates for creating and running unit tests. For periodic entrypoints, however, I cannot find any such instructions. How can we create unit tests for these programs?

Posted 2 years ago
Votes Newest

Answers


Hey Ethan,

Tests can be added to a periodic job in the same way that they are included with extensions.

Since we use pytest in the SDK, all that is really needed in a file name that starts with "test". For example, if I run "q2 create_endpoint" and create a new endpoint name "addingTests" the SDK would build a new directory (on the latest SDK version) called addingTests and an entrypoint.py is also written with some templated code. To add tests to this, I would simply create a new directory in that addingTests directory (for organizational purposes, not required) and then create a new python file in there named "test_addingTests.py". Since this file starts with "test", pytest will detect it and run the "test" methods found in the file.

Here is some example code showing what that test_addingTests.py file could look like:

import pytest
from q2_sdk.tools.testing.decorators import mock_q2_request
from .. import entrypoint


class MockTestGTFlavorHandler(entrypoint.EntryPoint):

    def __init__(self):
        super().__init__()

@pytest.mark.skip(reason="Generated with extension")
async def test_default_route():
    handler = MockTestGTFlavorHandler()
    actual = await handler.run()

mock_q2_request is used to mock any network request, or you could use pytest's monkeypatch to mock various functions with the different scenarios you are wanting to test.

Let me know if you have any questions.

Thanks,
Paden Rose

PS. We will also do some work to include tests out of the box for periodic jobs like we do with extensions.

Posted 2 years ago
Paden Rose
160 × 1 Administrator
130 Views
1 Answer
2 years ago
2 years ago