How to use get_validation_errors method in pypom_form

Best Python code snippet using pypom_form_python

test_validation.py

Source:test_validation.py Github

copy

Full Screen

...3from nose.tools import assert_equal, assert_in4from ckanext.spatial import validation5# other validation tests are in test_harvest.py6class TestValidation:7 def get_validation_errors(self, validator, validation_test_filename):8 validation_test_filepath = os.path.join(os.path.dirname(__file__),9 'xml',10 validation_test_filename)11 xml = etree.parse(validation_test_filepath)12 is_valid, errors = validator.is_valid(xml)13 return ';'.join(errors)14 def test_iso19139_failure(self):15 errors = self.get_validation_errors(validation.ISO19139Schema,16 'iso19139/dataset-invalid.xml')17 assert len(errors) > 018 assert_in('Dataset schema (gmx.xsd)', errors)19 assert_in('{http://www.isotc211.org/2005/gmd}nosuchelement\': This element is not expected.', errors)20 def test_iso19139_pass(self):21 errors = self.get_validation_errors(validation.ISO19139Schema,22 'iso19139/dataset.xml')23 assert_equal(errors, '')24 # Gemini2.1 tests are basically the same as those in test_harvest.py but25 # a few little differences make it worth not removing them in26 # test_harvest27 def test_01_dataset_fail_iso19139_schema(self):28 errors = self.get_validation_errors(validation.ISO19139EdenSchema,29 'gemini2.1/validation/01_Dataset_Invalid_XSD_No_Such_Element.xml')30 assert len(errors) > 031 assert_in('(gmx.xsd)', errors)32 assert_in('\'{http://www.isotc211.org/2005/gmd}nosuchelement\': This element is not expected.', errors)33 def test_02_dataset_fail_constraints_schematron(self):34 errors = self.get_validation_errors(validation.ConstraintsSchematron,35 'gemini2.1/validation/02_Dataset_Invalid_19139_Missing_Data_Format.xml')36 assert len(errors) > 037 assert_in('MD_Distribution / MD_Format: count(distributionFormat + distributorFormat) > 0', errors)38 def test_03_dataset_fail_gemini_schematron(self):39 errors = self.get_validation_errors(validation.Gemini2Schematron,40 'gemini2.1/validation/03_Dataset_Invalid_GEMINI_Missing_Keyword.xml')41 assert len(errors) > 042 assert_in('Descriptive keywords are mandatory', errors)43 def assert_passes_all_gemini2_1_validation(self, xml_filepath):44 errs = self.get_validation_errors(validation.ISO19139EdenSchema,45 xml_filepath)46 assert not errs, 'ISO19139EdenSchema: ' + errs47 errs = self.get_validation_errors(validation.ConstraintsSchematron,48 xml_filepath)49 assert not errs, 'ConstraintsSchematron: ' + errs50 errs = self.get_validation_errors(validation.Gemini2Schematron,51 xml_filepath)52 assert not errs, 'Gemini2Schematron: ' + errs53 def test_04_dataset_valid(self):54 self.assert_passes_all_gemini2_1_validation('gemini2.1/validation/04_Dataset_Valid.xml')55 def test_05_series_fail_iso19139_schema(self):56 errors = self.get_validation_errors(validation.ISO19139EdenSchema,57 'gemini2.1/validation/05_Series_Invalid_XSD_No_Such_Element.xml')58 assert len(errors) > 059 assert_in('(gmx.xsd)', errors)60 assert_in('\'{http://www.isotc211.org/2005/gmd}nosuchelement\': This element is not expected.', errors)61 def test_06_series_fail_constraints_schematron(self):62 errors = self.get_validation_errors(validation.ConstraintsSchematron,63 'gemini2.1/validation/06_Series_Invalid_19139_Missing_Data_Format.xml')64 assert len(errors) > 065 assert_in('MD_Distribution / MD_Format: count(distributionFormat + distributorFormat) > 0', errors)66 def test_07_series_fail_gemini_schematron(self):67 errors = self.get_validation_errors(validation.Gemini2Schematron,68 'gemini2.1/validation/07_Series_Invalid_GEMINI_Missing_Keyword.xml')69 assert len(errors) > 070 assert_in('Descriptive keywords are mandatory', errors)71 def test_08_series_valid(self):72 self.assert_passes_all_gemini2_1_validation('gemini2.1/validation/08_Series_Valid.xml')73 def test_09_service_fail_iso19139_schema(self):74 errors = self.get_validation_errors(validation.ISO19139EdenSchema,75 'gemini2.1/validation/09_Service_Invalid_No_Such_Element.xml')76 assert len(errors) > 077 assert_in('(gmx.xsd & srv.xsd)', errors)78 assert_in('\'{http://www.isotc211.org/2005/gmd}nosuchelement\': This element is not expected.', errors)79 def test_10_service_fail_constraints_schematron(self):80 errors = self.get_validation_errors(validation.ConstraintsSchematron,81 'gemini2.1/validation/10_Service_Invalid_19139_Level_Description.xml')82 assert len(errors) > 083 assert_in("DQ_Scope: 'levelDescription' is mandatory if 'level' notEqual 'dataset' or 'series'.", errors)84 def test_11_service_fail_gemini_schematron(self):85 errors = self.get_validation_errors(validation.Gemini2Schematron,86 'gemini2.1/validation/11_Service_Invalid_GEMINI_Service_Type.xml')87 assert len(errors) > 088 assert_in("Service type shall be one of 'discovery', 'view', 'download', 'transformation', 'invoke' or 'other' following INSPIRE generic names.", errors)89 def test_12_service_valid(self):90 self.assert_passes_all_gemini2_1_validation('gemini2.1/validation/12_Service_Valid.xml')91 def test_13_dataset_fail_iso19139_schema_2(self):92 # This test Dataset has srv tags and only Service metadata should.93 errors = self.get_validation_errors(validation.ISO19139EdenSchema,94 'gemini2.1/validation/13_Dataset_Invalid_Element_srv.xml')95 assert len(errors) > 096 assert_in('(gmx.xsd)', errors)97 assert_in('(u"Element \'{http://www.isotc211.org/2005/srv}SV_ServiceIdentification\': This element is not expected.', errors)98 def test_schematron_error_extraction(self):99 validation_error_xml = '''100<root xmlns:svrl="http://purl.oclc.org/dsdl/svrl">101 <svrl:failed-assert test="srv:serviceType/*[1] = 'discovery' or srv:serviceType/*[1] = 'view' or srv:serviceType/*[1] = 'download' or srv:serviceType/*[1] = 'transformation' or srv:serviceType/*[1] = 'invoke' or srv:serviceType/*[1] = 'other'" location="/*[local-name()='MD_Metadata' and namespace-uri()='http://www.isotc211.org/2005/gmd']/*[local-name()='identificationInfo' and namespace-uri()='http://www.isotc211.org/2005/gmd']/*[local-name()='SV_ServiceIdentification' and namespace-uri()='http://www.isotc211.org/2005/srv']">102 <svrl:text>103 Service type shall be one of 'discovery', 'view', 'download', 'transformation', 'invoke' or 'other' following INSPIRE generic names.104 </svrl:text>105 </svrl:failed-assert>106</root>107'''...

Full Screen

Full Screen

models.py

Source:models.py Github

copy

Full Screen

...18>>> from django.utils.datastructures import MultiValueDict19# Create a Musician object via the default AddManipulator.20>>> man = Musician.AddManipulator()21>>> data = MultiValueDict({'first_name': ['Ella'], 'last_name': ['Fitzgerald']})22>>> man.get_validation_errors(data)23{}24>>> man.do_html2python(data)25>>> m1 = man.save(data)26# Verify it worked.27>>> Musician.objects.all()28[<Musician: Ella Fitzgerald>]29>>> [m1] == list(Musician.objects.all())30True31# Attempt to add a Musician without a first_name.32>>> man.get_validation_errors(MultiValueDict({'last_name': ['Blakey']}))33{'first_name': ['This field is required.']}34# Attempt to add a Musician without a first_name and last_name.35>>> man.get_validation_errors(MultiValueDict({}))36{'first_name': ['This field is required.'], 'last_name': ['This field is required.']}37# Attempt to create an Album without a name or musician.38>>> man = Album.AddManipulator()39>>> man.get_validation_errors(MultiValueDict({}))40{'musician': ['This field is required.'], 'name': ['This field is required.']}41# Attempt to create an Album with an invalid musician.42>>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['foo']}))43{'musician': ["Select a valid choice; 'foo' is not in ['', '1']."]}44# Attempt to create an Album with an invalid release_date.45>>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['1'], 'release_date': 'today'}))46{'release_date': ['Enter a valid date in YYYY-MM-DD format.']}47# Create an Album without a release_date (because it's optional).48>>> data = MultiValueDict({'name': ['Ella and Basie'], 'musician': ['1']})49>>> man.get_validation_errors(data)50{}51>>> man.do_html2python(data)52>>> a1 = man.save(data)53# Verify it worked.54>>> Album.objects.all()55[<Album: Ella and Basie>]56>>> Album.objects.get().musician57<Musician: Ella Fitzgerald>58# Create an Album with a release_date.59>>> data = MultiValueDict({'name': ['Ultimate Ella'], 'musician': ['1'], 'release_date': ['2005-02-13']})60>>> man.get_validation_errors(data)61{}62>>> man.do_html2python(data)63>>> a2 = man.save(data)64# Verify it worked.65>>> Album.objects.order_by('name')66[<Album: Ella and Basie>, <Album: Ultimate Ella>]67>>> a2 = Album.objects.get(pk=2)68>>> a269<Album: Ultimate Ella>70>>> a2.release_date71datetime.date(2005, 2, 13)...

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