<commit_before>from __future__ import unicode_literals

import logging
from mock import patch
from django.test import TestCase

from .. import wp_api


class WPAPITestGet(TestCase):

    def setUp(self):
        logging.getLogger('wordpress.wp_api').addHandler(logging.NullHandler())

    @patch("requests.get")
    def test_get__basic(self, RequestsGetMock):
        wp_api.get("test")
        RequestsGetMock.assert_called_once_with(wp_api.api_base_url + "test",
                                                headers=None,
                                                params=None)
        self.assertFalse(wp_api.public_api_warnings)

    @patch("requests.get")
    def test_get__params(self, RequestsGetMock):
        wp_api.get("test", params={"x": 1})
        RequestsGetMock.assert_called_once_with(wp_api.api_base_url + "test",
                                                headers=None,
                                                params={"x": 1})
        self.assertFalse(wp_api.public_api_warnings)

    @patch("requests.get")
    def test_get__token(self, RequestsGetMock):
        with self.settings(WP_API_AUTH_TOKEN="<KEY>"):
            wp_api.get("test")
            RequestsGetMock.assert_called_once_with(wp_api.api_base_url + "test",
                                                    headers={"Authorization": "Bearer <KEY>"},
                                                    params=None)
            self.assertFalse(wp_api.public_api_warnings)

    @patch("requests.get")
    def test_get__params_token(self, RequestsGetMock):
        with self.settings(WP_API_AUTH_TOKEN="<KEY>"):
            wp_api.get("test", params={"x": 1})
            RequestsGetMock.assert_called_once_with(wp_api.api_base_url + "test",
                                                    headers={"Authorization": "Bearer <KEY>"},
                                                    params={"x": 1})
            self.assertFalse(wp_api.public_api_warnings)<commit_msg>more tests<commit_after>from __future__ import unicode_literals

import logging
from mock import patch, call, DEFAULT
from django.test import TestCase

from .. import wp_api


class WPAPIGetTest(TestCase):

    def setUp(self):
        logging.getLogger('wordpress.wp_api').addHandler(logging.NullHandler())

    @patch("requests.get")
    def test_get__basic(self, RequestsGetMock):
        wp_api.get("test")
        RequestsGetMock.assert_called_once_with(wp_api.api_base_url + "test",
                                                headers=None,
                                                params=None)
        self.assertFalse(wp_api.public_api_warnings)

    @patch("requests.get")
    def test_get__params(self, RequestsGetMock):
        wp_api.get("test", params={"x": 1})
        RequestsGetMock.assert_called_once_with(wp_api.api_base_url + "test",
                                                headers=None,
                                                params={"x": 1})
        self.assertFalse(wp_api.public_api_warnings)

    @patch("requests.get")
    def test_get__token(self, RequestsGetMock):
        with self.settings(WP_API_AUTH_TOKEN="<KEY>"):
            wp_api.get("test")
            RequestsGetMock.assert_called_once_with(wp_api.api_base_url + "test",
                                                    headers={"Authorization": "Bearer <KEY>"},
                                                    params=None)
            self.assertFalse(wp_api.public_api_warnings)

    @patch("requests.get")
    def test_get__params_token(self, RequestsGetMock):
        with self.settings(WP_API_AUTH_TOKEN="<KEY>"):
            wp_api.get("test", params={"x": 1})
            RequestsGetMock.assert_called_once_with(wp_api.api_base_url + "test",
                                                    headers={"Authorization": "Bearer <KEY>"},
                                                    params={"x": 1})
            self.assertFalse(wp_api.public_api_warnings)


class WPAPILoadTest(TestCase):

    @patch.multiple('wordpress.wp_api', load_categories=DEFAULT, load_tags=DEFAULT, load_authors=DEFAULT, load_media=DEFAULT, get_ref_data_map=DEFAULT, load_posts=DEFAULT)
    def test_load_wp_api(self, load_categories, load_tags, load_authors, load_media, get_ref_data_map, load_posts):

        get_ref_data_map.return_value = {"test": "map"}

        wp_api.load_wp_api(123)

        load_categories.assert_called_once_with(123, purge_first=False, full=False)
        load_tags.assert_called_once_with(123, purge_first=False, full=False)
        load_authors.assert_called_once_with(123, purge_first=False, full=False)
        load_media.assert_called_once_with(123, purge_first=False, full=False, modified_after=None)
        get_ref_data_map.assert_called_once_with(123)

        calls = []
        for post_type in ["attachment", "post", "page"]:
            calls.append(call(123, {"test": "map"}, purge_first=False, full=False, modified_after=None, post_type=post_type))

        load_posts.assert_has_calls(calls)
{'fraction_non_alphanumeric': 0.10415424368912742, 'fraction_numerical': 0.005764261578215067, 'mean_word_length': 2.1848101265822786, 'pattern_counts': {'":': 14, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3721356', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1405, 'n_words': 204}