integration-testing

Integration testing FastAPI with user authentication

Integration testing FastAPI with user authentication Question: I am trying to write some integration tests for my FastAPI endpoints and am not sure what the best solution is to testing the endpoints that require a user to be logged in. I am following the FastAPI authentication documentation for my auth flow which is just username …

Total answers: 1

How to keep Unit tests and Integrations tests separate in pytest

How to keep Unit tests and Integrations tests separate in pytest Question: According to Wikipedia and various articles it is best practice to divide tests into Unit tests (run first) and Integration tests (run second), where Unit tests are typically very fast and should be run with every build in a CI environment, however Integration …

Total answers: 2

How to apply integration tests to a Flask RESTful API

How to apply integration tests to a Flask RESTful API Question: [As per https://stackoverflow.com/a/46369945/1021819, the title should refer to integration tests rather than unit tests] Suppose I’d like to test the following Flask API (from here): import flask import flask_restful app = flask.Flask(__name__) api = flask_restful.Api(app) class HelloWorld(flask_restful.Resource): def get(self): return {‘hello’: ‘world’} api.add_resource(HelloWorld, ‘/’) …

Total answers: 5

What's the proper way to test token-based auth using APIRequestFactory?

What's the proper way to test token-based auth using APIRequestFactory? Question: The query to my endpoint works fine (as long as I pass it a valid token), it returns the json representation of my response data. The code in the service api that calls my endpoint, passing an auth token in the header: headers = …

Total answers: 4

How do I test the setup.py for my package?

How do I test the setup.py for my package? Question: I have a pretty big Python package I’ve written, about 3500 statements, with a robust unit and acceptance test suite. I feel quite confident about the quality of the code itself, but I’m uneasy about the install process going smoothly for users of the package …

Total answers: 3

Is there a convention to distinguish Python integration tests from unit tests?

Is there a convention to distinguish Python integration tests from unit tests? Question: The most common way of structuring a Python package with unit tests is as follows: package/ __init__.py module_1.py module_2.py module_n.py test/ __init__.py test_module_1.py test_module_2.py test_module_n.py I would like to distinguish between unit tests (of methods and functions) and integration tests (using the …

Total answers: 2

Simulating the passing of time in unittesting

Simulating the passing of time in unittesting Question: I’ve built a paywalled CMS + invoicing system for a client and I need to get more stringent with my testing. I keep all my data in a Django ORM and have a bunch of Celery tasks that run at different intervals that makes sure that new …

Total answers: 4