How to use test_unknown_fields method in tavern

Best Python code snippet using tavern

test_orbitals.py

Source:test_orbitals.py Github

copy

Full Screen

...33 orbital = Orbital(position=(1, 2, 3))34 assert round(abs(orbital.get_orbital_dict()['position'][0] - 1.), 7) == 035 assert round(abs(orbital.get_orbital_dict()['position'][1] - 2.), 7) == 036 assert round(abs(orbital.get_orbital_dict()['position'][2] - 3.), 7) == 037 def test_unknown_fields(self):38 """Verify that unkwown fields raise a validation error."""39 # position is required40 # position must be a list of three floats41 with pytest.raises(ValidationError, match='some_strange_key'):42 Orbital(position=(1, 2, 3), some_strange_key=1)43class TestRealhydrogenOrbital:44 """Test the Orbital base class"""45 def test_required_fields(self):46 """Verify that required fields are validated."""47 RealhydrogenOrbital = OrbitalFactory('core.realhydrogen') # pylint: disable=invalid-name48 # Check that the required fields of the base class are not enough49 with pytest.raises(ValidationError):50 RealhydrogenOrbital(position=(1, 2, 3))51 orbital = RealhydrogenOrbital(52 **{53 'position': (-1, -2, -3),54 'angular_momentum': 1,55 'magnetic_number': 0,56 'radial_nodes': 257 }58 )59 assert round(abs(orbital.get_orbital_dict()['position'][0] - -1.), 7) == 060 assert round(abs(orbital.get_orbital_dict()['position'][1] - -2.), 7) == 061 assert round(abs(orbital.get_orbital_dict()['position'][2] - -3.), 7) == 062 assert round(abs(orbital.get_orbital_dict()['angular_momentum'] - 1), 7) == 063 assert round(abs(orbital.get_orbital_dict()['magnetic_number'] - 0), 7) == 064 assert round(abs(orbital.get_orbital_dict()['radial_nodes'] - 2), 7) == 065 def test_validation_for_fields(self):66 """Verify that the values are properly validated"""67 RealhydrogenOrbital = OrbitalFactory('core.realhydrogen') # pylint: disable=invalid-name68 with pytest.raises(ValidationError, match='angular_momentum'):69 RealhydrogenOrbital(70 **{71 'position': (-1, -2, -3),72 'angular_momentum': 100,73 'magnetic_number': 0,74 'radial_nodes': 275 }76 )77 with pytest.raises(ValidationError, match='magnetic number must be in the range'):78 RealhydrogenOrbital(79 **{80 'position': (-1, -2, -3),81 'angular_momentum': 1,82 'magnetic_number': 3,83 'radial_nodes': 284 }85 )86 with pytest.raises(ValidationError, match='radial_nodes'):87 RealhydrogenOrbital(88 **{89 'position': (-1, -2, -3),90 'angular_momentum': 1,91 'magnetic_number': 0,92 'radial_nodes': 10093 }94 )95 def test_optional_fields(self):96 """97 Testing (some of) the optional parameters to check that the functionality works98 (they are indeed optional but accepted if specified, they are validated, ...)99 """100 RealhydrogenOrbital = OrbitalFactory('core.realhydrogen') # pylint: disable=invalid-name101 orbital = RealhydrogenOrbital(102 **{103 'position': (-1, -2, -3),104 'angular_momentum': 1,105 'magnetic_number': 0,106 'radial_nodes': 2107 }108 )109 # Check that the optional value is there and has its default value110 assert orbital.get_orbital_dict()['spin'] == 0111 assert orbital.get_orbital_dict()['diffusivity'] is None112 orbital = RealhydrogenOrbital(113 **{114 'position': (-1, -2, -3),115 'angular_momentum': 1,116 'magnetic_number': 0,117 'radial_nodes': 2,118 'spin': 1,119 'diffusivity': 3.1120 }121 )122 assert orbital.get_orbital_dict()['spin'] == 1123 assert orbital.get_orbital_dict()['diffusivity'] == 3.1124 with pytest.raises(ValidationError, match='diffusivity'):125 RealhydrogenOrbital(126 **{127 'position': (-1, -2, -3),128 'angular_momentum': 1,129 'magnetic_number': 0,130 'radial_nodes': 2,131 'spin': 1,132 'diffusivity': 'a'133 }134 )135 with pytest.raises(ValidationError, match='spin'):136 RealhydrogenOrbital(137 **{138 'position': (-1, -2, -3),139 'angular_momentum': 1,140 'magnetic_number': 0,141 'radial_nodes': 2,142 'spin': 5,143 'diffusivity': 3.1144 }145 )146 def test_unknown_fields(self):147 """Verify that unkwown fields raise a validation error."""148 RealhydrogenOrbital = OrbitalFactory('core.realhydrogen') # pylint: disable=invalid-name149 with pytest.raises(ValidationError, match='some_strange_key'):150 RealhydrogenOrbital(151 **{152 'position': (-1, -2, -3),153 'angular_momentum': 1,154 'magnetic_number': 0,155 'radial_nodes': 2,156 'some_strange_key': 1157 }158 )159 def test_get_name_from_quantum_numbers(self):160 """...

Full Screen

Full Screen

test_serializers.py

Source:test_serializers.py Github

copy

Full Screen

...69 })70 self.assertEqual(serializer.is_valid(), False)71 self.assertDictEqual(serializer.errors,72 {'branch_id': [ErrorDetail(string='This field is required.', code='required')]})73 def test_unknown_fields(self):74 """75 Verify failure with unknown fields76 """77 serializer = InvoiceSerializer(data={'some_field': 'some_value'})78 self.assertEqual(False, serializer.is_valid())79 def test_invalid_date(self):80 """81 Verify failure with invalid values for date field82 """83 serializer = InvoiceSerializer(data={'branch_id': str(uuidv4()),84 'vendor': self.get_vendor_data(),85 'invoice_num': self.get_invoice_num(),86 'date': "2020",87 'total_amount': "100.0",88 'items': self.get_items_data(),89 'document_id': str(uuidv4())90 })91 self.assertEqual(False, serializer.is_valid())92 def test_invalid_total_amount(self):93 """94 Verify failure with invalid values for date field95 """96 serializer = InvoiceSerializer(data={'branch_id': str(uuidv4()),97 'vendor': self.get_vendor_data(),98 'invoice_num': self.get_invoice_num(),99 'date': "2020",100 'total_amount': "abc",101 'items': self.get_items_data(),102 'document_id': str(uuidv4())103 })104 self.assertEqual(False, serializer.is_valid())105 def test_valid_data(self):106 """107 Verify successful validation of valid input data108 """109 serializer = InvoiceSerializer(data={'branch_id': str(uuidv4()),110 'vendor': self.get_vendor_data(),111 'invoice_num': self.get_invoice_num(),112 'date': "2020-06-14",113 'total_amount': "100.0",114 'items': self.get_items_data(),115 'document_id': str(uuidv4())116 })117 self.assertEqual(True, serializer.is_valid())118 self.assertEqual(100.0, serializer.validated_data['total_amount'])119class DocumentSerializerTest(TestCase):120 """121 Test cases to test DocumentSerializer122 """123 @staticmethod124 def setUp(**kwargs):125 """126 Clean database before each test127 :param **kwargs:128 """129 Document.objects.all().delete()130 def test_empty_data(self):131 """132 Verify failure with empty data133 """134 serializer = DocumentSerializer(data={})135 self.assertEqual(False, serializer.is_valid())136 def test_missing_file(self):137 """138 the "file" should be a valid file. Other values must be treated as invalid values139 """140 serializer = DocumentSerializer(data={'is_digitized': False})141 self.assertEqual(serializer.is_valid(), False)142 self.assertDictEqual(serializer.errors,143 {'file': [ErrorDetail(string='No file was submitted.', code='required')]})144 def test_unknown_fields(self):145 """146 Verify failure with unknown fields147 """148 serializer = InvoiceSerializer(data={'some_field': 'some_value'})149 self.assertEqual(False, serializer.is_valid())150 def test_invalid_is_digitized(self):151 """152 Verify failure with invalid values for is_digitized field153 """154 serializer = DocumentSerializer(data={'file': SimpleUploadedFile("file.txt", b'file_content'),155 'is_digitized': "sasa"})156 self.assertEqual(False, serializer.is_valid())157 def test_invalid_file(self):158 """...

Full Screen

Full Screen

test_templates.py

Source:test_templates.py Github

copy

Full Screen

...44 } == body45@pytest.mark.parametrize(46 "method", [routes.get, routes.post, routes.patch, routes.put, routes.delete]47)48async def test_unknown_fields(aiohttp_client, method):49 routes.routes._items.clear()50 @method("/test")51 @JSONTemplate({"interface": str}, ignore_unknown=False)52 async def test(request):53 return {"interfaces": [request.validated_data["interface"]]}54 app = aiohttp.web.Application()55 app.router.add_routes(routes.routes)56 client = await aiohttp_client(app)57 resp = await getattr(client, method.__name__)(58 "/test", json={"interface": "en2", "test": True, "test2": False}59 )60 assert resp.status == 40061 body = await resp.json()62 assert {63 "error": True,64 "reason": {65 "text": exception.UnknownFields.text,66 "path": ["test", "test2"],67 "code": exception.UnknownFields.__name__,68 },69 } == body70@pytest.mark.parametrize(71 "method", [routes.get, routes.post, routes.patch, routes.put, routes.delete]72)73async def test_unknown_fields(aiohttp_client, method):74 routes.routes._items.clear()75 @method("/test")76 @JSONTemplate(77 {"interface": int, "test": typing.Optional[int]},78 ignore_unknown=False,79 )80 async def test(request):81 return {"interfaces": [request.validated_data["interface"]]}82 app = aiohttp.web.Application()83 app.router.add_routes(routes.routes)84 client = await aiohttp_client(app)85 resp = await getattr(client, method.__name__)(86 "/test",87 json={...

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