Example #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,
        )
Example #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,
        )
Example #3
0
def test_correct_redirect():
    assert_redirect(
        auto_namedtuple(response=auto_namedtuple(
            status_code=302,
            location='/foo?bar=baz',
        ), ),
        '/foo',
        {'bar': ['baz']},
    )
Example #4
0
def test_correct_redirect():
    assert_redirect(
        auto_namedtuple(response=auto_namedtuple(
            status_code=302,
            location='/foo?bar=baz',
        )),
        '/foo',
        {'bar': ['baz']},
    )
Example #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,
    )
Example #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']},
        )
Example #7
0
def test_redirect_wrong_path():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(
                status_code=302,
                location='/foo',
            )),
            '/bar',
            {},
        )
Example #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']},
        )
Example #9
0
def test_redirect_wrong_path():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(
                status_code=302,
                location='/foo',
            ), ),
            '/bar',
            {},
        )
Example #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,
    )
Example #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)
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)
Example #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,
    )
Example #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)
Example #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,
        )
Example #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,
        )
Example #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,
        )
Example #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)
Example #19
0
def test_json():
    response = auto_namedtuple(
        'Response',
        data=b'{"foo": "bar"}',
        charset='UTF-8',
    )
    instance = Response(response)
    assert instance.json == {'foo': 'bar'}
Example #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')
def test_json():
    response = auto_namedtuple('Response', data='{"foo": "bar"}')
    instance = Response(response)
    assert instance.json == {'foo': 'bar'}
def test_pq():
    response = auto_namedtuple('Response', data='<p>Oh hai!</p>')
    instance = Response(response)
    assert instance.pq.__html__() == response.data
Example #23
0
def test_raises_for_response_error():
    with pytest.raises(AssertionError):
        assert_no_response_errors(
            auto_namedtuple(response=auto_namedtuple(status_code=201)), )
Example #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,
    )
Example #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')
Example #26
0
def test_json():
    response = auto_namedtuple(
        'Response', data=b'{"foo": "bar"}', charset='UTF-8',
    )
    instance = Response(response)
    assert instance.json == {'foo': 'bar'}
Example #27
0
def test_raises_for_response_error():
    with pytest.raises(AssertionError):
        assert_no_response_errors(
            auto_namedtuple(response=auto_namedtuple(status_code=201)),
        )
Example #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'}
Example #31
0
def test_ok_for_200():
    assert_no_response_errors(
        auto_namedtuple(response=auto_namedtuple(status_code=200)),
    )
Example #32
0
def test_ok_for_200():
    assert_no_response_errors(
        auto_namedtuple(response=auto_namedtuple(status_code=200)), )