Example #1
0
def test_page_registry_resolve_by_page_class_name_with_base_url_get_right_url():
    class MyPage(Page):
        url = 'blabla'

    PageGot, url = PageRegistry.resolve(Settings({'base_url': 'http://pyccuracy.org'}), 'My Page', exists_func=fake_abs)
    assert PageGot is MyPage, 'The page resolved by "My Page" should be a type class: MyPage. Got %r.' % PageGot
    assert url == 'http://pyccuracy.org/blabla', 'The url must be http://pyccuracy.org concatenated with "/" and "blabla". Got "%s".' % url
Example #2
0
def test_page_registry_resolve_by_page_class_name_with_base_url_get_right_url_without_slash_left():
    class MyPage(Page):
        url = 'blabla'

    PageGot, url = PageRegistry.resolve(Settings(dict(tests_dir='home'), cur_dir='home', abspath_func=fake_abs), 'My Page', abspath_func=fake_abs, exists_func=fake_abs)

    assert PageGot is MyPage, 'The page resolved by "My Page" should be a type class: MyPage. Got %r.' % PageGot
    assert url == 'file:///home/blabla', 'The url must be "file:///home" concatenated with "/" and "blabla". Got "%s".' % url
Example #3
0
def test_page_registry_resolve_page_by_url_without_base_url_without_slash():
    PageGot, url = PageRegistry.resolve(Settings(dict(tests_dir='/test/'),
                                                 cur_dir='/test'),
                                        'my_url',
                                        exists_func=fake_abs)

    assert PageGot is None, 'The page resolved by "my_url" should be a type class: MyPage. Got %r.' % PageGot
    assert url == 'file:///test/my_url', 'The url must be "file:///test/my_url". Got "%s".' % url
Example #4
0
def test_page_registry_resolve_by_url_without_base_url_without_page_without_slash_right(
):
    PageGot, url = PageRegistry.resolve(Settings(cur_dir='/test'),
                                        'file.html',
                                        exists_func=fake_abs)

    assert PageGot is None, 'The page resolved by "file.html" should be None. Got %r.' % PageGot
    assert url == 'file:///test/file.html', 'The url must be "file:///test/file.html". Got "%s".' % url
Example #5
0
def test_page_registry_resolve_by_page_class_name_get_right_class():
    class MyPage(Page):
        url = 'blabla'

    PageGot, url = PageRegistry.resolve(Settings(),
                                        'My Page',
                                        exists_func=fake_abs)
    assert PageGot is MyPage, 'The page resolved by "My Page" should be a type class: MyPage. Got %r.' % PageGot
Example #6
0
def test_page_registry_resolve_page_by_url_with_base_url():
    PageGot, url = PageRegistry.resolve(Settings(
        {'base_url': 'https://github.com/heynemann/pyccuracy/wiki'}),
                                        'my_url',
                                        exists_func=fake_abs)

    assert PageGot is None, 'The page resolved by "my_url" should be a type class: MyPage. Got %r.' % PageGot
    assert url == 'https://github.com/heynemann/pyccuracy/wiki/my_url', 'The url must be "https://github.com/heynemann/pyccuracy/wiki/my_url". Got "%s".' % url
Example #7
0
    def execute(self, context, url):
        page, resolved_url = PageRegistry.resolve(context.settings, url, must_raise=False)

        if page:
            # If the resolved page is the same as the current one, 
            # there's not need to override the context page, risking
            # losing all the re-registered elements of the users.
            if not isinstance(context.current_page, page):
                context.current_page = page()
                if hasattr(context.current_page, "register"):
                    context.current_page.register()
            context.url = resolved_url
        else:
            raise self.failed(context.language.format("page_am_in_failure", url))
Example #8
0
    def execute(self, context, url):
        page, resolved_url = PageRegistry.resolve(context.settings,
                                                  url,
                                                  must_raise=False)

        if page:
            # If the resolved page is the same as the current one,
            # there's not need to override the context page, risking
            # losing all the re-registered elements of the users.
            if not isinstance(context.current_page, page):
                context.current_page = page()
                if hasattr(context.current_page, "register"):
                    context.current_page.register()
            context.url = resolved_url
        else:
            raise self.failed(
                context.language.format("page_am_in_failure", url))
Example #9
0
    def execute(self, context, url):
        page, resolved_url = PageRegistry.resolve(context.settings, url.replace('"', ''), must_raise=False)

        if not resolved_url or (not url.startswith('"') and not page):
            raise self.failed(context.language.format("page_go_to_failure", url))

        context.browser_driver.page_open(resolved_url)
        context.browser_driver.wait_for_page()
        context.url = resolved_url
        if page:
            # If the resolved page is the same as the current one, 
            # there's not need to override the context page, risking
            # losing all the re-registered elements of the users.
            if not isinstance(context.current_page, page):
                context.current_page = page()
                if hasattr(context.current_page, "register"):
                    context.current_page.register()
Example #10
0
 def resolve_url(self, context, url):
     return PageRegistry.resolve(context.settings, url.replace('"', ''), must_raise=False)
Example #11
0
 def resolve_url(self, context, url):
     return PageRegistry.resolve(context.settings,
                                 url.replace('"', ''),
                                 must_raise=False)
def test_page_registry_resolve_page_by_url_without_base_url_without_slash():
    PageGot, url = PageRegistry.resolve(Settings(dict(tests_dir='/test/'), cur_dir='/test'), 'my_url', exists_func=fake_abs)

    assert PageGot is None, 'The page resolved by "my_url" should be a type class: MyPage. Got %r.' % PageGot
    assert url == 'file:///test/my_url', 'The url must be "file:///test/my_url". Got "%s".' % url
Example #13
0
 def do_resolve_fail():
     PageRegistry.resolve(Settings(), None, exists_func=fake_abs)
Example #14
0
def test_page_registry_does_not_raises_when_must_raise_is_false():
    assert PageRegistry.resolve(
        None, None, must_raise=False, exists_func=fake_abs) is None
Example #15
0
 def do_resolve_fail():
     PageRegistry.resolve(None, 'http://google.com', exists_func=fake_abs)
Example #16
0
 def do_resolve_fail():
     PageRegistry.resolve(None, None, exists_func=fake_abs)
 def do_resolve_fail():
     PageRegistry.resolve(None, 'http://google.com', exists_func=fake_abs)
def test_page_registry_resolve_by_url_without_base_url_without_page_without_slash_both():
    PageGot, url = PageRegistry.resolve(Settings(cur_dir='test', abspath_func=fake_abs), 'file.html', abspath_func=fake_abs, exists_func=fake_abs)

    assert PageGot is None, 'The page resolved by "file.html" should be None. Got %r.' % PageGot
    assert url == 'file:///test/file.html', 'The url must be "file:///test/file.html". Got "%s".' % url
def test_page_registry_resolve_page_by_url_with_base_url():
    PageGot, url = PageRegistry.resolve(Settings({'base_url': 'http://pyccuracy.org'}), 'my_url', exists_func=fake_abs)

    assert PageGot is None, 'The page resolved by "my_url" should be a type class: MyPage. Got %r.' % PageGot
    assert url == 'http://pyccuracy.org/my_url', 'The url must be "http://pyccuracy.org/my_url". Got "%s".' % url
 def do_resolve_fail():
     PageRegistry.resolve(None, None, exists_func=fake_abs)
 def do_resolve_fail():
     PageRegistry.resolve(Settings(), None, exists_func=fake_abs)
def test_page_registry_resolve_by_page_class_name_get_right_class():
    class MyPage(Page):
        url = 'blabla'

    PageGot, url = PageRegistry.resolve(Settings(), 'My Page', exists_func=fake_abs)
    assert PageGot is MyPage, 'The page resolved by "My Page" should be a type class: MyPage. Got %r.' % PageGot
def test_page_registry_does_not_raises_when_must_raise_is_false():
    assert PageRegistry.resolve(None, None, must_raise=False, exists_func=fake_abs) is None