diff --git a/tests/data/enum_options_with_search/sponsors.xls b/tests/data/enum_options_with_search/sponsors.xls new file mode 100644 index 00000000..7c6b1730 Binary files /dev/null and b/tests/data/enum_options_with_search/sponsors.xls differ diff --git a/tests/test_lookup_service.py b/tests/test_lookup_service.py index dda8772c..15157e46 100644 --- a/tests/test_lookup_service.py +++ b/tests/test_lookup_service.py @@ -176,3 +176,21 @@ class TestLookupService(BaseTest): first_result = result[0] self.assertEquals(1000, first_result['CUSTOMER_NUMBER']) self.assertEquals('UVA - INTERNAL - GM USE ONLY', first_result['CUSTOMER_NAME']) + + def test_lookup_fails_for_xls(self): + BaseTest.load_test_spec('enum_options_with_search') + + # Using an old xls file should raise an error + file_model_xls = session.query(FileModel).filter(FileModel.name == 'sponsors.xls').first() + file_data_model_xls = session.query(FileDataModel).filter(FileDataModel.file_model_id == file_model_xls.id).first() + with self.assertRaises(ApiError) as ae: + LookupService.build_lookup_table(file_data_model_xls, 'CUSTOMER_NUMBER', 'CUSTOMER_NAME') + self.assertIn('Error opening excel file', ae.exception.args[0]) + + # Using an xlsx file should work + file_model_xlsx = session.query(FileModel).filter(FileModel.name == 'sponsors.xlsx').first() + file_data_model_xlsx = session.query(FileDataModel).filter(FileDataModel.file_model_id == file_model_xlsx.id).first() + lookup_model = LookupService.build_lookup_table(file_data_model_xlsx, 'CUSTOMER_NUMBER', 'CUSTOMER_NAME') + self.assertEqual(28, len(lookup_model.dependencies)) + self.assertIn('CUSTOMER_NAME', lookup_model.dependencies[0].data.keys()) + self.assertIn('CUSTOMER_NUMBER', lookup_model.dependencies[0].data.keys())