Exemplo n.º 1
0
def run_around_tests():
    """Cleanup Database after each test run"""
    from protean.core.repository import repo_factory
    from authentic.utils import get_account_entity
    from .support.sample_app.entities import Human

    Account = get_account_entity()

    # A test function will be run at this point
    yield

    repo_factory.get_repository(Account).delete_all()
    repo_factory.get_repository(Human).delete_all()
Exemplo n.º 2
0
def register_models():
    """Register Test Models with Dict Repo

       Run only once for the entire test suite
    """
    from protean.core.repository import repo_factory
    from authentic.utils import get_account_entity

    from .support.sample_app.entities import Human

    Account = get_account_entity()

    repo_factory.register(Account)
    repo_factory.register(Human)
Exemplo n.º 3
0
def perform_authentication():
    """ Perform the authentication of the request """

    # Get the authorization header and build payload
    auth_header = request.headers.get('Authorization', '').split()
    auth_payload = {}
    if auth_header and len(auth_header) == 2:
        auth_payload['auth_scheme'] = auth_header[0]
        auth_payload['credentials'] = auth_header[1]

    # Get the account entity and the current backend
    account_entity = get_account_entity()
    auth_backend = get_auth_backend()

    # Perform the task and check the response
    response = Tasklet.perform(account_entity,
                               auth_backend.AuthenticationUseCase,
                               auth_backend.AuthenticationRequestObject,
                               auth_payload)
    return response
"""Module to test Protected Viewset functionality and features"""
import base64
import json

import pytest
from authentic.utils import get_account_entity
from passlib.hash import pbkdf2_sha256

from .support.sample_app import app
from .support.sample_app.entities import Human

Account = get_account_entity()


class TestGenericAPIResourceSet:
    """Class to test GenericAPIResourceSet functionality and methods"""
    @pytest.fixture(scope="function", autouse=True)
    def client(self):
        """ Setup client for test cases """
        yield app.test_client()

    @pytest.fixture(scope="function", autouse=True)
    def auth_header(self):
        """ Setup auth header for test cases """
        header = {
            'Authorization': b'Basic ' + base64.b64encode(b'janedoe:duMmy@123')
        }
        yield header

    @pytest.fixture(scope="function", autouse=True)
    def account(self):
Exemplo n.º 5
0
class SomeProtectedView(ShowAPIResource):
    """ A simple protected class based view """
    entity_cls = get_account_entity()
    serializer_cls = AccountSerializer
    decorators = [is_authenticated()]