Skip to main content

wrapAPI

Requests wrapper for API testing

Usage

conftest

conftest.py

import pytest

from wrapapi import Application, Settings


@pytest.fixture(scope='session')
def settings() -> Settings:
    config = Settings()
    config.base_url = 'http://localhost:5555'
    config.headers['Autorization'] = 'Basic secret'
    return config


@pytest.fixture(scope='session')
def client(settings) -> Application:
    app = Application(settings)
    client = app.create()
    yield client
    client.close()


@pytest.fixture(scope='function')
def app(client) -> Application:
    yield client
    client.report.build()

tests with pytest fixture

def test_main(app):
    response = app.get('/api/main', status=200)
    response.json.should.be.is_instance(list)


def test_main_item(app):
    response = app.get('/api/main/666', status=200)
    response.json.should.be.equal({'id': 666, 'name': 'test'})

TestCase

with TestSuite

from wrapapi import TestSuite


class TestExample(TestSuite):

    def test_main(self):
        response = self.app.get('/api/main', status=200)
        response.json.should.be.is_instance(list)

    def test_main_item(self):
        response = self.app.get('/api/main/666', status=200)
        response.json.should.be.equal({'id': 666, 'name': 'test'})

AssertionErrors

If we have any errors, raise exception with full request data:

E           AssertionError: 
E           ===========================================================
E           GET: http://localhost:5555/api/main/666
E           -----------------------------------------------------------
E               Status: 200
E               Body: None
E               Headers: {'Date': 'Wed, 27 Mar 2019 12:17:48 GMT', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'Content-Length': '51'....}
E           ===========================================================
E           Not equal: {'id': 666, 'name': 'test'} == {'id': 1, 'name': 'test'}
E                -> expected: {'id': 666, 'name': 'test'}
E                -> current: {'id': 1, 'name': 'test'}

Download files

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

Source Distribution

wrapAPI-0.0.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wrapAPI-0.0.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file wrapAPI-0.0.1.tar.gz.

File metadata

  • Download URL: wrapAPI-0.0.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for wrapAPI-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fac82fae31a38df6d21d4b403188918a107d9a6c395e71c9ee165e620e04a369
MD5 97afbb6005906fca6cf7f69e2c1846a6
BLAKE2b-256 a50519a251c4fbfee36323cd958ab17849eb6545bd91941ace946030589c2611

See more details on using hashes here.

File details

Details for the file wrapAPI-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: wrapAPI-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for wrapAPI-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30566d70b37a29e089636016e304dc4f6669704d616c21feaba3eb474fcbbbd7
MD5 7bcf8cf9b6fdc90b0e67f1a55e66a3d8
BLAKE2b-256 ca84bf5ef92950b84cfc344b0c50e5cc56a11e1e8a3deb0b3707187ca9527b6e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page