GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - apibyexample/abe-python: Python tooling around the ABE format

BranchesTags
Open more actions menu

Latest commit

 

History

41 Commits
41 Commits

Folders and files

NameName
Last commit message
Last commit date
abe
abe
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
README.md
README.md
 
 
ep.yml
ep.yml
 
 
requirements.txt
requirements.txt
 
 
setup.py
setup.py
 
 
test-requirements.txt
test-requirements.txt
 
 

Repository files navigation

Build Status

Api By Example for Python

This repository includes tools to be able to use the ABE format from within Python code. In particular we aim to support python tests.

Support for unittest.TestCase

You can use ABE in your unittests by mixing in AbeTestMixin, adding a class-level attribute samples_root that points to a root folder containing your sample files.

You can then compare how your code behaves re: an ABE sample with a simple call:

self.assert_matches_sample(
    path_to_sample, label, actual_url, actual_response
)

Here is a full example:

import os

from abe.unittest import AbeTestMixin
from django.conf import settings
from django.core.urlresolvers import reverse
from rest_framework_jwt.test import APIJWTTestCase as TestCase

from ..factories.accounts import UserFactory, TEST_PASSWORD


class TestMyAccountView(AbeTestMixin, TestCase):
    url = reverse('myaccount')
    samples_root = os.path.join(settings.BASE_DIR, 'docs', 'api')

    def setUp(self):
        super(TestMyAccountView, self).setUp()
        self.user = UserFactory()

    def test_get_my_account_not_logged_in(self):
        """
        If I'm not logged in, I can't access any account data
        """
        response = self.client.get(self.url)
        self.assert_matches_sample(
            'accounts/profile.json', 'unauthenticated', self.url, response
        )

    def test_get_my_account_logged_in(self):
        """
        If I'm logged in, I can access any account data
        """
        self.client.login(username=self.user.username, password=TEST_PASSWORD)

        response = self.client.get(self.url)

        self.assert_matches_sample(
            'accounts/profile.json', 'OK', self.url, response
        )

This is the file under docs/api/accounts/profile.json:

{
    "description": "Retrieve profile of logged in user",
    "url": "/accounts/me",
    "method": "GET",
    "examples": {
        "OK": {
            "request": {
                "url": "/accounts/me"
            },
            "response": {
                "status": 200,
                "body": {
                    "id": 1,
                    "username": "user-0",
                    "first_name": "",
                    "last_name": "",
                    "email": "[email protected]"
                }
            }
        },
        "unauthenticated": {
            "description": "I am not logged in",
            "request": {
                "url": "/accounts/me"
            },
            "response": {
                "status": 403,
                "body": {
                    "detail": "Authentication credentials were not provided."
                }
            }
        }
    }
}

About

Python tooling around the ABE format

Resources

Readme
Activity
Custom properties

Stars

1 star

Watchers

5 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.