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

from __future__ import absolute_import

import json
from collections import OrderedDict
from datetime import datetime
from typing import Any, Dict, Optional

from flask import Response
from mock import Mock, patch

from eduid_common.api.testing import EduidAPITestCase
from eduid_userdb.locked_identity import LockedIdentityNin
from eduid_userdb.nin import Nin

from eduid_webapp.letter_proofing.app import init_letter_proofing_app
from eduid_webapp.letter_proofing.helpers import LetterMsg
from eduid_webapp.letter_proofing.settings.common import LetterProofingConfig

__author__ = 'lundberg'


class LetterProofingTests(EduidAPITestCase):
    """Base TestCase for those tests that need a full environment setup"""

    def setUp(self):
        self.test_user_eppn = 'hubba-baar'
        self.test_user_nin = '200001023456'
        self.test_user_wrong_nin = '190001021234'
        self.mock_address = OrderedDict(
            [
                (
                    u'Name',
                    OrderedDict(
                        [(u'GivenNameMarking', u'20'), (u'GivenName', u'Testaren Test'), (u'Surname', u'Testsson')]
                    ),
                ),
                (
                    u'OfficialAddress',
                    OrderedDict(
                        [(u'Address2', u'\xd6RGATAN 79 LGH 10'), (u'PostalCode', u'12345'), (u'City', u'LANDET')]
                    ),
                ),
            ]
        )
        super(LetterProofingTests, self).setUp(users=['hubba-baar'])

    @staticmethod
    def mock_response(status_code=200, content=None, json_data=None, headers=dict(), raise_for_status=None):
        """
        since we typically test a bunch of different
        requests calls for a service, we are going to do
        a lot of mock responses, so its usually a good idea
        to have a helper function that builds these things
        """
        mock_resp = Mock()
        # mock raise_for_status call w/optional error
        mock_resp.raise_for_status = Mock()
        if raise_for_status:
            mock_resp.raise_for_status.side_effect = raise_for_status
        # set status code and content
        mock_resp.status_code = status_code
        mock_resp.content = content
        # set headers
        mock_resp.headers = headers
        # add json data if provided
        if json_data:
            mock_resp.json = Mock(return_value=json_data)
        return mock_resp

    def load_app(self, config):
        """
        Called from the parent class, so we can provide the appropriate flask
        app for this test case.
        """
        return init_letter_proofing_app('testing', config)

    def update_config(self, app_config):
        app_config.update(
            {
                # 'ekopost_debug_pdf': devnull,
                'ekopost_api_uri': 'http://localhost',
                'ekopost_api_user': 'ekopost_user',
                'ekopost_api_pw': 'secret',
                'letter_wait_time_hours': 336,
                'msg_broker_url': 'amqp://dummy',<commit_msg>mock_response: fix mutable default value<commit_after># -*- coding: utf-8 -*-

from __future__ import absolute_import

import json
from collections import OrderedDict
from datetime import datetime
from typing import Any, Dict, Optional

from flask import Response
from mock import Mock, patch

from eduid_common.api.testing import EduidAPITestCase
from eduid_userdb.locked_identity import LockedIdentityNin
from eduid_userdb.nin import Nin

from eduid_webapp.letter_proofing.app import init_letter_proofing_app
from eduid_webapp.letter_proofing.helpers import LetterMsg
from eduid_webapp.letter_proofing.settings.common import LetterProofingConfig

__author__ = 'lundberg'


class LetterProofingTests(EduidAPITestCase):
    """Base TestCase for those tests that need a full environment setup"""

    def setUp(self):
        self.test_user_eppn = 'hubba-baar'
        self.test_user_nin = '200001023456'
        self.test_user_wrong_nin = '190001021234'
        self.mock_address = OrderedDict(
            [
                (
                    u'Name',
                    OrderedDict(
                        [(u'GivenNameMarking', u'20'), (u'GivenName', u'<NAME>'), (u'Surname', u'Testsson')]
                    ),
                ),
                (
                    u'OfficialAddress',
                    OrderedDict(
                        [(u'Address2', u'\xd6RGATAN 79 LGH 10'), (u'PostalCode', u'12345'), (u'City', u'LANDET')]
                    ),
                ),
            ]
        )
        super(LetterProofingTests, self).setUp(users=['hubba-baar'])

    @staticmethod
    def mock_response(status_code=200, content=None, json_data=None, headers=None, raise_for_status=None):
        """
        since we typically test a bunch of different
        requests calls for a service, we are going to do
        a lot of mock responses, so its usually a good idea
        to have a helper function that builds these things
        """
        if headers is None:
            headers = {}
        mock_resp = Mock()
        # mock raise_for_status call w/optional error
        mock_resp.raise_for_status = Mock()
        if raise_for_status:
            mock_resp.raise_for_status.side_effect = raise_for_status
        # set status code and content
        mock_resp.status_code = status_code
        mock_resp.content = content
        # set headers
        mock_resp.headers = headers
        # add json data if provided
        if json_data:
            mock_resp.json = Mock(return_value=json_data)
        return mock_resp

    def load_app(self, config):
        """
        Called from the parent class, so we can provide the appropriate flask
        app for this test case.
        """
        return init_letter_proofing_app('testing', config)

    def update_config(self, app_config):
        app_config.update(
            {
                # 'ekopost_debug_pdf': devnull,
                'ekopost_api_uri': 'http://localhost',
                'ekopost_api_user': 'ekopost_user',
                'ekopost_api_pw': '<PASSWORD>',
                'letter_wait_time_hours': 336,
                'msg_broker_url': 'amqp://dummy',
{'fraction_non_alphanumeric': 0.08275972466784057, 'fraction_numerical': 0.014086761645589883, 'mean_word_length': 2.209039548022599, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4734174', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1752, 'n_words': 455}