Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
def fetch(self, url):
if url in self.test_data:
return json.dumps(self.test_data[url])
return False
test_pr = ProviderRegistry()
test_cache = Cache()
test_pr_cache = ProviderRegistry(test_cache)
for pr in (test_pr, test_pr_cache):
pr.register('http://link\S*', TestProvider('link'))
pr.register('http://photo\S*', TestProvider('photo'))
pr.register('http://video\S*', TestProvider('video'))
pr.register('http://rich\S*', TestProvider('rich'))
class BaseTestCase(unittest.TestCase):
def setUp(self):
test_cache._cache = {}
self.full_pairs = {
'http://link-test1': '<a title="test1" href="http://link-test1">test1</a>',
'http://photo-test2': '<a title="ptest2" href="test2.jpg"><img src="test2.jpg" alt="ptest2"></a>',
'http://video-test1': 'video',
'http://rich-test2': 'rich',
'http://photo-notitle': '<a title="notitle.jpg" href="notitle.jpg"><img src="notitle.jpg" alt="notitle.jpg"></a>',
}
self.inline_pairs = {
'http://link-test1': '<a title="test1" href="http://link-test1">test1</a>',
def fetch(self, url):
if url in self.test_data:
return json.dumps(self.test_data[url])
return False
test_pr = ProviderRegistry()
test_cache = Cache()
test_pr_cache = ProviderRegistry(test_cache)
for pr in (test_pr, test_pr_cache):
pr.register('http://link\S*', TestProvider('link'))
pr.register('http://photo\S*', TestProvider('photo'))
pr.register('http://video\S*', TestProvider('video'))
pr.register('http://rich\S*', TestProvider('rich'))
class BaseTestCase(unittest.TestCase):
def setUp(self):
test_cache._cache = {}
self.full_pairs = {
'http://link-test1': '<a title="test1" href="http://link-test1">test1</a>',
'http://photo-test2': '<a title="ptest2" href="test2.jpg"><img src="test2.jpg" alt="ptest2"></a>',
'http://video-test1': 'video',
'http://rich-test2': 'rich',
'http://photo-notitle': '<a title="notitle.jpg" href="notitle.jpg"><img src="notitle.jpg" alt="notitle.jpg"></a>',
}
self.inline_pairs = {
'http://link-test1': '<a title="test1" href="http://link-test1">test1</a>',
'http://photo-test2': '<a title="ptest2" href="test2.jpg">ptest2</a>',
def test_register_unregister(self):
pr = ProviderRegistry()
provider1 = TestProvider('link')
provider2 = TestProvider('link')
pr.register('1', provider1)
pr.register('2', provider1)
pr.register('3', provider2)
pr.unregister('2')
self.assertEqual(len(pr._registry), 2)
# Multiple calls to remove() are OK.
self.assertRaises(KeyError, pr.unregister, '2')
self.assertEqual(pr.provider_for_url('1'), provider1)
self.assertEqual(pr.provider_for_url('2'), None)
self.assertEqual(pr.provider_for_url('3'), provider2)
pr.unregister('1')
pr.unregister('3')
def test_multiple_matches(self):
pr = ProviderRegistry()
provider1 = TestProvider('link')
provider2 = TestProvider('link')
pr.register('1(\d+)', provider1)
pr.register('1\d+', provider2)
self.assertEqual(pr.provider_for_url('11'), provider2)
pr.unregister('1\d+')
self.assertEqual(pr.provider_for_url('11'), provider1)
def test_multiple_matches(self):
pr = ProviderRegistry()
provider1 = TestProvider('link')
provider2 = TestProvider('link')
pr.register('1(\d+)', provider1)
pr.register('1\d+', provider2)
self.assertEqual(pr.provider_for_url('11'), provider2)
pr.unregister('1\d+')
self.assertEqual(pr.provider_for_url('11'), provider1)
def test_register_unregister(self):
pr = ProviderRegistry()
provider1 = TestProvider('link')
provider2 = TestProvider('link')
pr.register('1', provider1)
pr.register('2', provider1)
pr.register('3', provider2)
pr.unregister('2')
self.assertEqual(len(pr._registry), 2)
# Multiple calls to remove() are OK.
self.assertRaises(KeyError, pr.unregister, '2')
self.assertEqual(pr.provider_for_url('1'), provider1)
self.assertEqual(pr.provider_for_url('2'), None)
self.assertEqual(pr.provider_for_url('3'), provider2)
pr.unregister('1')
pr.unregister('3')
self.assertEqual(len(pr._registry), 0)
'photo?format=json&url=http%3A%2F%2Fphoto-notitle': {'url': 'notitle.jpg', 'type': 'photo'},
}
def fetch(self, url):
if url in self.test_data:
return json.dumps(self.test_data[url])
return False
test_pr = ProviderRegistry()
test_cache = Cache()
test_pr_cache = ProviderRegistry(test_cache)
for pr in (test_pr, test_pr_cache):
pr.register('http://link\S*', TestProvider('link'))
pr.register('http://photo\S*', TestProvider('photo'))
pr.register('http://video\S*', TestProvider('video'))
pr.register('http://rich\S*', TestProvider('rich'))
class BaseTestCase(unittest.TestCase):
def setUp(self):
test_cache._cache = {}
self.full_pairs = {
'http://link-test1': '<a title="test1" href="http://link-test1">test1</a>',
'http://photo-test2': '<a title="ptest2" href="test2.jpg"><img src="test2.jpg" alt="ptest2"></a>',
'http://video-test1': 'video',
'http://rich-test2': 'rich',
'http://photo-notitle': '<a title="notitle.jpg" href="notitle.jpg"><img src="notitle.jpg" alt="notitle.jpg"></a>',
}
self.inline_pairs = {
# no title
'photo?format=json&url=http%3A%2F%2Fphoto-notitle': {'url': 'notitle.jpg', 'type': 'photo'},
}
def fetch(self, url):
if url in self.test_data:
return json.dumps(self.test_data[url])
return False
test_pr = ProviderRegistry()
test_cache = Cache()
test_pr_cache = ProviderRegistry(test_cache)
for pr in (test_pr, test_pr_cache):
pr.register('http://link\S*', TestProvider('link'))
pr.register('http://photo\S*', TestProvider('photo'))
pr.register('http://video\S*', TestProvider('video'))
pr.register('http://rich\S*', TestProvider('rich'))
class BaseTestCase(unittest.TestCase):
def setUp(self):
test_cache._cache = {}
self.full_pairs = {
'http://link-test1': '<a title="test1" href="http://link-test1">test1</a>',
'http://photo-test2': '<a title="ptest2" href="test2.jpg"><img src="test2.jpg" alt="ptest2"></a>',
'http://video-test1': 'video',
'http://rich-test2': 'rich',
'http://photo-notitle': '<a title="notitle.jpg" href="notitle.jpg"><img src="notitle.jpg" alt="notitle.jpg"></a>',
}