diff --git a/test/data/ims_otrs_customers.json b/test/data/ims_otrs_customers.json new file mode 100644 index 0000000000000000000000000000000000000000..c5da5600087ba4175a495f9ad802674ce684db6b --- /dev/null +++ b/test/data/ims_otrs_customers.json @@ -0,0 +1,276 @@ +{ + "Customer": [ + { + "Id": 57284, + "ParentCustomerId": null, + "Name": "DUMMY 1", + "FullName": "DUMMY 1", + "Number": null, + "Address": "", + "PhoneNumber": "", + "FaxNumber": "", + "AccountManager": "", + "AccountEmail": "", + "Code": "", + "SlaId": null, + "ServiceCenter": 0, + "ServiceCenterName": "", + "Website": "", + "CustomerTypeId": null, + "PwCodeBlue": 0, + "PwInformProtectionSwitch": 0, + "PwInformDown": 0, + "PwInformAtRisk": 0, + "PwInformImPact": 0, + "PwInformNoImPact": 0, + "PwExtraInfo": "", + "PwLanguage": "", + "CountryId": null, + "Sla": null, + "Sites": null, + "Nodes": null, + "Racks": null, + "Orders": null, + "PwInformedList": null, + "Circuits": null, + "OloCircuits": null, + "ChannelReservations": null, + "PortReservations": null, + "IpRanges": null, + "NumberManagementList": null, + "CustomerRelatedContacts": null, + "CustomerRelatedContracts": null, + "InNumbers": null, + "ManagementSystems": null, + "CustomerType": null, + "ContractCustomerRelations": null, + "ParentCustomer": null, + "SubCustomers": null, + "EsimProfiles": null, + "Esims": null, + "Country": null, + "PwEmailSetups": null, + "TelephoneNumbers": null, + "TelephoneNumberRanges": null, + "RowVersion": "2016-05-18T10:20:38", + "Errors": null, + "HasErrors": false + }, + { + "Id": 57603, + "ParentCustomerId": null, + "Name": "DUMMY 2", + "FullName": "DUMMY 2", + "Number": null, + "Address": "", + "PhoneNumber": "", + "FaxNumber": "", + "AccountManager": "", + "AccountEmail": "", + "Code": "", + "SlaId": null, + "ServiceCenter": 0, + "ServiceCenterName": "", + "Website": "", + "CustomerTypeId": 1, + "PwCodeBlue": 0, + "PwInformProtectionSwitch": 1, + "PwInformDown": 1, + "PwInformAtRisk": 1, + "PwInformImPact": 1, + "PwInformNoImPact": 1, + "PwExtraInfo": "", + "PwLanguage": "", + "CountryId": null, + "Sla": null, + "Sites": null, + "Nodes": null, + "Racks": null, + "Orders": null, + "PwInformedList": null, + "Circuits": null, + "OloCircuits": null, + "ChannelReservations": null, + "PortReservations": null, + "IpRanges": null, + "NumberManagementList": null, + "CustomerRelatedContacts": null, + "CustomerRelatedContracts": null, + "InNumbers": null, + "ManagementSystems": null, + "CustomerType": null, + "ContractCustomerRelations": null, + "ParentCustomer": null, + "SubCustomers": null, + "EsimProfiles": null, + "Esims": null, + "Country": null, + "PwEmailSetups": null, + "TelephoneNumbers": null, + "TelephoneNumberRanges": null, + "RowVersion": "2020-01-31T13:35:07", + "Errors": null, + "HasErrors": false + }, + { + "Id": 57604, + "ParentCustomerId": null, + "Name": "DUMMY 3", + "FullName": "DUMMY 3", + "Number": null, + "Address": "", + "PhoneNumber": "", + "FaxNumber": "", + "AccountManager": "", + "AccountEmail": "", + "Code": "", + "SlaId": null, + "ServiceCenter": 0, + "ServiceCenterName": "", + "Website": "", + "CustomerTypeId": 1, + "PwCodeBlue": 0, + "PwInformProtectionSwitch": 1, + "PwInformDown": 1, + "PwInformAtRisk": 1, + "PwInformImPact": 1, + "PwInformNoImPact": 1, + "PwExtraInfo": "", + "PwLanguage": "", + "CountryId": null, + "Sla": null, + "Sites": null, + "Nodes": null, + "Racks": null, + "Orders": null, + "PwInformedList": null, + "Circuits": null, + "OloCircuits": null, + "ChannelReservations": null, + "PortReservations": null, + "IpRanges": null, + "NumberManagementList": null, + "CustomerRelatedContacts": null, + "CustomerRelatedContracts": null, + "InNumbers": null, + "ManagementSystems": null, + "CustomerType": null, + "ContractCustomerRelations": null, + "ParentCustomer": null, + "SubCustomers": null, + "EsimProfiles": null, + "Esims": null, + "Country": null, + "PwEmailSetups": null, + "TelephoneNumbers": null, + "TelephoneNumberRanges": null, + "RowVersion": "2020-01-31T13:35:07", + "Errors": null, + "HasErrors": false + } + ], + "Vendor": [ + { + "Id": 2482, + "Name": "DUMMY 4", + "TypeId": 1, + "SlaOnSiteId": null, + "SlaMainTimeToRepairId": null, + "SlaLink": "", + "SlaDescription": "", + "Description": "TESTVENDORDESCRIPTION", + "SpareOwner": "", + "StockLocation": "", + "StockContact": "", + "InternetAddress": "", + "MasterAccount": "", + "EscalationDescription": "", + "Color": "", + "IssuerCodeEsim": null, + "MnoCode": "", + "EumId": "", + "EquipmentDefinitions": null, + "ManagementSystems": null, + "CardCodes": null, + "CardDefinitions": null, + "CableTypes": null, + "VendorRelatedContacts": null, + "VendorMaterialTypes": null, + "Contract": null, + "SlaOnSite": null, + "SlaMainTimeToRepair": null, + "Type": null, + "RowVersion": "2020-01-23T16:34:30", + "Errors": null, + "HasErrors": false + }, + { + "Id": 2502, + "Name": "DUMMY 5", + "TypeId": 13, + "SlaOnSiteId": null, + "SlaMainTimeToRepairId": null, + "SlaLink": "", + "SlaDescription": "", + "Description": "", + "SpareOwner": "", + "StockLocation": "", + "StockContact": "", + "InternetAddress": "", + "MasterAccount": "", + "EscalationDescription": "", + "Color": "", + "IssuerCodeEsim": null, + "MnoCode": "", + "EumId": "", + "EquipmentDefinitions": null, + "ManagementSystems": null, + "CardCodes": null, + "CardDefinitions": null, + "CableTypes": null, + "VendorRelatedContacts": null, + "VendorMaterialTypes": null, + "Contract": null, + "SlaOnSite": null, + "SlaMainTimeToRepair": null, + "Type": null, + "RowVersion": "2020-01-31T13:30:42", + "Errors": null, + "HasErrors": false + }, + { + "Id": 2503, + "Name": "DUMMY 2", + "TypeId": 14, + "SlaOnSiteId": null, + "SlaMainTimeToRepairId": null, + "SlaLink": "", + "SlaDescription": "", + "Description": "", + "SpareOwner": "", + "StockLocation": "", + "StockContact": "", + "InternetAddress": "", + "MasterAccount": "", + "EscalationDescription": "", + "Color": "", + "IssuerCodeEsim": null, + "MnoCode": "", + "EumId": "", + "EquipmentDefinitions": null, + "ManagementSystems": null, + "CardCodes": null, + "CardDefinitions": null, + "CableTypes": null, + "VendorRelatedContacts": null, + "VendorMaterialTypes": null, + "Contract": null, + "SlaOnSite": null, + "SlaMainTimeToRepair": null, + "Type": null, + "RowVersion": "2020-01-31T13:30:42", + "Errors": null, + "HasErrors": false + } + ] +} \ No newline at end of file diff --git a/test/test_ims_data.py b/test/test_ims_data.py index 3afd06359eec764108ab0889c23824aa62ecccfe..4a951ec054df8df4397189dc4c2de7f826e75cc8 100644 --- a/test/test_ims_data.py +++ b/test/test_ims_data.py @@ -2,7 +2,8 @@ import json import inventory_provider from inventory_provider.db.ims import InventoryStatus -from inventory_provider.db.ims_data import lookup_pop_info, lookup_lg_routers +from inventory_provider.db.ims_data import lookup_pop_info, lookup_lg_routers, \ + otrs_get_customer_company_rows def test_lookup_lg_routers(mocker): @@ -29,7 +30,7 @@ def test_lookup_lg_routers(mocker): } ds = inventory_provider.db.ims.IMS( - 'dummy_base', 'dmmy_username', 'dummy_password') + 'dummy_base', 'dummy_username', 'dummy_password') res = list(lookup_lg_routers(ds)) @@ -66,7 +67,7 @@ def test_lookup_pop_info(mocker): ims.return_value.get_entity_by_id.return_value = resp_data['site'] ds = inventory_provider.db.ims.IMS( - 'dummy_base', 'dmmy_username', 'dummy_password') + 'dummy_base', 'dummy_username', 'dummy_password') res = lookup_pop_info(ds, 'dummy_host') ds.get_entity_by_name.assert_called_once_with('Node', 'dummy_host') ds.get_entity_by_id.assert_called_once_with( @@ -83,3 +84,30 @@ def test_lookup_pop_info(mocker): 'latitude': 50.10166667, } } + + +def test_otrs_get_customer_company_rows(mocker): + ims = mocker.patch('inventory_provider.db.ims.IMS') + with open('test/data/ims_otrs_customers.json') as data: + resp_data = json.load(data) + + def se(*args, **kargs): + return resp_data[args[0]] + mocked_get_all_entities = ims.return_value.get_all_entities + mocked_get_all_entities.side_effect = se + ds = inventory_provider.db.ims.IMS( + 'dummy_base', 'dummy_username', 'dummy_password') + cus_comp_rows = list(otrs_get_customer_company_rows(ds)) + assert len(cus_comp_rows) == 6 + mocked_get_all_entities.assert_any_call('Customer') + mocked_get_all_entities.assert_any_call('Vendor') + assert cus_comp_rows[0] == ['customer_id', 'name', 'street', 'zip', + 'city', 'country', 'url', 'comments'] + ids = [] + names = [] + for row in cus_comp_rows[1:]: + assert len(row) == 8 + ids.append(row[0]) + names.append(row[1]) + assert ids == ['DUMMY1', 'DUMMY2', 'DUMMY3', 'DUMMY4', 'DUMMY5'] + assert names == ['DUMMY 1', 'DUMMY 2', 'DUMMY 3', 'DUMMY 4', 'DUMMY 5']