How to use the micawber.test_utils.TestProvider function in micawber

To help you get started, we’ve selected a few micawber examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coleifer / micawber / micawber / test_utils.py View on Github external
}

    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>',
github coleifer / micawber / micawber / test_utils.py View on Github external
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>',
github coleifer / micawber / micawber / tests.py View on Github external
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')
github coleifer / micawber / micawber / tests.py View on Github external
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)
github coleifer / micawber / micawber / tests.py View on Github external
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)
github coleifer / micawber / micawber / tests.py View on Github external
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)
github coleifer / micawber / micawber / test_utils.py View on Github external
'photo?format=json&amp;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 = {
github coleifer / micawber / micawber / test_utils.py View on Github external
# no title
        'photo?format=json&amp;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>',
        }