def test_customer_name_person(self): entity = record.Person() entity.set_name("Herp L. Derpinson", "Mr") entity.set_contactnum("0402000000") item = record.CustomerName(entity) records = item.get_records() # Expect PERSON result (3x records) self.assertEqual(len(records), 3) result = item.generate_as_dict() self.assertListEqual( result, [ { "type": "X", "size": 40, "value": "Derpinson" }, { "type": "X", "size": 120, "value": "Herp L." }, { "type": "X", "size": 12, "value": "Mr" }, ], )
def test_customer_name_business(self): entity = record.Business() entity.set_name( "Extremely Long Name Pty Ltd, Trading as Stupidly Long Name Incorporated" ) entity.set_contactnum("0402000000") item = record.CustomerName(entity) records = item.get_records() # Expect BUSINESS result (2x records) self.assertEqual(len(records), 2) result = item.generate_as_dict() self.assertListEqual( result, [ { "type": "X", "size": 160, "value": "Extremely Long Name Pty Ltd, Trading as Stupidly Long Name Incorporated", }, { "type": "X", "size": 12, "value": "" }, ], )
def test_transaction(self): person = self.get_person() business = self.get_business() address = self.get_address() # This is the File Sequence Number i = IPND(source="XXXXX", seq=2, date=self.get_date()) nums = (("0749700000", person), ("0749700001", business)) for num, entity in nums: t = record.Transaction() t.add_entry(record.CSPCode("999")) t.add_entry(record.DPCode("YYYYYY")) t.add_entry(record.PublicNumber(num)) t.add_entry(record.UsageCode(entity)) t.add_entry(record.ServiceStatusCode("C")) t.add_entry(record.PendingFlag("N")) t.add_entry(record.CancelPendingFlag("N")) t.add_entry(record.CustomerName(entity)) t.add_entry(record.FindingName(entity)) t.add_entry(record.ServiceAddress(address)) t.add_entry(record.DirectoryAddress(address)) t.add_entry(record.ListCode("UL")) t.add_entry(record.CustomerContact(entity)) t.add_entry(record.TransactionDate(self.get_date())) t.add_entry(record.ServiceStatusDate(self.get_date())) i.add_transaction(t) result = i.generate() # header/footer + 2 rows self.assertEqual(len(result), 4) header = "".join(result[0]).strip() self.assertEqual(header, "HDRIPNDUPXXXXX000000220200101000000") footer = "".join(result[-1]).strip() self.assertEqual(footer, "TRL0000002202001010000000000002") output = i.generate_to_string() self.assertEqual(len(output), 905 * 4)
# This is the File Sequence Number i = IPND(source="XXXXX", seq=2) nums = (("0749700000", person), ("0749700001", business)) for num, entity in nums: t = record.Transaction() t.add_entry(record.CSPCode("999")) t.add_entry(record.DPCode("YYYYYY")) t.add_entry(record.PublicNumber(num)) t.add_entry(record.UsageCode(entity)) t.add_entry(record.ServiceStatusCode("C")) t.add_entry(record.PendingFlag("N")) t.add_entry(record.CancelPendingFlag("N")) t.add_entry(record.CustomerName(entity)) t.add_entry(record.FindingName(entity)) t.add_entry(record.ServiceAddress(address)) t.add_entry(record.DirectoryAddress(address)) t.add_entry(record.ListCode("UL")) t.add_entry(record.CustomerContact(entity)) i.add_transaction(t) output = i.generate_to_string() print(output)
def test_person_transaction(self): person = self.get_person() address = self.get_address() transaction = record.Transaction() transaction.add_entry(record.CSPCode("999")) transaction.add_entry(record.DPCode("YYYYYY")) transaction.add_entry(record.PublicNumber("0749700000")) transaction.add_entry(record.UsageCode(person.get_code())) transaction.add_entry(record.ServiceStatusCode("C")) transaction.add_entry(record.PendingFlag("N")) transaction.add_entry(record.CancelPendingFlag("N")) transaction.add_entry(record.CustomerName(person)) transaction.add_entry(record.FindingName(person)) transaction.add_entry(record.ServiceAddress(address)) transaction.add_entry(record.DirectoryAddress(address)) transaction.add_entry(record.ListCode("UL")) transaction.add_entry(record.CustomerContact(person)) transaction.add_entry(record.TransactionDate(self.get_date())) transaction.add_entry(record.ServiceStatusDate(self.get_date())) records = transaction.get_records() self.assertEquals(len(records), 18) flat_records = transaction.generate() self.assertEquals(len(flat_records), 68) output = "".join(flat_records) self.assertEqual(len(output), 905) # PublicNumber self.assertEqual(records[0].format(), "0749700000 ") # ServiceStatusCode self.assertEqual(records[1].format(), "C") # PendingFlag self.assertEqual(records[2].format(), "N") # CancelPendingFlag self.assertEqual(records[3].format(), "N") # CustomerName (multi) customer_name = [r.format() for r in records[4].get_records()] self.assertEqual( customer_name, [ "Derpinson ", "Herp L. ", "Mr ", ], ) # FindingName (multi) finding_name = [r.format() for r in records[5].get_records()] self.assertEqual( finding_name, [ "Derpinson ", "Herp ", "Mr ", ], ) # ServiceAddress (multi) service_address = [ r.format() for r in record.BaseRecord.flatten(records[6].get_records()) ] self.assertListEqual( service_address, [ " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "1 ", " ", " ", " ", "FAKE ", "ST ", " ", " ", " ", " ", "ACT", "ANU ", "0200", ], ) # DirectoryAddress (multi) directory_address = [ r.format() for r in record.BaseRecord.flatten(records[7].get_records()) ] self.assertListEqual( directory_address, [ " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "1 ", " ", " ", " ", "FAKE ", "ST ", " ", " ", " ", " ", "ACT", "ANU ", "0200", ], ) # ListCode self.assertEqual(records[8].format(), "UL") # UsageCode self.assertEqual(records[9].format(), "R") # TypeOfService self.assertEqual(records[10].format(), " ") # CustomerContact (multi) customer_contact = [ r.format() for r in record.BaseRecord.flatten(records[11].get_records()) ] self.assertListEqual( customer_contact, [ "Derpinson ", "Herp ", "0402000000 ", ], ) # CSPCode self.assertEqual(records[12].format(), "999") # DPCode self.assertEqual(records[13].format(), "YYYYYY") # TransactionDate self.assertEqual(records[14].format(), "20200101000000") # ServiceStatusDate self.assertEqual(records[15].format(), "20200101000000")