<commit_before># -*- coding: utf-8 -*-

import base64

from nose.tools import assert_is_instance, assert_true, assert_tuple_equal

from tuxedo_mask import clients


def test_base_client_has_repository_attributes():

    class FooMockRepository:
        def __init__(self, db_context, logger):
            pass

    class BarMockRepository:
        def __init__(self, db_context, logger):
            pass

    class MockClient(clients.BaseClient):
        @classmethod
        def from_configuration(cls):
            pass
        @staticmethod
        def _do_verify_credentials(self, username, password, scope):
            pass

    my_repositories = {'foo_mock_repository': FooMockRepository,
                       'bar_mock_repository': BarMockRepository}
    client = MockClient(repositories=my_repositories,
                        db_context=None,
                        logger=None)

    for name, class_ in my_repositories.items():
        assert_true(hasattr(client, '_' + name))
        assert_is_instance(getattr(client, '_' + name), class_)


def test_parse_authorization_header():

    credentials = ('foo', 'bar')
    encoded = base64.b64encode(':'.join(credentials).encode('utf-8'))
    header = 'Basic ' + encoded.decode('utf-8')
    decoded = clients.BaseClient._parse_authorization_header(header)
    assert_tuple_equal(decoded, credentials)
<commit_msg>N/A: Changed to methods from functions<commit_after># -*- coding: utf-8 -*-

import base64

from nose.tools import assert_is_instance, assert_true, assert_tuple_equal

from tuxedo_mask import clients


class TestBaseClient:

    @staticmethod
    def test_has_repository_attributes():
        class FooMockRepository:
            def __init__(self, db_context, logger):
                pass

        class BarMockRepository:
            def __init__(self, db_context, logger):
                pass

        class MockClient(clients.BaseClient):
            @classmethod
            def from_configuration(cls):
                pass
            @staticmethod
            def _do_verify_credentials(self, username, password, scope):
                pass

        my_repositories = {'foo_mock_repository': FooMockRepository,
                           'bar_mock_repository': BarMockRepository}
        client = MockClient(repositories=my_repositories,
                            db_context=None,
                            logger=None)

        for name, class_ in my_repositories.items():
            assert_true(hasattr(client, '_' + name))
            assert_is_instance(getattr(client, '_' + name), class_)

    @staticmethod
    def test_parse_authorization_header():
        credentials = ('foo', 'bar')
        encoded = base64.b64encode(':'.join(credentials).encode('utf-8'))
        header = 'Basic ' + encoded.decode('utf-8')
        decoded = clients.BaseClient._parse_authorization_header(header)
        assert_tuple_equal(decoded, credentials)

{'fraction_non_alphanumeric': 0.09035117627003068, 'fraction_numerical': 0.006137061029662462, 'mean_word_length': 2.5650060753341433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '519880', 'n_tokens_mistral': 822, 'n_tokens_neox': 783, 'n_words': 163}