def test_save(self): # test save against invalid lines invalid_lines = self.invalid_lines.copy() invalid_lines.update({ 1: { 'field3': [u'Field field3 is required!'], 'cpf': [u'Field cpf is required!'] } }) importer = RequiredFieldValidationsImporterDB( self.files['csv_invalid_cpf_sheet']) results = [i for i in importer.save_all_iter()] for i, know_data in enumerate(self.data_invalid): data = results[i] if not data and i + 1 in invalid_lines: # dict data starts from 1 self.assertEquals(data, None) else: for k, v in know_data.items(): # RequiredFieldValidationsImporterDB should return field # CPF as instance of data_importer.tests.cpfcnpj.CPF class, # so we make cpf a instance before comparation if k == 'cpf': v = CPF(v) self.assertEquals(True, k in data) self.assertEquals(data[k], v)
def test_invalid_required_field_DB(self): importer = RequiredFieldValidationsImporterDB(self.files['csv_invalid_cpf_sheet']) self.assertEquals([],list(Error.objects.all())) # apply list to queryset self.assertTrue(not importer.is_valid(),u"Should return False to is_valid()") self.assertTrue(importer.logger,u"Logger isn't set") self.assertTrue(isinstance(importer.logger.handlers[0],DBLoggingHandler),u"Logger handler isn't DBLoggingHandler") errors = Error.objects.all() self.assertTrue(u"RequiredFieldValidationsImporterDB_importer :: error :: Line 1, field cpf: Field cpf is required!" in \ str(errors[0]),u"Weird string for this test, check loggers.") self.assertTrue(u"RequiredFieldValidationsImporterDB_importer :: error :: Line 1, field field3: Field field3 is required!" in \ str(errors[1]),u"Weird string for this test, check loggers.") self.assertTrue(u"RequiredFieldValidationsImporterDB_importer :: error :: Line 2, field cpf: Invalid CPF number." in \ str(errors[2]),u"Weird string for this test, check loggers.") self.assertTrue(u"RequiredFieldValidationsImporterDB_importer :: error :: Line 3, field cpf: Invalid CPF number." in \ str(errors[3]),u"Weird string for this test, check loggers.")
def test_save(self): # test save against invalid lines invalid_lines = self.invalid_lines.copy() invalid_lines.update({1: {'field3': [u'Field field3 is required!'], 'cpf': [u'Field cpf is required!']}}) importer = RequiredFieldValidationsImporterDB(self.files['csv_invalid_cpf_sheet']) results = [i for i in importer.save_all_iter()] for i,know_data in enumerate(self.data_invalid): data = results[i] if not data and i+1 in invalid_lines: # dict data starts from 1 self.assertEquals(data,None) else: for k,v in know_data.items(): # RequiredFieldValidationsImporterDB should return field # CPF as instance of data_importer.tests.cpfcnpj.CPF class, # so we make cpf a instance before comparation if k == 'cpf': v = CPF(v) self.assertEquals(True,k in data) self.assertEquals(data[k],v)
def test_invalid_required_field_DB(self): importer = RequiredFieldValidationsImporterDB( self.files['csv_invalid_cpf_sheet']) self.assertEquals([], list(Error.objects.all())) # apply list to queryset self.assertTrue(not importer.is_valid(), u"Should return False to is_valid()") self.assertTrue(importer.logger, u"Logger isn't set") self.assertTrue( isinstance(importer.logger.handlers[0], DBLoggingHandler), u"Logger handler isn't DBLoggingHandler") errors = Error.objects.all() self.assertTrue(u"RequiredFieldValidationsImporterDB_importer :: error :: Line 1, field cpf: Field cpf is required!" in \ str(errors[0]),u"Weird string for this test, check loggers.") self.assertTrue(u"RequiredFieldValidationsImporterDB_importer :: error :: Line 1, field field3: Field field3 is required!" in \ str(errors[1]),u"Weird string for this test, check loggers.") self.assertTrue(u"RequiredFieldValidationsImporterDB_importer :: error :: Line 2, field cpf: Invalid CPF number." in \ str(errors[2]),u"Weird string for this test, check loggers.") self.assertTrue(u"RequiredFieldValidationsImporterDB_importer :: error :: Line 3, field cpf: Invalid CPF number." in \ str(errors[3]),u"Weird string for this test, check loggers.")