Ejemplo n.º 1
0
def test_redirect_not_a_redirect():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(status_code=200)),
            mock.sentinel.expected_path,
            mock.sentinel.expected_query,
        )
Ejemplo n.º 2
0
def test_redirect_not_a_redirect():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(status_code=200)),
            mock.sentinel.expected_path,
            mock.sentinel.expected_query,
        )
Ejemplo n.º 3
0
def test_correct_redirect():
    assert_redirect(
        auto_namedtuple(response=auto_namedtuple(
            status_code=302,
            location='/foo?bar=baz',
        ), ),
        '/foo',
        {'bar': ['baz']},
    )
Ejemplo n.º 4
0
def test_correct_redirect():
    assert_redirect(
        auto_namedtuple(response=auto_namedtuple(
            status_code=302,
            location='/foo?bar=baz',
        )),
        '/foo',
        {'bar': ['baz']},
    )
Ejemplo n.º 5
0
def test_redirect_custom_status_code():
    assert_redirect(
        auto_namedtuple(response=auto_namedtuple(
            status_code=303,
            location='/foo',
        ), ),
        '/foo',
        {},
        redirect_status_code=303,
    )
Ejemplo n.º 6
0
def test_redirect_wrong_query():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(
                status_code=302,
                location='/foo?bar=baz',
            ), ),
            '/foo',
            {'bar': ['biz']},
        )
Ejemplo n.º 7
0
def test_redirect_wrong_path():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(
                status_code=302,
                location='/foo',
            )),
            '/bar',
            {},
        )
Ejemplo n.º 8
0
def test_redirect_wrong_query():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(
                status_code=302,
                location='/foo?bar=baz',
            )),
            '/foo',
            {'bar': ['biz']},
        )
Ejemplo n.º 9
0
def test_redirect_wrong_path():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(
                status_code=302,
                location='/foo',
            ), ),
            '/bar',
            {},
        )
Ejemplo n.º 10
0
def test_redirect_custom_status_code():
    assert_redirect(
        auto_namedtuple(response=auto_namedtuple(
            status_code=303,
            location='/foo',
        )),
        '/foo',
        {},
        redirect_status_code=303,
    )
Ejemplo n.º 11
0
def cloneable_with_commits(cloneable):
    commits = []

    def append_commit():
        output = cmd_output("git", "show", COMMIT_FORMAT)
        sha, date = output.splitlines()[:2]
        commits.append(Commit(sha, int(date)))

    def make_commit(filename, contents):
        # Make the graph tests more deterministic
        # import time; time.sleep(2)
        with io.open(filename, "w") as file_obj:
            file_obj.write(contents)

        subprocess.check_call(["git", "add", filename])
        subprocess.check_call(["git", "commit", "-m", "Add {0}".format(filename)])
        append_commit()

    with cwd(cloneable):
        # Append a commit for the inital commit
        append_commit()
        make_commit("bar.py", "")
        make_commit("baz.py", "")
        make_commit("test.py", "import foo\nimport bar\n")
        make_commit("foo.tmpl", "#import foo\n#import bar\n")

    yield auto_namedtuple(path=cloneable, commits=commits)
Ejemplo n.º 12
0
def cloneable_with_commits(cloneable):
    commits = []

    def append_commit():
        output = cmd_output('git', 'show', COMMIT_FORMAT)
        sha, date = output.splitlines()[:2]
        commits.append(Commit(sha, int(date)))

    def make_commit(filename, contents):
        # Make the graph tests more deterministic
        # import time; time.sleep(2)
        with io.open(filename, 'w') as file_obj:
            file_obj.write(contents)

        subprocess.check_call(['git', 'add', filename])
        subprocess.check_call([
            'git',
            'commit',
            '-m',
            'Add {0}'.format(filename),
        ])
        append_commit()

    with cwd(cloneable):
        # Append a commit for the inital commit
        append_commit()
        make_commit('bar.py', '')
        make_commit('baz.py', '')
        make_commit('test.py', 'import foo\nimport bar\n')
        make_commit('foo.tmpl', '#import foo\n#import bar\n')

    yield auto_namedtuple(path=cloneable, commits=commits)
Ejemplo n.º 13
0
def server_with_data(server, cloneable_with_commits):
    cfg = server.sandbox.gen_config(repo=cloneable_with_commits.path)
    main(('-C', cfg))
    yield auto_namedtuple(
        server=server,
        cloneable_with_commits=cloneable_with_commits,
    )
Ejemplo n.º 14
0
def hg_cloneable_with_commits(hg_cloneable):
    commits = []

    def append_commit():
        output = cmd_output(
            'hg',
            'log',
            '--template={node}\n{word(0, date, \".\")}\n',
            '--rev',
            '.',
        )
        sha, date = output.splitlines()[:2]
        commits.append(Commit(sha, int(date)))

    def make_commit(filename, contents):
        with open(filename, 'w') as file_obj:
            file_obj.write(contents)

        subprocess.check_call(('hg', 'add', filename))
        subprocess.check_call(('hg', 'ci', '-m', f'Add {filename}'))
        append_commit()

    with cwd(hg_cloneable):
        append_commit()
        make_commit('bar.py', '')
        make_commit('baz.py', '')
        make_commit('test.py', 'import foo\nimport bar\n')
        make_commit('foo.tmpl', '#import foo\n#import bar\n')

    yield auto_namedtuple(path=hg_cloneable, commits=commits)
Ejemplo n.º 15
0
def checked_out_repo(cloneable_with_commits):
    parser = git_repo_parser.GitRepoParser(cloneable_with_commits.path)
    with parser.repo_checked_out():
        yield auto_namedtuple(
            repo_parser=parser,
            cloneable_with_commits=cloneable_with_commits,
        )
Ejemplo n.º 16
0
def checked_out_repo(cloneable_with_commits):
    parser = repo_parser.RepoParser(cloneable_with_commits.path)
    with parser.repo_checked_out():
        yield auto_namedtuple(
            repo_parser=parser,
            cloneable_with_commits=cloneable_with_commits,
        )
Ejemplo n.º 17
0
def checked_out_repo(hg_cloneable_with_commits):
    parser = hg_repo_parser.HgRepoParser(hg_cloneable_with_commits.path)
    with parser.repo_checked_out():
        yield auto_namedtuple(
            repo_parser=parser,
            cloneable_with_commits=hg_cloneable_with_commits,
        )
Ejemplo n.º 18
0
def cloneable_with_commits(cloneable):
    commits = []

    def append_commit():
        output = cmd_output('git', 'show', COMMIT_FORMAT)
        sha, date = output.splitlines()[:2]
        commits.append(Commit(sha, int(date)))

    def make_commit(filename, contents):
        # Make the graph tests more deterministic
        # import time; time.sleep(2)
        with io.open(filename, 'w') as file_obj:
            file_obj.write(contents)

        subprocess.check_call(('git', 'add', filename))
        subprocess.check_call((
            'git', 'commit', '-m', 'Add {0}'.format(filename),
        ))
        append_commit()

    with cwd(cloneable):
        # Append a commit for the inital commit
        append_commit()
        make_commit('bar.py', '')
        make_commit('baz.py', '')
        make_commit('test.py', 'import foo\nimport bar\n')
        make_commit('foo.tmpl', '#import foo\n#import bar\n')

    yield auto_namedtuple(path=cloneable, commits=commits)
Ejemplo n.º 19
0
def test_json():
    response = auto_namedtuple(
        'Response',
        data=b'{"foo": "bar"}',
        charset='UTF-8',
    )
    instance = Response(response)
    assert instance.json == {'foo': 'bar'}
Ejemplo n.º 20
0
def test_pq():
    response = auto_namedtuple(
        'Response',
        data=b'<p>Oh hai!</p>',
        charset='UTF-8',
    )
    instance = Response(response)
    assert instance.pq.__html__() == response.data.decode('UTF-8')
Ejemplo n.º 21
0
def test_json():
    response = auto_namedtuple('Response', data='{"foo": "bar"}')
    instance = Response(response)
    assert instance.json == {'foo': 'bar'}
Ejemplo n.º 22
0
def test_pq():
    response = auto_namedtuple('Response', data='<p>Oh hai!</p>')
    instance = Response(response)
    assert instance.pq.__html__() == response.data
Ejemplo n.º 23
0
def test_raises_for_response_error():
    with pytest.raises(AssertionError):
        assert_no_response_errors(
            auto_namedtuple(response=auto_namedtuple(status_code=201)), )
Ejemplo n.º 24
0
def server_with_data(server, cloneable_with_commits):
    main([cloneable_with_commits.path, server.sandbox.db_path])
    yield auto_namedtuple(
        server=server,
        cloneable_with_commits=cloneable_with_commits,
    )
Ejemplo n.º 25
0
def test_pq():
    response = auto_namedtuple(
        'Response', data=b'<p>Oh hai!</p>', charset='UTF-8',
    )
    instance = Response(response)
    assert instance.pq.__html__() == response.data.decode('UTF-8')
Ejemplo n.º 26
0
def test_json():
    response = auto_namedtuple(
        'Response', data=b'{"foo": "bar"}', charset='UTF-8',
    )
    instance = Response(response)
    assert instance.json == {'foo': 'bar'}
Ejemplo n.º 27
0
def test_raises_for_response_error():
    with pytest.raises(AssertionError):
        assert_no_response_errors(
            auto_namedtuple(response=auto_namedtuple(status_code=201)),
        )
Ejemplo n.º 28
0
def server_with_data(server, cloneable_with_commits):
    main([cloneable_with_commits.path, server.sandbox.db_path])
    yield auto_namedtuple(server=server, cloneable_with_commits=cloneable_with_commits)
def test_pq():
    response = auto_namedtuple('Response', data='<p>Oh hai!</p>')
    instance = Response(response)
    assert instance.pq.__html__() == response.data
def test_json():
    response = auto_namedtuple('Response', data='{"foo": "bar"}')
    instance = Response(response)
    assert instance.json == {'foo': 'bar'}
Ejemplo n.º 31
0
def test_ok_for_200():
    assert_no_response_errors(
        auto_namedtuple(response=auto_namedtuple(status_code=200)),
    )
Ejemplo n.º 32
0
def test_ok_for_200():
    assert_no_response_errors(
        auto_namedtuple(response=auto_namedtuple(status_code=200)), )