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, )
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, )
def test_correct_redirect(): assert_redirect( auto_namedtuple(response=auto_namedtuple( status_code=302, location='/foo?bar=baz', ), ), '/foo', {'bar': ['baz']}, )
def test_correct_redirect(): assert_redirect( auto_namedtuple(response=auto_namedtuple( status_code=302, location='/foo?bar=baz', )), '/foo', {'bar': ['baz']}, )
def test_redirect_custom_status_code(): assert_redirect( auto_namedtuple(response=auto_namedtuple( status_code=303, location='/foo', ), ), '/foo', {}, redirect_status_code=303, )
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']}, )
def test_redirect_wrong_path(): with pytest.raises(AssertionError): assert_redirect( auto_namedtuple(response=auto_namedtuple( status_code=302, location='/foo', )), '/bar', {}, )
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']}, )
def test_redirect_wrong_path(): with pytest.raises(AssertionError): assert_redirect( auto_namedtuple(response=auto_namedtuple( status_code=302, location='/foo', ), ), '/bar', {}, )
def test_redirect_custom_status_code(): assert_redirect( auto_namedtuple(response=auto_namedtuple( status_code=303, location='/foo', )), '/foo', {}, redirect_status_code=303, )
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)
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, )
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)
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, )
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, )
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, )
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 test_json(): response = auto_namedtuple( 'Response', data=b'{"foo": "bar"}', charset='UTF-8', ) instance = Response(response) assert instance.json == {'foo': 'bar'}
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
def test_raises_for_response_error(): with pytest.raises(AssertionError): assert_no_response_errors( auto_namedtuple(response=auto_namedtuple(status_code=201)), )
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=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=b'{"foo": "bar"}', charset='UTF-8', ) instance = Response(response) assert instance.json == {'foo': 'bar'}
def test_raises_for_response_error(): with pytest.raises(AssertionError): assert_no_response_errors( auto_namedtuple(response=auto_namedtuple(status_code=201)), )
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'}
def test_ok_for_200(): assert_no_response_errors( auto_namedtuple(response=auto_namedtuple(status_code=200)), )
def test_ok_for_200(): assert_no_response_errors( auto_namedtuple(response=auto_namedtuple(status_code=200)), )