Exemplo n.º 1
0
 def test_get_url_no_save(self, _):
     """ Calls to get_url() doesn't save if autocommit=False """
     cache = ICache(MagicMock())
     cache.autocommit = False
     with patch.object(cache, 'save') as save:
         package = make_package()
         cache.get_url(package)
         self.assertFalse(save.called)
Exemplo n.º 2
0
 def test_get_url_no_save(self, _):
     """ Calls to get_url() doesn't save if autocommit=False """
     cache = ICache(MagicMock())
     cache.autocommit = False
     with patch.object(cache, 'save') as save:
         package = make_package()
         cache.get_url(package)
         self.assertFalse(save.called)
Exemplo n.º 3
0
 def test_get_url_saves(self, _):
     """ Calls to get_url() saves to caching db if autocommit=True """
     cache = ICache(MagicMock())
     with patch.object(cache, 'save') as save:
         cache.autocommit = True
         package = make_package()
         cache.get_url(package)
         save.assert_called_with(package)
Exemplo n.º 4
0
 def test_get_url_no_save(self):
     """ Calls to get_url() doesn't save if changed=False """
     cache = ICache(MagicMock(), storage=MagicMock())
     cache.storage.get_url.return_value = 'a', False
     with patch.object(cache, 'save') as save:
         package = make_package()
         cache.get_url(package)
         self.assertFalse(save.called)
Exemplo n.º 5
0
 def test_configure_storage(self):
     """ Calling configure() sets up storage backend """
     config = MagicMock()
     config.get_settings.return_value = {
         'pypi.storage': 'tests.DummyStorage'
     }
     ICache.configure(config)
     self.assertEqual(ICache.storage_impl, DummyStorage)
Exemplo n.º 6
0
 def test_get_url_saves(self):
     """ Calls to get_url() saves to caching db if changed=True """
     cache = ICache(MagicMock(), storage=MagicMock())
     cache.storage.get_url.return_value = 'a', True
     with patch.object(cache, 'save') as save:
         package = make_package()
         cache.get_url(package)
         save.assert_called_with(package)
Exemplo n.º 7
0
 def test_get_url_no_save(self):
     """ Calls to get_url() doesn't save if changed=False """
     cache = ICache(MagicMock(), storage=MagicMock())
     cache.storage.get_url.return_value = "a", False
     with patch.object(cache, "save") as save:
         package = make_package()
         cache.get_url(package)
         self.assertFalse(save.called)
Exemplo n.º 8
0
 def test_get_url_saves(self):
     """ Calls to get_url() saves to caching db if changed=True """
     cache = ICache(MagicMock(), storage=MagicMock())
     cache.storage.get_url.return_value = "a", True
     with patch.object(cache, "save") as save:
         package = make_package()
         cache.get_url(package)
         save.assert_called_with(package)
Exemplo n.º 9
0
 def test_configure_storage(self):
     """ Calling configure() sets up storage backend """
     config = MagicMock()
     config.get_settings.return_value = {
         'pypi.storage': 'tests.DummyStorage'
     }
     ICache.configure(config)
     self.assertEqual(ICache.storage_impl, DummyStorage)
Exemplo n.º 10
0
 def test_get_url_saves(self, _):
     """ Calls to get_url() saves to caching db if autocommit=True """
     cache = ICache(MagicMock())
     with patch.object(cache, 'save') as save:
         cache.autocommit = True
         package = make_package()
         cache.get_url(package)
         save.assert_called_with(package)
Exemplo n.º 11
0
 def test_configure_storage(self):
     """ Calling configure() sets up storage backend """
     settings = {
         'pypi.storage': 'tests.DummyStorage'
     }
     kwargs = ICache.configure(settings)
     self.assertTrue(isinstance(kwargs['storage'](), DummyStorage))
Exemplo n.º 12
0
 def test_abstract_methods(self):
     """ Abstract methods raise exception """
     settings = {"pypi.storage": "tests.DummyStorage"}
     kwargs = ICache.configure(settings)
     cache = ICache(**kwargs)
     with self.assertRaises(NotImplementedError):
         cache.distinct()
     with self.assertRaises(NotImplementedError):
         cache.fetch("pkg-1.1.tar.gz")
     with self.assertRaises(NotImplementedError):
         cache.all("pkg")
     with self.assertRaises(NotImplementedError):
         cache.clear(make_package())
     with self.assertRaises(NotImplementedError):
         cache.clear_all()
     with self.assertRaises(NotImplementedError):
         cache.save(make_package())
Exemplo n.º 13
0
 def test_no_reload_if_needed(self, distinct, reload_pkgs):
     """ Don't reload the cache if it's not necessary """
     distinct.return_value = ['hi']
     ICache.reload_if_needed()
     self.assertFalse(reload_pkgs.called)
Exemplo n.º 14
0
 def test_abstract_methods(self):
     """ Abstract methods raise exception """
     config = MagicMock()
     config.get_settings.return_value = {
         'pypi.storage': 'tests.DummyStorage'
     }
     ICache.configure(config)
     cache = ICache()
     with self.assertRaises(NotImplementedError):
         cache.distinct()
     with self.assertRaises(NotImplementedError):
         cache.fetch('pkg', '1.1')
     with self.assertRaises(NotImplementedError):
         cache.all('pkg')
     with self.assertRaises(NotImplementedError):
         cache.clear(make_package())
     with self.assertRaises(NotImplementedError):
         cache.clear_all()
     with self.assertRaises(NotImplementedError):
         cache.save(make_package())
Exemplo n.º 15
0
 def test_abstract_methods(self):
     """ Abstract methods raise exception """
     settings = {"pypi.storage": "tests.DummyStorage"}
     kwargs = ICache.configure(settings)
     cache = ICache(**kwargs)
     with self.assertRaises(NotImplementedError):
         cache.distinct()
     with self.assertRaises(NotImplementedError):
         cache.fetch("pkg-1.1.tar.gz")
     with self.assertRaises(NotImplementedError):
         cache.all("pkg")
     with self.assertRaises(NotImplementedError):
         cache.clear(make_package())
     with self.assertRaises(NotImplementedError):
         cache.clear_all()
     with self.assertRaises(NotImplementedError):
         cache.save(make_package())
Exemplo n.º 16
0
 def test_abstract_methods(self):
     """ Abstract methods raise exception """
     config = MagicMock()
     config.get_settings.return_value = {
         'pypi.storage': 'tests.DummyStorage'
     }
     ICache.configure(config)
     cache = ICache()
     with self.assertRaises(NotImplementedError):
         cache.distinct()
     with self.assertRaises(NotImplementedError):
         cache.fetch('pkg', '1.1')
     with self.assertRaises(NotImplementedError):
         cache.all('pkg')
     with self.assertRaises(NotImplementedError):
         cache.clear(make_package())
     with self.assertRaises(NotImplementedError):
         cache.clear_all()
     with self.assertRaises(NotImplementedError):
         cache.save(make_package())
Exemplo n.º 17
0
 def test_no_reload_if_needed(self, distinct, reload_pkgs):
     """ Don't reload the cache if it's not necessary """
     distinct.return_value = ['hi']
     ICache.reload_if_needed()
     self.assertFalse(reload_pkgs.called)