def test_import_customer_csv(self):
     from csvimport.management.commands.customermetertrackcsvimport import Command
     cmd = Command()
     cmd.setup( uploaded = 'test_files/customer_csv_good.csv', defaults = 'utf-8')
     errors = cmd.run(logid = 1)
     print(errors)
     self.assertFalse("Error" in str(errors))
     #rma = ElsterRma.objects.get(number="090814-001")
     #self.assertEquals(rma.complete_date.toordinal(), datetime.datetime(2014,06,12).toordinal())
     cmd.setup( uploaded = 'test_files/customer_csv_short.csv', defaults = 'utf-8')
     errors = cmd.run(logid = 2)
     #print(errors)
     self.assertTrue("Incorrect number of columns 17. Should be 18" in str(errors))
def processCustomerMeterTrackImportFile(self, defaults, obj, user):
	try:
		from csvimport.management.commands.customermetertrackcsvimport import Command
		cmd = Command()
		obj.file_name = str(obj.upload_file)
		cmd.setup( uploaded = obj.file_name, defaults = defaults)
		errors = cmd.run(logid = obj.id)
		obj.error_log = obj.error_log + "\nNew Task ID: %s\n"%str(self.request.id)
		if errors:
			obj.error_log = obj.error_log +'\n'.join(errors)
		obj.import_user = str(user)
		obj.import_date = datetime.datetime.now()
		try:
		    obj.save()
		except IntegrityError:
		    obj.update()
	except Exception as inst:
		obj.error_log = obj.error_log + '\nImport Error in background task: %s'% str(inst)
		try:
		    obj.save()
		except IntegrityError:
		    obj.update()
	return obj.error_log