How to use test_gabbits method in gabbi

Best Python code snippet using gabbi_python

test_driver.py

Source: test_driver.py Github

copy

Full Screen

1#2# Licensed under the Apache License, Version 2.0 (the "License"); you may3# not use this file except in compliance with the License. You may obtain4# a copy of the License at5#6# http:/​/​www.apache.org/​licenses/​LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the11# License for the specific language governing permissions and limitations12# under the License.13"""Test that the driver can build tests effectively."""14import os15import unittest16from gabbi import driver17TESTS_DIR = 'test_gabbits'18class DriverTest(unittest.TestCase):19 def setUp(self):20 super(DriverTest, self).setUp()21 self.loader = unittest.defaultTestLoader22 self.test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)23 def test_driver_loads_two_tests(self):24 suite = driver.build_tests(self.test_dir, self.loader,25 host='localhost', port=8001)26 self.assertEqual(1, len(suite._tests),27 'top level suite contains one suite')28 self.assertEqual(2, len(suite._tests[0]._tests),29 'contained suite contains two tests')30 the_one_test = suite._tests[0]._tests[0]31 self.assertEqual('test_driver_sample_one',32 the_one_test.__class__.__name__,33 'test class name maps')34 self.assertEqual('one',35 the_one_test.test_data['name'])36 self.assertEqual('/​', the_one_test.test_data['url'])37 def test_driver_prefix(self):38 suite = driver.build_tests(self.test_dir, self.loader,39 host='localhost', port=8001,40 prefix='/​mountpoint')41 the_one_test = suite._tests[0]._tests[0]42 the_two_test = suite._tests[0]._tests[1]43 self.assertEqual('/​mountpoint', the_one_test.prefix)44 self.assertEqual('/​mountpoint', the_two_test.prefix)45 def test_build_requires_host_or_intercept(self):46 with self.assertRaises(AssertionError):47 driver.build_tests(self.test_dir, self.loader)48 def test_tests_key_required(self):49 test_yaml = {'name': 'house', 'url': '/​'}50 with self.assertRaises(driver.GabbiFormatError) as failure:51 driver.test_suite_from_dict(self.loader, 'foo', test_yaml, '.',52 'localhost', 80, None, None)53 self.assertEqual('malformed test file, "tests" key required',54 str(failure.exception))55 def test_upper_dict_required(self):56 test_yaml = [{'name': 'house', 'url': '/​'}]57 with self.assertRaises(driver.GabbiFormatError) as failure:58 driver.test_suite_from_dict(self.loader, 'foo', test_yaml, '.',59 'localhost', 80, None, None)60 self.assertEqual('malformed test file, invalid format',61 str(failure.exception))62 def test_inner_list_required(self):63 test_yaml = {'tests': {'name': 'house', 'url': '/​'}}64 with self.assertRaises(driver.GabbiFormatError) as failure:65 driver.test_suite_from_dict(self.loader, 'foo', test_yaml, '.',66 'localhost', 80, None, None)67 self.assertIn('test chunk is not a dict at',68 str(failure.exception))69 def test_name_key_required(self):70 test_yaml = {'tests': [{'url': '/​'}]}71 with self.assertRaises(driver.GabbiFormatError) as failure:72 driver.test_suite_from_dict(self.loader, 'foo', test_yaml, '.',73 'localhost', 80, None, None)74 self.assertEqual('Test name missing in a test in foo.',75 str(failure.exception))76 def test_url_key_required(self):77 test_yaml = {'tests': [{'name': 'missing url'}]}78 with self.assertRaises(driver.GabbiFormatError) as failure:79 driver.test_suite_from_dict(self.loader, 'foo', test_yaml, '.',80 'localhost', 80, None, None)81 self.assertEqual('Test url missing in test foo_missing_url.',82 str(failure.exception))83 def test_unsupported_key_errors(self):84 test_yaml = {'tests': [{85 'url': '/​',86 'name': 'simple',87 'bad_key': 'wow',88 }]}89 with self.assertRaises(driver.GabbiFormatError) as failure:90 driver.test_suite_from_dict(self.loader, 'foo', test_yaml, '.',91 'localhost', 80, None, None)92 self.assertIn("Invalid test keys used in test foo_simple:",93 str(failure.exception))94 def test_method_url_pair_format_error(self):95 test_yaml = {'defaults': {'GET': '/​foo'}, 'tests': []}96 with self.assertRaises(driver.GabbiFormatError) as failure:97 driver.test_suite_from_dict(self.loader, 'foo', test_yaml, '.',98 'localhost', 80, None, None)99 self.assertIn('"METHOD: url" pairs not allowed in defaults',100 str(failure.exception))101 def test_method_url_pair_duplication_format_error(self):102 test_yaml = {'tests': [{103 'GET': '/​',104 'POST': '/​',105 'name': 'duplicate methods',106 }]}107 with self.assertRaises(driver.GabbiFormatError) as failure:108 driver.test_suite_from_dict(self.loader, 'foo', test_yaml, '.',109 'localhost', 80, None, None)110 self.assertIn(111 'duplicate method/​URL directive in "foo_duplicate_methods"',112 str(failure.exception)113 )114 def test_dict_on_invalid_key(self):115 test_yaml = {'tests': [{116 'name': '...',117 'GET': '/​',118 'response_html': {119 'foo': 'hello',120 'bar': 'world',121 }122 }]}123 with self.assertRaises(driver.GabbiFormatError) as failure:124 driver.test_suite_from_dict(self.loader, 'foo', test_yaml, '.',125 'localhost', 80, None, None)126 self.assertIn(127 "invalid key in test: 'response_html'",128 str(failure.exception)...

Full Screen

Full Screen

pytest-example.py

Source: pytest-example.py Github

copy

Full Screen

...10from myapp.test import fixtures11# By convention the YAML files are put in a directory named12# "gabbits" that is in the same directory as the Python test file.13TESTS_DIR = 'gabbits'14def test_gabbits():15 test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)16 # Pass "require_ssl=True" as an argument to force all tests17 # to use SSL in requests.18 test_generator = driver.py_test_generator(19 test_loader_name=__name__,20 test_dir, intercept=wsgiapp.app,21 fixture_module=fixtures)22 for test in test_generator:...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Pair testing strategy in an Agile environment

Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.

Migrating Test Automation Suite To Cypress 10

There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.

Continuous Integration explained with jenkins deployment

Continuous integration is a coding philosophy and set of practices that encourage development teams to make small code changes and check them into a version control repository regularly. Most modern applications necessitate the development of code across multiple platforms and tools, so teams require a consistent mechanism for integrating and validating changes. Continuous integration creates an automated way for developers to build, package, and test their applications. A consistent integration process encourages developers to commit code changes more frequently, resulting in improved collaboration and code quality.

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 gabbi 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