def test_fstring_templates(): response = Namespace(JSON_DICT) runner = State(response=response) for kwargs in VALIDATION_KWARGS: validator = Validator(**kwargs) result = runner.check_validation(validator) assert result.success, "%s != %s" % (result.expect, result.actual)
def test_local_profile(local): # host assert local.host == "http://localhost:8000" # schemas assert local.schemas['v1'] == "/api/v1/schema?format=openapi" assert local.schemas['v2'] == "/api/v2/schema?format=openapi" assert local.schemas['v3'] == "/api/v3/schema?format=openapi" assert local.schemas['v4'] == "/api/v4/schema?format=openapi" # globals ns = local.globals assert Namespace.render("{language}", ns) == "Python" assert Namespace.render("{pi}", ns) == pytest.approx(3.14159) assert Namespace.render("{score}", ns) == GLOBAL_SCORE assert Namespace.render("{tokens.admin}", ns) == 'a' + '0' * 39 assert Namespace.render("{tokens.staff}", ns) == 'a' + '1' * 39 assert Namespace.render("{tokens.guest}", ns) == 'a' + '2' * 39 assert Namespace.render("{tokens.oauth}", ns) == {} # headers assert local.headers.get("Authorization") == "Token {tokens.guest}" assert local.headers.get("Content-Type") == "application/json" # other assert local.extensions == ["rigor"] assert local.includes == [] assert local.excludes == ["broken"] assert local.concurrency == 10
def test_root_profile(root): assert root.name == "__root__" assert root.file_path == os.path.join(CONFIG_DIR, "rigor.yml") assert root.host == "http://localhost:8000" # sanity check assert len(root.schemas) == 2 assert len(root.globals) == 4 assert len(root.headers) == 2 assert len(root.profiles) == 3 # schemas assert root.schemas['v1'] == "/api/v1/schema?format=openapi" assert root.schemas['v2'] == "/api/v2/schema?format=openapi" # globals ns = root.globals assert Namespace.render("{language}", ns) == "Python" assert Namespace.render("{pi}", ns) == pytest.approx(3.14159) assert Namespace.render("{score}", ns) == GLOBAL_SCORE assert Namespace.render("{tokens.admin}", ns) == 'a' + '0' * 39 assert Namespace.render("{tokens.staff}", ns) == 'a' + '1' * 39 assert Namespace.render("{tokens.guest}", ns) == 'a' + '2' * 39 assert Namespace.render("{tokens.oauth}", ns) == {} # headers assert root.headers.get("Authorization") == "Token {tokens.guest}" assert root.headers.get("Content-Type") == "application/json" # other assert root.extensions == ["rigor"] assert root.includes == [] assert root.excludes == ["broken"] assert root.concurrency == 10
def test_production_profile(production): # host assert production.host == "http://production.host.com" # schemas assert production.schemas['v1'] == "/api/v1/schema?format=openapi" assert production.schemas['v2'] == "/api/v2/schema?format=openapi" assert production.schemas.get('v3') is None assert production.schemas.get('v4') is None # globals ns = production.globals assert Namespace.render("{language}", ns) == "Python" assert Namespace.render("{pi}", ns) == pytest.approx(3.14159) assert Namespace.render("{score}", ns) == GLOBAL_SCORE assert Namespace.render("{tokens.admin}", ns) == 'None' assert Namespace.render("{tokens.staff}", ns) == 'None' assert Namespace.render("{tokens.guest}", ns) == 'None' assert Namespace.render("{tokens.oauth}", ns) == 'None' # headers assert production.headers.get("Authorization") is None assert production.headers.get("Content-Type") == "application/json" # other assert production.extensions == ["rigor"] assert production.includes == [] assert production.excludes == ["broken"] assert production.concurrency == 10
def test_test_profile(test): # host assert test.host == "http://test.host.com" # schemas assert test.schemas['v1'] == "/api/v1/schema?format=openapi" assert test.schemas['v2'] == "/api/v2/schema?format=openapi" assert test.schemas['v3'] == "/api/v3/schema?format=openapi" assert test.schemas.get('v4') is None # globals ns = test.globals assert Namespace.render("{language}", ns) == "Python" assert Namespace.render("{pi}", ns) == pytest.approx(3.14159) assert Namespace.render("{score}", ns) == GLOBAL_SCORE assert Namespace.render("{tokens.admin}", ns) == TEST_ADMIN_TOKEN assert Namespace.render("{tokens.staff}", ns) == 'a' + '1' * 39 assert Namespace.render("{tokens.guest}", ns) == 'a' + '2' * 39 assert Namespace.render("{tokens.oauth}", ns) == OAUTH_TOKEN # headers assert test.headers.get("Authorization") == "Bearer {tokens.oauth}" assert test.headers.get("Content-Type") == "application/json" # other assert test.extensions == ["rigor"] assert test.includes == [] assert test.excludes == ["broken"] assert test.concurrency == 10
def test_namespace_access(): response = Namespace(JSON_DICT) assert Namespace.render("{url}", response) == "https://httpbin.org/get" assert Namespace.render("{args}", response) == {} assert Namespace.render("{headers.Accept}", response) == "*/*" assert Namespace.render("{origin}", response) is not None assert Namespace.render("{headers.Connection}", response) == "close"
def test_namespace_render(): assert Namespace.render("000-00-0000", {}) == "000-00-0000" assert Namespace.render("22", {}) == 22 assert Namespace.render("-22.330", {}) == -22.330 assert Namespace.render_string("['1', '2', '3']", {}) == ["1", "2", "3"] assert Namespace.render_string("range(2,12)", {}) == [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ] assert Namespace.render_string("range(3)", {}) == [0, 1, 2] assert Namespace.render_string("range_inclusive(2,12)", {}) == [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ] assert Namespace.render_string("range_inclusive(3)", {}) == [0, 1, 2, 3] # test range with variable name(s) assert Namespace.render_string("range($val)", {"val": 3}) == [0, 1, 2] assert Namespace.render_string("range($val1, $val2)", { "val1": 3, "val2": 5 }) == [3, 4]
def test_hasattr(): ns = Namespace(dict(a=1)) assert hasattr(ns, "a") assert not hasattr(ns, "b")
def test_unknown_variables(): assert Namespace.render_string("{{ $unknown }}", {}) == "{ $unknown }" assert Namespace.render_string("{ $unknown }", {}) == "{ $unknown }" assert Namespace.render_string("{ unknown }", {}) == "{ unknown }" assert Namespace.render_string("{{ unknown }}", {}) == "{ unknown }"
def test_namespace_render(): assert Namespace.render("000-00-0000", {}) == "000-00-0000" assert Namespace.render("22", {}) == 22 assert Namespace.render("-22.330", {}) == -22.330 assert Namespace.render_string("['1', '2', '3']", {}) == ['1', '2', '3']
] def test_case_params(suite): case = suite.get_case(ROOT_DIR, "params.rigor") # check case root assert case.name == "Params" assert case.format == "1.0" assert case.host == "https://httpbin.org" assert case.tags == ["working"] assert len(case.steps) == 1 assert len(case.scenarios) == 3 # check scenarios assert case.scenarios[0] == Namespace(value=1, __name__="Scenario #1") assert case.scenarios[1] == Namespace(value=2, __name__="Override!") assert case.scenarios[2] == Namespace(value=['a', 'b', 'c'], __name__="Scenario #3") def test_case_http_status(suite): case = suite.get_case(ROOT_DIR, "http_status.rigor") # check case root assert case.name == "HTTP Status" assert case.format == "1.0" assert case.host == "https://httpbin.org" assert len(case.steps) == 4 assert len(case.scenarios) == 1 # default empty scenario
] def test_case_params(suite): case = suite.get_case(ROOT_DIR, "params.rigor") # check case root assert case.name == "Params" assert case.format == "1.0" assert case.host == "https://httpbin.org" assert case.tags == ["working"] assert len(case.steps) == 1 assert len(case.scenarios) == 3 # check scenarios assert case.scenarios[0] == Namespace(value=1, __name__="Scenario #1") assert case.scenarios[1] == Namespace(value=2, __name__="Override!") assert case.scenarios[2] == Namespace( value=["a", "b", "c"], __name__="Scenario #3" ) def test_case_http_status(suite): case = suite.get_case(ROOT_DIR, "http_status.rigor") # check case root assert case.name == "HTTP Status" assert case.format == "1.0" assert case.host == "https://httpbin.org" assert len(case.steps) == 4 assert len(case.scenarios) == 1 # default empty scenario
def test_case_params(suite): case = suite.get_case(ROOT_DIR, "params.rigor") # check case root assert case.name == "Params" assert case.format == "1.0" assert case.host == "https://httpbin.org" assert case.tags == ["working"] assert len(case.steps) == 1 assert len(case.scenarios) == 3 # check scenarios assert case.scenarios[0] == Namespace(value=1, __name__="Scenario #1", __sequence__=1) assert case.scenarios[1] == Namespace(value=2, __name__="Override!", __sequence__=2) assert case.scenarios[2] == Namespace(value=["a", "b", "c"], __name__="Scenario #3", __sequence__=3) def test_case_http_status(suite): case = suite.get_case(ROOT_DIR, "http_status.rigor") # check case root assert case.name == "HTTP Status" assert case.format == "1.0"