Best Python code snippet using tavern
test_lease4.py
Source:test_lease4.py
...11 x = kea.Lease4()12 self.assertEqual('0.0.0.0', x.addr)13 x.addr = '192.168.0.1'14 self.assertEqual('192.168.0.1', x.addr)15 def test_bad_type(self):16 x = kea.Lease4()17 with self.assertRaises(TypeError) as cm:18 x.addr = 'bogus'19 self.assertEqual(("Failed to convert string to address 'bogus': Invalid argument",),20 cm.exception.args)21 with self.assertRaises(TypeError) as cm:22 x.addr = 023 self.assertEqual(('The addr attribute value must be a str',), cm.exception.args)24class TestLease4_valid_lft(utils.BaseTestCase):25 def test_getset(self):26 x = kea.Lease4()27 self.assertEqual(0, x.valid_lft)28 x.valid_lft = 360029 self.assertEqual(3600, x.valid_lft)30 def test_bad_type(self):31 x = kea.Lease4()32 with self.assertRaises(TypeError) as cm:33 x.valid_lft = 'bogus'34 self.assertEqual(('The valid_lft attribute value must be an int',), cm.exception.args)35class TestLease4_cltt(utils.BaseTestCase):36 def test_getset(self):37 x = kea.Lease4()38 self.assertEqual(0, x.cltt)39 x.cltt = 360040 self.assertEqual(3600, x.cltt)41 def test_bad_type(self):42 x = kea.Lease4()43 with self.assertRaises(TypeError) as cm:44 x.cltt = 'bogus'45 self.assertEqual(('The cltt attribute value must be an int',), cm.exception.args)46class TestLease4_subnet_id(utils.BaseTestCase):47 def test_getset(self):48 x = kea.Lease4()49 self.assertEqual(0, x.subnet_id)50 x.subnet_id = 551 self.assertEqual(5, x.subnet_id)52 def test_bad_type(self):53 x = kea.Lease4()54 with self.assertRaises(TypeError) as cm:55 x.subnet_id = 'bogus'56 self.assertEqual(('The subnet_id attribute value must be an int',), cm.exception.args)57class TestLease4_hostname(utils.BaseTestCase):58 def test_getset(self):59 x = kea.Lease4()60 self.assertIsNone(x.hostname)61 x.hostname = 'example.org'62 self.assertEqual('example.org', x.hostname)63 x.hostname = None64 self.assertIsNone(x.hostname)65 def test_bad_type(self):66 x = kea.Lease4()67 with self.assertRaises(TypeError) as cm:68 x.hostname = 369 self.assertEqual(('The hostname attribute value must be a str',), cm.exception.args)70class TestLease4_fqdn_fwd(utils.BaseTestCase):71 def test_getset(self):72 x = kea.Lease4()73 self.assertEqual(False, x.fqdn_fwd)74 x.fqdn_fwd = True75 self.assertEqual(True, x.fqdn_fwd)76 x.fqdn_fwd = False77 self.assertEqual(False, x.fqdn_fwd)78 def test_bad_type(self):79 x = kea.Lease4()80 with self.assertRaises(TypeError) as cm:81 x.fqdn_fwd = 'bogus'82 self.assertEqual(('The fqdn_fwd attribute value must be a bool',), cm.exception.args)83class TestLease4_fqdn_rev(utils.BaseTestCase):84 def test_getset(self):85 x = kea.Lease4()86 self.assertEqual(False, x.fqdn_rev)87 x.fqdn_rev = True88 self.assertEqual(True, x.fqdn_rev)89 x.fqdn_rev = False90 self.assertEqual(False, x.fqdn_rev)91 def test_bad_type(self):92 x = kea.Lease4()93 with self.assertRaises(TypeError) as cm:94 x.fqdn_rev = 'bogus'95 self.assertEqual(('The fqdn_rev attribute value must be a bool',), cm.exception.args)96class TestLease4_hwaddr(utils.BaseTestCase):97 def test_getset(self):98 x = kea.Lease4()99 self.assertIsNone(x.hwaddr)100 x.hwaddr = '01:02:03:04:05:06'101 self.assertEqual('01:02:03:04:05:06', x.hwaddr)102 def test_bad_type(self):103 x = kea.Lease4()104 with self.assertRaises(TypeError) as cm:105 x.hwaddr = 'bogus'106 self.assertEqual(("invalid format of the decoded string 'bogus'",), cm.exception.args)107class TestLease4_client_id(utils.BaseTestCase):108 def test_getset(self):109 x = kea.Lease4()110 self.assertIsNone(x.client_id)111 x.client_id = '01:02:03:04:05:06'112 self.assertEqual('01:02:03:04:05:06', x.client_id)113 def test_bad_type(self):114 x = kea.Lease4()115 with self.assertRaises(TypeError) as cm:116 x.client_id = 'bogus'117 self.assertEqual(("'bogus' is not a valid string of hexadecimal digits",),118 cm.exception.args)119class TestLease4_state(utils.BaseTestCase):120 def test_getset(self):121 x = kea.Lease4()122 self.assertEqual(0, x.state)123 x.state = 5124 self.assertEqual(5, x.state)125 def test_bad_type(self):126 x = kea.Lease4()127 with self.assertRaises(TypeError) as cm:128 x.state = 'bogus'129 self.assertEqual(('The state attribute value must be an int',), cm.exception.args)130class TestLease4_setContext(utils.BaseTestCase):131 def test_badarg_count(self):132 x = kea.Lease4()133 self.assert_method_one_arg_no_keywords(x.setContext)134 def test_ok(self):135 x = kea.Lease4()136 self.assertIs(x, x.setContext('foo'))137 self.assertIs(x, x.setContext(2))138 self.assertIs(x, x.setContext(True))139 self.assertIs(x, x.setContext([1, 'foo']))...
test_config.py
Source:test_config.py
...35class TestConfigStyle(Test):36 def test_setting(self):37 self.uncreated.style = "color"38 assert self.uncreated.style == "color"39 def test_bad_type(self):40 with raises(TypeError):41 self.uncreated.style = 1242 def test_bad_value(self):43 with raises(ValueError):44 self.uncreated.style = "fish"45 def test_after_create(self):46 with raises(stampr.exceptions.ReadOnlyError):47 self.created.style = "color"48class TestConfigTurnaround(Test):49 def test_setting(self):50 self.uncreated.turnaround = "threeday"51 assert self.uncreated.turnaround == "threeday"52 def test_bad_type(self):53 with raises(TypeError):54 self.uncreated.turnaround = 1255 def test_bad_value(self):56 with raises(ValueError):57 self.uncreated.turnaround = "fish"58 def test_after_create(self):59 with raises(stampr.exceptions.ReadOnlyError):60 self.created.turnaround = "threeday"61class TestConfigOutput(Test):62 def test_setting(self):63 self.uncreated.output = "single"64 assert self.uncreated.output == "single"65 def test_bad_type(self):66 with raises(TypeError):67 self.uncreated.output = 1268 def test_bad_value(self):69 with raises(ValueError):70 self.uncreated.output = "fish"71 def test_after_create(self):72 with raises(stampr.exceptions.ReadOnlyError):73 self.created.output = "single"74class TestConfigSize(Test):75 def test_setting(self):76 self.uncreated.size = "standard"77 assert self.uncreated.size == "standard"78 def test_bad_type(self):79 with raises(TypeError):80 self.uncreated.size = 1281 def test_bad_value(self):82 with raises(ValueError):83 self.uncreated.size = "fish"84 def test_after_create(self):85 with raises(stampr.exceptions.ReadOnlyError):86 self.created.size = "standard"87class TestConfigReturnEnvelope(Test):88 def test_setting(self):89 self.uncreated.return_envelope = False90 assert self.uncreated.return_envelope == False91 def test_bad_type(self):92 with raises(TypeError):93 self.uncreated.return_envelope = 1294 def test_after_create(self):95 with raises(stampr.exceptions.ReadOnlyError):96 self.created.return_envelope = False97class TestConfigCreate(Test):98 def test_no_authentication(self):99 stampr.client.Client._current = stampr.client.NullClient()100 with raises(stampr.exceptions.APIError):101 self.uncreated.create()102 def test_creation(self):103 (flexmock(stampr.client.Client.current)104 .should_receive("_api")105 .with_args("post", ("configs",), output="single", returnenvelope=False, size="standard", style="color", turnaround="threeday")106 .and_return(json_data("config_create")))107 config = self.uncreated108 config.create()109 assert config.id == 4677110class TestConfigIndex(Test):111 def test_no_authentication(self):112 stampr.client.Client._current = stampr.client.NullClient()113 with raises(stampr.exceptions.APIError):114 stampr.config.Config[4677]115 def test_indexing(self):116 (flexmock(stampr.client.Client.current)117 .should_receive("_api")118 .with_args("get", ("configs", 4677))119 .and_return(json_data("config_index")))120 config = stampr.config.Config[4677]121 assert isinstance(config, stampr.config.Config)122 assert config.id == 4677123 def test_bad_type(self):124 with raises(TypeError):125 stampr.config.Config["frog"]126 def test_bad_value(self):127 with raises(ValueError):128 stampr.config.Config[-1]129 def test_not_exists(self):130 (flexmock(stampr.client.Client.current)131 .should_receive("_api")132 .with_args("get", ("configs", 4677))133 .and_return([]))134 with raises(stampr.exceptions.RequestError):135 stampr.config.Config[4677]136class TestConfigAll(Test):137 def test_no_authentication(self):...
test_fields.py
Source:test_fields.py
...24 field.name = 'checkmark'25 with self.assertRaises(exceptions.ValidationError) as e:26 field.validate({})27 self.assertEqual(str(e.exception), "'checkmark' is required.")28 def test_bad_type(self):29 field = fields.BooleanField()30 field.name = 'checkmark'31 with self.assertRaises(exceptions.ValidationError) as e:32 field.validate({'checkmark': 'a'})33 self.assertEqual(str(e.exception), "'checkmark' must be a boolean.")34 def test_ok(self):35 field = fields.BooleanField()36 field.name = 'checkmark'37 self.assertIsNone(field.validate({'checkmark': True}))38 self.assertIsNone(field.validate({'checkmark': False}))39class IntFieldTestCase(unittest.TestCase):40 def test_not_required(self):41 field = fields.IntField(required=False)42 field.name = 'widgets'43 self.assertIsNone(field.validate({}))44 def test_ranged_not_required(self):45 field = fields.IntField(min=0, max=100, required=False)46 field.name = 'widgets'47 self.assertIsNone(field.validate({}))48 def test_explicit_required(self):49 field = fields.IntField(required=True)50 field.name = 'widgets'51 with self.assertRaises(exceptions.ValidationError) as e:52 field.validate({})53 self.assertEqual(str(e.exception), "'widgets' is required.")54 def test_bad_type(self):55 field = fields.IntField(required=True)56 field.name = 'widgets'57 with self.assertRaises(exceptions.ValidationError) as e:58 field.validate({'widgets': 'a'})59 self.assertEqual(str(e.exception), "'widgets' must be an integer.")60 def test_in_range(self):61 field = fields.IntField(min=0, max=100, required=True)62 field.name = 'widgets'63 self.assertIsNone(field.validate({'widgets': 42}))64 def test_under_min(self):65 field = fields.IntField(min=0, max=100, required=True)66 field.name = 'widgets'67 with self.assertRaises(exceptions.ValidationError) as e:68 field.validate({'widgets': -10})69 self.assertEqual(str(e.exception), "'widgets' must be greater than or equal to 0.")70 def test_over_max(self):71 field = fields.IntField(min=0, max=100, required=True)72 field.name = 'widgets'73 with self.assertRaises(exceptions.ValidationError) as e:74 field.validate({'widgets': 200})75 self.assertEqual(str(e.exception), "'widgets' must be less than or equal to 100.")76class CharFieldTestCase(unittest.TestCase):77 def test_not_required(self):78 field = fields.CharField(required=False)79 field.name = 'name'80 self.assertIsNone(field.validate({}))81 def test_explicit_required(self):82 field = fields.CharField(required=True)83 field.name = 'name'84 with self.assertRaises(exceptions.ValidationError) as e:85 field.validate({})86 self.assertEqual(str(e.exception), "'name' is required.")87 def test_bad_type(self):88 field = fields.CharField(required=True)89 field.name = 'name'90 with self.assertRaises(exceptions.ValidationError) as e:91 field.validate({'name': 0})92 self.assertEqual(str(e.exception), "'name' must be a string.")93 def test_empty_string_is_valid(self):94 field = fields.CharField(required=True)95 field.name = 'name'96 self.assertIsNone(field.validate({'name': ""}))97 def test_valid_string(self):98 field = fields.CharField(required=True)99 field.name = 'name'100 self.assertIsNone(field.validate({'name': "Human"}))101class ReferenceTestCase(unittest.TestCase):102 def test_not_required(self):103 field = fields.Reference(required=False)104 field.name = 'owner'105 self.assertIsNone(field.validate({}))106 def test_explicit_required(self):107 field = fields.Reference(required=True)108 field.name = 'owner'109 with self.assertRaises(exceptions.ValidationError) as e:110 field.validate({})111 self.assertEqual(str(e.exception), "'owner_id' is required.")112 def test_bad_type(self):113 field = fields.Reference(required=True)114 field.name = 'owner'115 with self.assertRaises(exceptions.ValidationError) as e:116 field.validate({'owner_id': 'a'})...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!