{"repo":"theY4Kman/pytest-drf","free":true,"listed":false,"github":"https://github.com/theY4Kman/pytest-drf","clone":"git clone https://github.com/theY4Kman/pytest-drf.git","description":"A Django REST framework plugin for pytest","language":"Python","stars":87,"topics":["pytest","python","django","django-rest-framework"],"license":"MIT","category":"saas-starters-boilerplates","readme_excerpt":"pytest-drf pytest-drf is a pytest plugin for testing your Django REST Framework APIs. Installation The Spiel pytest-drf aims to shoo away clunky setup code and boilerplate in DRF tests, in favor of declarative scaffolds and configurable fixtures encouraging small, easy-to-follow tests with single responsibilities. This is accomplished by performing one request per test, and providing the response as a fixture. All configuration of the request — the URL, the query params, the HTTP method, the POST data, etc — is also done through fixtures. This frees the test methods to contain only assertions about the response or the state of the app after the request completes. For example, consider a public API endpoint that responds to a GET request with the JSON string \"Hello, World!\" and a 200 status code. Such an endpoint might be written like so Let's route it to /hello , and give it a name, so we can easily generate URLs for it. With pytest-drf, we'd verify the behavior of our endpoint with something like this When we run pytest, we see two tests run What happened here? Well, APIViewTest defines a response fixture that takes the value of the url fixture and makes an HTTP request to it. The UsesGetMethod mixin defines the http method as 'get' , making it a GET request. The response fixture is defined as autouse=True , so it's automatically evaluated before the test method is executed. The Returns200 mixin simply adds a test with assert response.status code == 200 . This test has its o","default_branch":null,"files":null,"tree":[],"storefront":"/r/theY4Kman","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/theY4Kman/pytest-drf/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}