~homeworkprod/byceps

93729d5e22f50becece9465455965c3ab583ac0c — Jochen Kupperschmidt 2 years ago 99e5b39
Pass authorization header to fix tourney API tests
M config/test_party.py => config/test_party.py +2 -0
@@ 28,3 28,5 @@ MAIL_DEFAULT_SENDER = 'BYCEPS <noreply@example.com>'
MAIL_SUPPRESS_SEND = True

JOBS_ASYNC = False

API_TOKEN = 'just-say-PLEASE'

A tests/api_helpers.py => tests/api_helpers.py +20 -0
@@ 0,0 1,20 @@
"""
tests.api_helpers
~~~~~~~~~~~~~~~~~

:Copyright: 2006-2019 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from base64 import b64encode
from typing import Tuple


def assemble_authorization_header(api_token: str) -> Tuple[str, str]:
    """Assemble header to authorize against the API."""
    encoded_token = b64encode(api_token.encode('ascii')).decode('ascii')

    name = 'Authorization'
    value = 'Bearer ' + encoded_token

    return name, value

M tests/blueprints/api/tourney/match/test_comment_create.py => tests/blueprints/api/tourney/match/test_comment_create.py +8 -1
@@ 3,10 3,13 @@
:License: Modified BSD, see LICENSE for details.
"""

from base64 import b64encode

from byceps.services.tourney.models.match import MatchComment
from byceps.services.tourney import match_service

from tests.base import AbstractAppTestCase
from tests.api_helpers import assemble_authorization_header
from tests.helpers import create_brand, create_party, create_session_token, \
    create_site, create_user, http_client



@@ 65,12 68,16 @@ class MatchCommentCreateTest(AbstractAppTestCase):
    def request_comment_creation(self, match_id, *, user_id=None):
        url = '/api/tourney/matches/{}/comments'.format(match_id)

        headers = [
            assemble_authorization_header('just-say-PLEASE'),
        ]

        form_data = {
            'body': 'gg',
        }

        with http_client(self.app, user_id=user_id) as client:
            return client.post(url, data=form_data)
            return client.post(url, headers=headers, data=form_data)


def get_comment_count_for_match(match_id):