<commit_before>from gittip.testing import tip_graph, serve_request, DUMMY_GITHUB_JSON
from gittip.elsewhere import github

from mock import patch
from nose.tools import assert_equal


def test_github_resolve_resolves():
    with tip_graph(('alice', 'bob', 1)):
        expected = 'alice'
        actual = github.resolve(u'alice')
        assert actual == expected, actual


@patch('gittip.elsewhere.github.requests')
def test_github_user_info_status_handling(requests):
    # Check that different possible github statuses are handled correctly
    for (github_status, github_content), expected_gittip_response in [
            ((200, DUMMY_GITHUB_JSON), 200),
            ((404, ""), 404),
            ((500, ""), 502),
            ((777, ""), 502)]:

        requests.get().status_code = github_status
        requests.get().text = github_content
        response = serve_request('/on/github/not-in-the-db/')
        assert_equal(response.code, expected_gittip_response)<commit_msg>Convert tests/test_elsewhere_github.py to use Harness & TestClient.<commit_after>from mock import patch
from nose.tools import assert_equal

from gittip.elsewhere import github
from gittip.models import Elsewhere
from gittip.testing import Harness, DUMMY_GITHUB_JSON
from gittip.testing.client import TestClient


class TestElsewhereGithub(Harness):
    def test_github_resolve_resolves_correctly(self):
        alice = self.make_participant('alice')
        alice_on_github = Elsewhere(platform='github', user_id="1",
                                    user_info={'login': 'alice'})
        alice.accounts_elsewhere.append(alice_on_github)
        self.session.commit()

        expected = 'alice'
        actual = github.resolve(u'alice')
        assert actual == expected, actual

    @patch('gittip.elsewhere.github.requests')
    def test_github_user_info_status_handling(self, requests):
        client = TestClient()
        # Check that different possible github statuses are handled correctly
        for (github_status, github_content), expected_gittip_response in [
                ((200, DUMMY_GITHUB_JSON), 200),
                ((404, ""), 404),
                ((500, ""), 502),
                ((777, ""), 502)]:

            requests.get().status_code = github_status
            requests.get().text = github_content
            response = client.get('/on/github/not-in-the-db/')
            assert_equal(response.code, expected_gittip_response)
{'fraction_non_alphanumeric': 0.10629599345870809, 'fraction_numerical': 0.02044153720359771, 'mean_word_length': 3.0988274706867673, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1339480', 'n_tokens_mistral': 773, 'n_tokens_neox': 700, 'n_words': 153}