def test_without_mandatory_fields(): xl_file_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "testdata", "without_mandatory.xls")) print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>xl_file_path:", xl_file_path validator = ngdsvalidator.NGDSValidator(filepath=xl_file_path, resource_path=None, resource_list=None) validator.find_column_pos() validator._validate_mandatory_field()
def test_valid_file(): xl_file_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "testdata", "test_find_pos.xls")) print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>xl_file_path:", xl_file_path validator = ngdsvalidator.NGDSValidator(filepath=xl_file_path, resource_path=None, resource_list=None) validationResponse = validator.validate() assert validationResponse
def test_invalid_date_fields(): xl_file_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "testdata", "invalid_date_fields.xls")) print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>xl_file_path:", xl_file_path validator = ngdsvalidator.NGDSValidator(filepath=xl_file_path, resource_path=None, resource_list=None) validator.find_column_pos() try: validator._validate_date_field() except Exception, e: print "exception: ", e assert False
def test_find_column_pos2(): xl_file_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "testdata", "test_find_pos1.xls")) print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>xl_file_path:", xl_file_path validator = ngdsvalidator.NGDSValidator(filepath=xl_file_path, resource_path=None, resource_list=None) validator.find_column_pos() print "self.mandatory_keys_pos: ", validator.mandatory_keys_pos print 'self.mandatory_keys_pos: %s date_field_pos: %s upload_file_pos: %s' % ( validator.mandatory_keys_pos, validator.date_field_pos, validator.upload_file_pos) assert_equals(validator.mandatory_keys_pos, [(0, u'name'), (1, u'title')]) assert_equals(validator.date_field_pos, [(8, u'publication_date')]) assert_equals(validator.upload_file_pos, [(14, u'resource-0-upload_file')])
def _validate_uploadfile(self, data_file, resource_path, resource_list): """ This function is responsible for validating a bulk upload. """ err_msg = "" try: validator = ngdsvalidator.NGDSValidator( filepath=data_file, resource_path=resource_path, resource_list=resource_list) validator.validate() status = "VALID" h.flash_notice(toolkit._('Files Uploaded Successfully.'), allow_html=True) except Exception, e: err_msg = e.__str__() h.flash_error(toolkit._('Uploaded files are invalid.: %s ') % err_msg, allow_html=True) status = "INVALID"