Exemplo n.º 1
0
 def test_synchronize_catch_node_error(self, *unused):
     # Setup
     request = self.request()
     # Test
     strategy = strategies.ImporterStrategy()
     strategy.synchronize(request)
     self.assertEqual(len(request.summary.errors), 1)
     self.assertEqual(request.summary.errors[0].error_id, error.UnitDownloadError.ERROR_ID)
Exemplo n.º 2
0
 def test_synchronize_catch_unknown_exception(self, *unused):
     # Setup
     request = self.request()
     # Test
     strategy = strategies.ImporterStrategy()
     strategy.synchronize(request)
     self.assertEqual(len(request.summary.errors), 1)
     self.assertEqual(request.summary.errors[0].error_id, error.CaughtException.ERROR_ID)
Exemplo n.º 3
0
 def test_add_unit_exception(self, *unused):
     # Setup
     request = self.request()
     # Test
     unit = dict(unit_id='abc', type_id='T', unit_key={}, metadata={})
     strategy = strategies.ImporterStrategy()
     strategy.add_unit(request, unit)
     self.assertEqual(len(request.summary.errors), 1)
     self.assertEqual(request.summary.errors[0].error_id, error.AddUnitError.ERROR_ID)
Exemplo n.º 4
0
 def test_delete_units_exception(self, *unused):
     # Setup
     request = self.request()
     # Test
     unit = dict(unit_id='abc', type_id='T', unit_key={}, metadata={})
     inventory = UnitInventory(BASE_URL, [], [unit])
     strategy = strategies.ImporterStrategy()
     strategy._delete_units(request, inventory)
     self.assertEqual(len(request.summary.errors), 1)
     self.assertEqual(request.summary.errors[0].error_id, error.DeleteUnitError.ERROR_ID)
Exemplo n.º 5
0
 def test_cancel_at_delete_units(self):
     # Setup
     request = self.request(1)
     unit = dict(unit_id='abc', type_id='T', unit_key={}, metadata={})
     inventory = UnitInventory(BASE_URL, [], [unit])
     request.conduit.remove_unit = Mock()
     # Test
     strategy = strategies.ImporterStrategy()
     strategy._delete_units(request, inventory)
     self.assertEqual(request.cancel_event.call_count, 1)
     request.conduit.remove_unit.assert_not_called()
Exemplo n.º 6
0
 def test_cancel_at_add_units(self, mock_add_unit):
     # Setup
     request = self.request(1)
     request.downloader.download = Mock()
     unit = dict(unit_id='abc', type_id='T', unit_key={}, metadata={})
     units = [unit]
     manifest = TestManifest(units)
     inventory = UnitInventory(BASE_URL, manifest.get_units(), [])
     # Test
     strategy = strategies.ImporterStrategy()
     strategy._add_units(request, inventory)
     self.assertEqual(request.cancel_event.call_count, 1)
     self.assertEqual(mock_add_unit.call_count, 0)
Exemplo n.º 7
0
 def test_needs_update(self):
     # Setup
     path = os.path.join(self.tmp_dir, 'unit_1')
     with open(path, 'w+') as fp:
         fp.write('123')
     size = os.path.getsize(path)
     strategy = strategies.ImporterStrategy()
     # Test
     unit = {constants.STORAGE_PATH: path, constants.FILE_SIZE: size}
     self.assertFalse(strategy._needs_download(unit))
     unit = {constants.STORAGE_PATH: '&&&&&&&', constants.FILE_SIZE: size}
     self.assertTrue(strategy._needs_download(unit))
     unit = {constants.STORAGE_PATH: path, constants.FILE_SIZE: size + 1}
     self.assertTrue(strategy._needs_download(unit))
Exemplo n.º 8
0
 def test_cancel_just_before_downloading(self, mock_download):
     # Setup
     unit_id = str(uuid4())
     request = self.request(2)
     request.downloader.download = Mock()
     unit = dict(
         unit_id=unit_id,
         type_id='T',
         unit_key={},
         metadata={},
         storage_path=os.path.join(self.tmp_dir, unit_id),
         relative_path=os.path.join(self.tmp_dir, 'testing', unit_id))
     units = [unit]
     manifest = TestManifest(units)
     inventory = UnitInventory(BASE_URL, manifest.get_units(), [])
     # Test
     strategy = strategies.ImporterStrategy()
     strategy._add_units(request, inventory)
     self.assertEqual(request.cancel_event.call_count, 2)
     self.assertFalse(mock_download.called)
Exemplo n.º 9
0
 def test_get_parent_units_manifest_error(self, *unused):
     # Setup
     request = self.request()
     # Test
     strategy = strategies.ImporterStrategy()
     self.assertRaises(error.ManifestDownloadError, strategy._unit_inventory, request)
Exemplo n.º 10
0
 def test_get_parent_units_exception(self, *unused):
     # Setup
     request = self.request()
     # Test
     strategy = strategies.ImporterStrategy()
     self.assertRaises(error.GetParentUnitsError, strategy._unit_inventory, request)
Exemplo n.º 11
0
 def test_abstract(self):
     # Test
     strategy = strategies.ImporterStrategy()
     # Verify
     self.assertRaises(NotImplementedError, strategy._synchronize, None)