Skip to main content

Smoke tests for API built with Django Rest Framework

Project description

Rest-Framework-Smoke

Smoke tests for API built with Django Rest Framework.

build codecov PyPI version

Installation

pip install rest-framework-smoke

Usage

Full example located at testproject.testapp.tests

from rest_framework.test import APITestCase

from rest_framework_smoke.tests.mixins import ReadOnlyViewSetTestsMixin
from rest_framework_smoke.tests.schemas import get_object_schema
from testproject.testapp import models

TASK_SCHEMA = {
    "id": {"type": ["number"]},
    "name": {"type": ["string"]},
}

PROJECT_SCHEMA = {
    "id": {"type": ["number"]},
    "name": {"type": ["string"]},
    "task_set": {
        "type": ["array"],
        "minItems": 1,
        "items": get_object_schema(TASK_SCHEMA)
    }
}


class ProjectViewSetTestCase(ReadOnlyViewSetTestsMixin, APITestCase):
    object_name = 'project'
    basename = 'projects'
    schema = details_schema = PROJECT_SCHEMA
    pagination_schema = None

    @classmethod
    def setUpTestData(cls):
        cls.project = models.Project.objects.create(name='project')
        cls.task = models.Task.objects.create(name='task', project=cls.project)

Happy API testing :)

About schema checks

Rest-Framework-Smoke uses jsonschema to validate API response format. When we check format, we should pay attention to:

  • no unexpected properties are found (is so, they are not validated by schema)
  • there are no missing properties (missing properties are not validated)
  • arrays are not empty (because there is nothing to check in empty arrays)
  • all values are not null (because null values mostly are null by default, and other type variants will never appear in schema validation code)

So there are two helpers in rest_framework_smoke.tests.schemas to enforce these constraints (and they are used internally for format tests):

  • get_object_schema
  • get_array_schema

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rest-framework-smoke-0.9.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

rest_framework_smoke-0.9.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file rest-framework-smoke-0.9.0.tar.gz.

File metadata

  • Download URL: rest-framework-smoke-0.9.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for rest-framework-smoke-0.9.0.tar.gz
Algorithm Hash digest
SHA256 7d21df539b80f887de2e9d6cf1ab4219c2c4cd4e2ed3b3f95697df33638ed065
MD5 0a028cc46645b3c30376f90ba7461dfd
BLAKE2b-256 19c017d810c2e7f9c509cd2e4f600cbd284e5094567868af8ccee007100f8ec8

See more details on using hashes here.

File details

Details for the file rest_framework_smoke-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rest_framework_smoke-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa180cc2547bc23f92cfe719baa1df398387dd4d96d598a13a98b53345f14225
MD5 e02a66caae902a684e67ebbd622c9737
BLAKE2b-256 60c2ee84d02019568600a10e37280eb6077c805f0d8c16768967425ddaea209d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page