<commit_before>import codecs
import unittest

import mock
import responses

import util

from lib import swa


@mock.patch('lib.swa.requests')
class TestRequest(unittest.TestCase):
    def test_make_request_get(self, mock_requests):
        expected_headers = {
            "User-Agent": "Southwest/4.9.1 CFNetwork/887 Darwin/17.0.0",
            "Content-Type": "application/vnd.swacorp.com.mobile.boarding-passes-v1.0+json",
            "X-Api-Key": codecs.decode("<KEY>", "rot13"),
            "Accept-Language": "en-US;q=1"
        }
        expected_url = "https://api-extensions.southwest.com/v1/mobile/foo/123456/bar"
        fake_data = {}

        _ = swa._make_request(  # NOQA
            "/foo/123456/bar",
            fake_data,
            method='get',
            content_type="application/vnd.swacorp.com.mobile.boarding-passes-v1.0+json"
        )

        mock_requests.get.assert_called_with(expected_url, params=fake_data, headers=expected_headers, verify=False)

    def test_make_request_post(self, mock_requests):
        expected_headers = {
            "User-Agent": "Southwest/4.9.1 CFNetwork/887 Darwin/17.0.0",
            "Content-Type": "application/vnd.swacorp.com.mobile.boarding-passes-v1.0+json",
            "X-Api-Key": codecs.decode("<KEY>", "rot13"),
            "Accept-Language": "en-US;q=1"
        }
        expected_url = "https://api-extensions.southwest.com/v1/mobile/foo/123456/bar"
        fake_data = {}

        _ = swa._make_request(  # NOQA
            "/foo/123456/bar",
            fake_data,
            content_type="application/vnd.swacorp.com.mobile.boarding-passes-v1.0+json"
        )

        mock_requests.post.assert_called_with(expected_url, json=fake_data, headers=expected_headers, verify=False)

    def test_make_request_invalid_method(self, mock_requests):
        with self.assertRaises(AssertionError):
            swa._make_request("/foo/123456/bar", {}, "application/json", method="foo")


class TestCheckIn(unittest.TestCase):

    def setUp(self):
        self.names = [{<commit_msg>DRY: Use swa.API_KEY in tests<commit_after>import unittest

import mock
import responses

import util

from lib import swa


@mock.patch('lib.swa.requests')
class TestRequest(unittest.TestCase):
    def test_make_request_get(self, mock_requests):
        expected_headers = {
            "User-Agent": "Southwest/4.9.1 CFNetwork/887 Darwin/17.0.0",
            "Content-Type": "application/vnd.swacorp.com.mobile.boarding-passes-v1.0+json",
            "X-Api-Key": swa.API_KEY,
            "Accept-Language": "en-US;q=1"
        }
        expected_url = "https://api-extensions.southwest.com/v1/mobile/foo/123456/bar"
        fake_data = {}

        _ = swa._make_request(  # NOQA
            "/foo/123456/bar",
            fake_data,
            method='get',
            content_type="application/vnd.swacorp.com.mobile.boarding-passes-v1.0+json"
        )

        mock_requests.get.assert_called_with(expected_url, params=fake_data, headers=expected_headers, verify=False)

    def test_make_request_post(self, mock_requests):
        expected_headers = {
            "User-Agent": "Southwest/4.9.1 CFNetwork/887 Darwin/17.0.0",
            "Content-Type": "application/vnd.swacorp.com.mobile.boarding-passes-v1.0+json",
            "X-Api-Key": swa.API_KEY,
            "Accept-Language": "en-US;q=1"
        }
        expected_url = "https://api-extensions.southwest.com/v1/mobile/foo/123456/bar"
        fake_data = {}

        _ = swa._make_request(  # NOQA
            "/foo/123456/bar",
            fake_data,
            content_type="application/vnd.swacorp.com.mobile.boarding-passes-v1.0+json"
        )

        mock_requests.post.assert_called_with(expected_url, json=fake_data, headers=expected_headers, verify=False)

    def test_make_request_invalid_method(self, mock_requests):
        with self.assertRaises(AssertionError):
            swa._make_request("/foo/123456/bar", {}, "application/json", method="foo")


class TestCheckIn(unittest.TestCase):

    def setUp(self):
        self.names = [{
{'fraction_non_alphanumeric': 0.1348700343305542, 'fraction_numerical': 0.03138793526238352, 'mean_word_length': 2.6161347517730498, 'pattern_counts': {'":': 16, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '6056153', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1327, 'n_words': 170}