Example #1
0
 def test_t1_doesnt_match_donor(self):
     donor = self.donor
     donor.t1_codes.clear()
     donor.t1_codes.add(DonorCodeT1Factory(code='Another T1'))
     sheet = MockSimpleSheet([self.valid_row])
     _catalog_import_from_simple_sheet(sheet)
     # Form should add the missing t1 donor to the donor's t1_codes
     self.assertTrue(self.donor_t1 in self.donor.t1_codes.all())
Example #2
0
 def test_no_t1_specified(self):
     row = self.valid_row.copy()
     row['donor_t1'] = ''
     sheet = MockSimpleSheet([row])
     _catalog_import_from_simple_sheet(sheet)
     self.assertTrue(
         CatalogItem.objects.filter(
             item_code=self.valid_row['item_code']).exists())
Example #3
0
 def test_t1_doesnt_match_donor(self):
     donor = self.donor
     donor.t1_codes.clear()
     donor.t1_codes.add(DonorCodeT1Factory(code='Another T1'))
     sheet = MockSimpleSheet([self.valid_row])
     _catalog_import_from_simple_sheet(sheet)
     # Form should add the missing t1 donor to the donor's t1_codes
     self.assertTrue(self.donor_t1 in self.donor.t1_codes.all())
Example #4
0
 def test_max_errors(self):
     invalid_row = self.valid_row.copy()
     invalid_row['description'] = ''  # required field
     sheet = MockSimpleSheet([invalid_row for x in range(MAX_IMPORT_ERRORS - 1)])
     expected_msg = "Giving up after %d errors" % MAX_IMPORT_ERRORS
     try:
         _catalog_import_from_simple_sheet(sheet)
     except CatalogImportFailure as e:
         self.assertNotIn(expected_msg, e.errlist)
     else:
         self.fail("Expected CatalogImportFailure")
     sheet = MockSimpleSheet([invalid_row for x in range(MAX_IMPORT_ERRORS + 10)])
     try:
         _catalog_import_from_simple_sheet(sheet)
     except CatalogImportFailure as e:
         self.assertIn(expected_msg, e.errlist)
         self.assertEqual(MAX_IMPORT_ERRORS + 1, len(e.errlist))
     else:
         self.fail("Expected CatalogImportFailure")
Example #5
0
 def test_max_errors(self):
     invalid_row = self.valid_row.copy()
     invalid_row['description'] = ''  # required field
     sheet = MockSimpleSheet(
         [invalid_row for x in range(MAX_IMPORT_ERRORS - 1)])
     expected_msg = "Giving up after %d errors" % MAX_IMPORT_ERRORS
     try:
         _catalog_import_from_simple_sheet(sheet)
     except CatalogImportFailure as e:
         self.assertNotIn(expected_msg, e.errlist)
     else:
         self.fail("Expected CatalogImportFailure")
     sheet = MockSimpleSheet(
         [invalid_row for x in range(MAX_IMPORT_ERRORS + 10)])
     try:
         _catalog_import_from_simple_sheet(sheet)
     except CatalogImportFailure as e:
         self.assertIn(expected_msg, e.errlist)
         self.assertEqual(MAX_IMPORT_ERRORS + 1, len(e.errlist))
     else:
         self.fail("Expected CatalogImportFailure")
Example #6
0
 def test_exception_during_import(self):
     sheet = MockSimpleSheet([self.valid_row])
     with patch('catalog.utils.CatalogItemImportForm') as mock_form:
         mock_form.side_effect = TypeError
         with self.assertRaises(CatalogImportFailure):
             _catalog_import_from_simple_sheet(sheet)
Example #7
0
 def test_missing_columns(self):
     # mock sheet that's missing some columns
     sheet = MockSimpleSheet(col_names=['one', 'two', 'description'])
     with self.assertRaises(CatalogImportFailure):
         _catalog_import_from_simple_sheet(sheet)
Example #8
0
 def test_no_t1_specified(self):
     row = self.valid_row.copy()
     row['donor_t1'] = ''
     sheet = MockSimpleSheet([row])
     _catalog_import_from_simple_sheet(sheet)
     self.assertTrue(CatalogItem.objects.filter(item_code=self.valid_row['item_code']).exists())
Example #9
0
 def test_valid(self):
     sheet = MockSimpleSheet([self.valid_row])
     _catalog_import_from_simple_sheet(sheet)
     item = CatalogItem.objects.get(item_code=self.valid_row['item_code'])
     self.assertEqual(self.donor_t1, item.donor_t1)
Example #10
0
 def test_exception_during_import(self):
     sheet = MockSimpleSheet([self.valid_row])
     with patch('catalog.utils.CatalogItemImportForm') as mock_form:
         mock_form.side_effect = TypeError
         with self.assertRaises(CatalogImportFailure):
             _catalog_import_from_simple_sheet(sheet)
Example #11
0
 def test_missing_columns(self):
     # mock sheet that's missing some columns
     sheet = MockSimpleSheet(col_names=['one', 'two', 'description'])
     with self.assertRaises(CatalogImportFailure):
         _catalog_import_from_simple_sheet(sheet)
Example #12
0
 def test_valid(self):
     sheet = MockSimpleSheet([self.valid_row])
     _catalog_import_from_simple_sheet(sheet)
     item = CatalogItem.objects.get(item_code=self.valid_row['item_code'])
     self.assertEqual(self.donor_t1, item.donor_t1)