Exemplo n.º 1
0
 def __init__(self, assert_all_requests_are_fired=False):
     super(GitHubRequestsMock, self).__init__(
         assert_all_requests_are_fired=assert_all_requests_are_fired)
     self._response_map = {
         input_file('zero.md'): {
             'markdown': output_file('raw', 'zero.html'),
             'user-content': output_file('raw', 'zero-user-content.html'),
             'user-context': output_file('raw', 'zero-user-context.html'),
         },
         input_file('simple.md'): {
             'markdown': output_file('raw', 'simple.html'),
             'user-content': output_file('raw', 'simple-user-content.html'),
             'user-context': output_file('raw', 'simple-user-context.html'),
         },
         input_file('gfm-test.md'): {
             'markdown': output_file('raw', 'gfm-test.html'),
             'user-content': output_file(
                 'raw', 'gfm-test-user-content.html'),
             'user-context': output_file(
                 'raw', 'gfm-test-user-context.html'),
         },
     }
     self.add_callback(
         responses.POST, '{0}/markdown'.format(DEFAULT_API_URL),
         callback=self._markdown_request)
     self.add_callback(
         responses.POST, '{0}/markdown/raw'.format(DEFAULT_API_URL),
         callback=self._markdown_raw_request)
Exemplo n.º 2
0
def test_github_renderer():
    simple_input = input_file('simple.md')
    gfm_test_input = input_file('gfm-test.md')

    with GitHubRequestsMock() as responses:
        assert (GitHubRenderer().render(simple_input) ==
                output_file('renderer', 'simple.html'))
        assert (GitHubRenderer(True).render(simple_input) ==
                output_file('renderer', 'simple-user-content.html'))
        assert (GitHubRenderer(True).render(simple_input) ==
                output_file('renderer', 'simple-user-context.html'))
        assert len(responses.calls) == 3

    assert (output_file('renderer', 'gfm-test-user-content.html') !=
            output_file('renderer', 'gfm-test-user-context.html'))

    with GitHubRequestsMock() as responses:
        assert (GitHubRenderer().render(gfm_test_input) ==
                output_file('renderer', 'gfm-test.html'))
        assert (GitHubRenderer(True).render(gfm_test_input) ==
                output_file('renderer', 'gfm-test-user-content.html'))
        assert (GitHubRenderer(True, USER_CONTEXT).render(gfm_test_input) ==
                output_file('renderer', 'gfm-test-user-context.html'))
        assert len(responses.calls) == 3

    with GitHubRequestsMock() as responses:
        assert (
            GitHubRenderer().render(simple_input, GitHubRequestsMock.auth) ==
            output_file('renderer', 'simple.html'))
        with pytest.raises(HTTPError):
            GitHubRenderer().render(simple_input, GitHubRequestsMock.bad_auth)
        assert len(responses.calls) == 2
Exemplo n.º 3
0
def test_github_renderer():
    simple_input = input_file('simple.md')
    gfm_test_input = input_file('gfm-test.md')

    with GitHubRequestsMock() as responses:
        assert (GitHubRenderer().render(simple_input) == output_file(
            'renderer', 'simple.html'))
        assert (GitHubRenderer(True).render(simple_input) == output_file(
            'renderer', 'simple-user-content.html'))
        assert (GitHubRenderer(True).render(simple_input) == output_file(
            'renderer', 'simple-user-context.html'))
        assert len(responses.calls) == 3

    assert (output_file('renderer', 'gfm-test-user-content.html') !=
            output_file('renderer', 'gfm-test-user-context.html'))

    with GitHubRequestsMock() as responses:
        assert (GitHubRenderer().render(gfm_test_input) == output_file(
            'renderer', 'gfm-test.html'))
        assert (GitHubRenderer(True).render(gfm_test_input) == output_file(
            'renderer', 'gfm-test-user-content.html'))
        assert (GitHubRenderer(
            True, USER_CONTEXT).render(gfm_test_input) == output_file(
                'renderer', 'gfm-test-user-context.html'))
        assert len(responses.calls) == 3

    with GitHubRequestsMock() as responses:
        assert (GitHubRenderer().render(
            simple_input,
            GitHubRequestsMock.auth) == output_file('renderer', 'simple.html'))
        with pytest.raises(HTTPError):
            GitHubRenderer().render(simple_input, GitHubRequestsMock.bad_auth)
        assert len(responses.calls) == 2
Exemplo n.º 4
0
 def __init__(self, assert_all_requests_are_fired=False):
     super(GitHubRequestsMock, self).__init__(
         assert_all_requests_are_fired=assert_all_requests_are_fired)
     self._response_map = {
         input_file('zero.md'): {
             'markdown': output_file('raw', 'zero.html'),
             'user-content': output_file('raw', 'zero-user-content.html'),
             'user-context': output_file('raw', 'zero-user-context.html'),
         },
         input_file('simple.md'): {
             'markdown': output_file('raw', 'simple.html'),
             'user-content': output_file('raw', 'simple-user-content.html'),
             'user-context': output_file('raw', 'simple-user-context.html'),
         },
         input_file('gfm-test.md'): {
             'markdown': output_file('raw', 'gfm-test.html'),
             'user-content': output_file('raw',
                                         'gfm-test-user-content.html'),
             'user-context': output_file('raw',
                                         'gfm-test-user-context.html'),
         },
     }
     self.add_callback(responses.POST,
                       '{0}/markdown'.format(DEFAULT_API_URL),
                       callback=self._markdown_request)
     self.add_callback(responses.POST,
                       '{0}/markdown/raw'.format(DEFAULT_API_URL),
                       callback=self._markdown_raw_request)
Exemplo n.º 5
0
def test_app(monkeypatch, tmpdir):
    monkeypatch.setenv('GRIPHOME', str(tmpdir))
    zero_path = input_filename('zero.md')
    zero_output = output_file('app', 'zero.html')
    gfm_test_path = input_filename('gfm-test.md')
    gfm_test_output = output_file('app', 'gfm-test.html')
    assets = GitHubAssetManagerMock()

    with GitHubRequestsMock() as responses:
        assert Grip(zero_path, assets=assets).render() == zero_output
        assert Grip(zero_path, assets=assets).render('/') == zero_output
        assert Grip(zero_path, assets=assets).render('/x/../') == zero_output
        with Grip(zero_path, assets=assets).test_client() as client:
            assert client.get('/').data.decode('utf-8') == zero_output
        assert len(responses.calls) == 4

    with GitHubRequestsMock() as responses:
        app = Grip(gfm_test_path, assets=assets)
        assert app.render() == gfm_test_output
        assert app.render('/') == gfm_test_output
        assert len(responses.calls) == 2
Exemplo n.º 6
0
def test_app(monkeypatch, tmpdir):
    monkeypatch.setenv('GRIPHOME', str(tmpdir))
    zero_path = input_filename('zero.md')
    zero_output = output_file('app', 'zero.html')
    gfm_test_path = input_filename('gfm-test.md')
    gfm_test_output = output_file('app', 'gfm-test.html')
    assets = GitHubAssetManagerMock()

    with GitHubRequestsMock() as responses:
        assert Grip(zero_path, assets=assets).render() == zero_output
        assert Grip(zero_path, assets=assets).render('/') == zero_output
        assert Grip(zero_path, assets=assets).render('/x/../') == zero_output
        with Grip(zero_path, assets=assets).test_client() as client:
            assert client.get('/').data.decode('utf-8') == zero_output
        assert len(responses.calls) == 4

    with GitHubRequestsMock() as responses:
        app = Grip(gfm_test_path, assets=assets)
        assert app.render() == gfm_test_output
        assert app.render('/') == gfm_test_output
        assert len(responses.calls) == 2
Exemplo n.º 7
0
def output_user_context():
    return output_file('raw', 'gfm-test-user-context.html')
Exemplo n.º 8
0
def output_readme():
    return output_file('raw', 'gfm-test.html')
Exemplo n.º 9
0
def output_user_context():
    return output_file("raw", "gfm-test-user-context.html")
Exemplo n.º 10
0
def output_readme():
    return output_file("raw", "gfm-test.html")
Exemplo n.º 11
0
def output_user_context():
    return output_file('raw', 'gfm-test-user-context.html')
Exemplo n.º 12
0
def output_readme():
    return output_file('raw', 'gfm-test.html')