How to use _validate_block method in tavern

Best Python code snippet using tavern

test_rest.py

Source:test_rest.py Github

copy

Full Screen

...123 def test_simple_validate_body(self, example_response, includes):124 """Make sure a simple value comparison works125 """126 r = RestResponse(Mock(), "Test 1", example_response, includes)127 r._validate_block("body", example_response["body"])128 assert not r.errors129 def test_validate_list_body(self, example_response, includes):130 """Make sure a list response can be validated131 """132 example_response["body"] = ["a", 1, "b"]133 r = RestResponse(Mock(), "Test 1", example_response, includes)134 r._validate_block("body", example_response["body"])135 assert not r.errors136 def test_validate_list_body_wrong_order(self, example_response, includes):137 """Order of list items matters138 """139 example_response["body"] = ["a", 1, "b"]140 r = RestResponse(Mock(), "Test 1", example_response, includes)141 r._validate_block("body", example_response["body"][::-1])142 assert r.errors143 def test_validate_nested_body(self, example_response, includes):144 """Make sure a nested value comparison works145 """146 example_response["body"]["nested"] = { "subthing": "blah" }147 r = RestResponse(Mock(), "Test 1", example_response, includes)148 r._validate_block("body", example_response["body"])149 assert not r.errors150 def test_simple_validate_headers(self, example_response, includes):151 """Make sure a simple value comparison works152 """153 r = RestResponse(Mock(), "Test 1", example_response, includes)154 r._validate_block("headers", example_response["headers"])155 assert not r.errors156 def test_simple_validate_redirect_query_params(self, example_response, includes):157 """Make sure a simple value comparison works158 """159 r = RestResponse(Mock(), "Test 1", example_response, includes)160 r._validate_block("redirect_query_params", {"search": "breadsticks"})161 assert not r.errors162 def test_validate_missing_list_key(self, example_response, includes):163 """If we expect 4 items and 3 were returned, catch error"""164 example_response["body"] = ["a", 1, "b", "c"]165 bad_expected = example_response["body"][:-1]166 r = RestResponse(Mock(), "Test 1", example_response, includes)167 r._validate_block("body", bad_expected)168 assert r.errors169 def test_validate_wrong_list_dict(self, example_response, includes):170 """We expected a list, but we got a dict in the response"""171 example_response["body"] = ["a", 1, "b", "c"]172 bad_expected = {"a": "b"}173 r = RestResponse(Mock(), "Test 1", example_response, includes)174 r._validate_block("body", bad_expected)175 assert r.errors176 def test_validate_wrong_dict_list(self, example_response, includes):177 """We expected a dict, but we got a list in the response"""178 example_response["body"] = {"a": "b"}179 bad_expected = ["a", "b", "c"]180 r = RestResponse(Mock(), "Test 1", example_response, includes)181 r._validate_block("body", bad_expected)182 assert r.errors183class TestNestedValidate:184 def test_validate_nested_null(self, example_response, includes):185 """Check that nested 'null' comparisons work186 This will be removed in a future version187 """188 example_response["body"] = {189 "nested": {190 "subthing": None191 }192 }193 expected = {194 "nested": {195 "subthing": "blah",196 }197 }198 r = RestResponse(Mock(), "Test 1", example_response, includes)199 with pytest.warns(FutureWarning):200 r._validate_block("body", expected)201 assert not r.errors202 def test_validate_nested_anything(self, example_response, includes):203 """Check that nested 'anything' comparisons work204 This is a bit hacky because we're directly checking the ANYTHING205 comparison - need to add an integration test too206 """207 example_response["body"] = {208 "nested": {209 "subthing": ANYTHING,210 }211 }212 expected = {213 "nested": {214 "subthing": "blah",215 }216 }217 r = RestResponse(Mock(), "Test 1", example_response, includes)218 r._validate_block("body", expected)219 assert not r.errors220class TestFull:221 def test_validate_and_save(self, example_response, includes):222 """Test full verification + return saved values223 """224 example_response["save"] = {"body": {"test_code": "code"}}225 r = RestResponse(Mock(), "Test 1", example_response, includes)226 class FakeResponse:227 headers = example_response["headers"]228 content = "test".encode("utf8")229 def json(self):230 return example_response["body"]231 status_code = example_response["status_code"]232 saved = r.verify(FakeResponse())...

Full Screen

Full Screen

PRESUBMIT.py

Source:PRESUBMIT.py Github

copy

Full Screen

...158 filename=PY_INIT_FILENAME, dir=test_directory)159 return None160def py_import_order(python_source_path):161 """Validate that python imports are alphabetized."""162 def _validate_block(import_block):163 """Ensure that a single block is ordered properly."""164 if not import_block:165 return []166 sorted_import_block = sorted(import_block, key=lambda i: i.lower())167 if sorted_import_block == import_block:168 return []169 return ['\n'.join(sorted_import_block)]170 def _validate_imports(data):171 """Test that a file's contents are ordered properly."""172 imports = []173 from_imports = []174 corrected_import_blocks = []175 for line in data.splitlines():176 if line.startswith('import '):177 imports.append(line)178 else:179 corrected_import_blocks += _validate_block(imports)180 imports = []181 if line.startswith('from '):182 from_imports.append(line)183 else:184 corrected_import_blocks += _validate_block(from_imports)185 from_imports = []186 # Though rare, if a file ends with an import we must still validate them.187 corrected_import_blocks += _validate_block(imports)188 corrected_import_blocks += _validate_block(from_imports)189 if not corrected_import_blocks:190 return None191 suggestions = '\n\n--------\n\n'.join(corrected_import_blocks)192 return ('File {filename} has non-alphabetized import blocks. '193 'Suggested order:\n\n{suggestions}').format(194 filename=python_source_path, suggestions=suggestions)195 with open(python_source_path) as handle:196 return _validate_imports(handle.read())197 return None198def go_lint(source_path):199 """Run golint for the given source path."""200 if os.path.basename(source_path) in GOLINT_EXCEPTIONS:201 return ''202 golint_path = os.path.join('local', 'bin', 'golint')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tavern automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful