Пример #1
0
def test_get_suitable_action_appropriately_for_page_actions_ptbr():
    # Reset action regexes (this is necessary because pyccuracy was not built
    # to run 2 different languages in the same execution, then we do this to 
    # allow appropriate testing)
    PageGoToAction.regex = LanguageItem('page_go_to_regex')
    PageGoToWithParametersAction.regex = LanguageItem('page_go_to_with_parameters_regex')
    
    Action, args, kw = ActionRegistry.suitable_for(u'Eu navego para Uma Pagina', 'pt-br')
    assert issubclass(Action, PageGoToAction)
    assert kw['url'] == u'Uma Pagina'

    Action, args, kw = ActionRegistry.suitable_for(u'Eu navego para Pagina de Blog do usuario "nome"', 'pt-br')
    assert issubclass(Action, PageGoToWithParametersAction)
    assert kw['url'] == u'Pagina de Blog'
    assert kw['parameters'] == u'usuario "nome"'

    Action, args, kw = ActionRegistry.suitable_for(u'Eu navego para Pagina de Busca para query "palavra"', 'pt-br')
    assert issubclass(Action, PageGoToWithParametersAction)
    assert kw['url'] == u'Pagina de Busca'
    assert kw['parameters'] == u'query "palavra"'

    Action, args, kw = ActionRegistry.suitable_for(u'Eu navego para Pagina de Config com parameter1 "value1", parameter2 "value2"', 'pt-br')
    assert issubclass(Action, PageGoToWithParametersAction)
    assert kw['url'] == u'Pagina de Config'
    assert kw['parameters'] == u'parameter1 "value1", parameter2 "value2"'
Пример #2
0
def test_action_registry_can_resolve_same_name_classes():

    mocker = Mocker()

    class MyActionSameName(ActionBase):
        regex = r'I do (\w+) very well'

        def execute(self, context, *args, **kw):
            pass

    Temp1 = MyActionSameName

    class MyActionSameName(ActionBase):
        regex = r'I do (\w+) very bad'

        def execute(self, context, *args, **kw):
            pass

    Temp2 = MyActionSameName

    language_getter_mock = mocker.mock()
    language_getter_mock.get(ANY)
    mocker.count(min=1, max=None)
    mocker.result('^$')

    with mocker:
        Action1, args1, kwargs1 = ActionRegistry.suitable_for(
            'I do test very well', 'en-us', getter=language_getter_mock)
        Action2, args2, kwargs2 = ActionRegistry.suitable_for(
            'I do test very bad', 'en-us', getter=language_getter_mock)
        assert Action1 is not MyActionSameName
        assert Action1 is not Temp2
        assert Action1 is Temp1
        assert Action2 is Temp2
        assert Action2 is MyActionSameName
Пример #3
0
def test_get_suitable_action():
    Action, args, kw = ActionRegistry.suitable_for(u'I see "Welcome to Pyccuracy" title', 'en-us')
    assert Action, "Action cannot be None"
    assert issubclass(Action, ActionBase)
    assert isinstance(args, (list, tuple))
    assert isinstance(kw, dict)
    assert args[1] == u'Welcome to Pyccuracy'
Пример #4
0
def test_action_registry_suitable_for_returns_type_on_match():
    class FooTitleAction(ActionBase):
        regex = r'I see "foo" title'
        def execute(self, context, *args, **kwargs):
            pass

    Action, args, kwargs = ActionRegistry.suitable_for('I see "foo" title', 'en-us')
    assert isinstance(Action, type)
Пример #5
0
def test_action_registry_suitable_for_returns_my_action_without_language_item():
    class MyActionNoLanguage(ActionBase):
        regex = r'^I do (\w+)\s(\w+) so proudly$'
        def execute(self, context, *args, **kw):
            pass

    language_getter_mock = Mock()
    language_getter_mock.expects(at_least_once()).method('get').will(return_value('^$'))
    Action, args, kwargs = ActionRegistry.suitable_for('I do unit test so proudly', 'en-us', getter=language_getter_mock)
    assert Action is MyActionNoLanguage
Пример #6
0
def test_action_registry_suitable_for_raises_when_language_getter_can_not_resolve():
    class MyActionLanguage(ActionBase):
        regex = LanguageItem('foo_bar_regex1')
        def execute(self, context, *args, **kw):
            pass

    language_getter_mock = Mock()
    language_getter_mock.expects(at_least_once()).method('get').will(return_value('^$'))
    language_getter_mock.expects(once()).get(eq(LanguageItem('foo_bar_regex1'))).will(return_value(None))
    Action, args, kwargs = ActionRegistry.suitable_for('Something blabla', 'en-us', getter=language_getter_mock)
Пример #7
0
def test_get_suitable_action_appropriately_for_page_actions_enus():
    Action, args, kw = ActionRegistry.suitable_for(u'I go to My Page', 'en-us')
    assert issubclass(Action, PageGoToAction)
    assert kw['url'] == u'My Page'
    
    Action, args, kw = ActionRegistry.suitable_for(u'I go to My Page for parameter "value"', 'en-us')
    assert issubclass(Action, PageGoToWithParametersAction)
    assert kw['url'] == u'My Page'
    assert kw['parameters'] == u'parameter "value"'

    Action, args, kw = ActionRegistry.suitable_for(u'I go to My Page of parameter "value"', 'en-us')
    assert issubclass(Action, PageGoToWithParametersAction)
    assert kw['url'] == u'My Page'
    assert kw['parameters'] == u'parameter "value"'
    
    Action, args, kw = ActionRegistry.suitable_for(u'I go to My Page with parameter1 "value1", parameter2 "value2"', 'en-us')
    assert issubclass(Action, PageGoToWithParametersAction)
    assert kw['url'] == u'My Page'
    assert kw['parameters'] == u'parameter1 "value1", parameter2 "value2"'
Пример #8
0
def test_action_registry_suitable_for_returns_my_action():
    class MyAction(ActionBase):
        regex = LanguageItem('foo_bar_regex')
        def execute(self, context, *args, **kw):
            pass

    language_getter_mock = Mock()
    language_getter_mock.expects(at_least_once()).method('get').will(return_value('^$'))
    language_getter_mock.expects(once()).get(eq(LanguageItem('foo_bar_regex'))).will(return_value('My regex .+'))
    Action, args, kwargs = ActionRegistry.suitable_for('My regex baz', 'en-us', getter=language_getter_mock)
    language_getter_mock.verify()
    assert Action is MyAction
Пример #9
0
def test_action_registry_can_resolve_same_name_classes():
    class MyActionSameName(ActionBase):
        regex = r'I do (\w+) very well'
        def execute(self, context, *args, **kw):
            pass
    Temp1 = MyActionSameName

    class MyActionSameName(ActionBase):
        regex = r'I do (\w+) very bad'
        def execute(self, context, *args, **kw):
            pass
    Temp2 = MyActionSameName

    language_getter_mock = Mock()
    language_getter_mock.expects(at_least_once()).method('get').will(return_value('^$'))

    Action1, args1, kwargs1 = ActionRegistry.suitable_for('I do test very well', 'en-us', getter=language_getter_mock)
    Action2, args2, kwargs2 = ActionRegistry.suitable_for('I do test very bad', 'en-us', getter=language_getter_mock)
    assert Action1 is not MyActionSameName
    assert Action1 is not Temp2
    assert Action1 is Temp1
    assert Action2 is Temp2
    assert Action2 is MyActionSameName
Пример #10
0
def test_action_registry_can_resolve_same_name_classes():

    mocker = Mocker()

    class MyActionSameName(ActionBase):
        regex = r"I do (\w+) very well"

        def execute(self, context, *args, **kw):
            pass

    Temp1 = MyActionSameName

    class MyActionSameName(ActionBase):
        regex = r"I do (\w+) very bad"

        def execute(self, context, *args, **kw):
            pass

    Temp2 = MyActionSameName

    language_getter_mock = mocker.mock()
    language_getter_mock.get(ANY)
    mocker.count(min=1, max=None)
    mocker.result("^$")

    with mocker:
        Action1, args1, kwargs1 = ActionRegistry.suitable_for(
            "I do test very well", "en-us", getter=language_getter_mock
        )
        Action2, args2, kwargs2 = ActionRegistry.suitable_for(
            "I do test very bad", "en-us", getter=language_getter_mock
        )
        assert Action1 is not MyActionSameName
        assert Action1 is not Temp2
        assert Action1 is Temp1
        assert Action2 is Temp2
        assert Action2 is MyActionSameName
Пример #11
0
def test_action_registry_suitable_for_raises_when_language_getter_can_not_resolve():

    mocker = Mocker()

    class MyActionLanguage(ActionBase):
        regex = LanguageItem("foo_bar_regex1")

        def execute(self, context, *args, **kw):
            pass

    language_getter_mock = mocker.mock()
    language_getter_mock.get(LanguageItem("foo_bar_regex1"))
    mocker.result(None)
    language_getter_mock.get(ANY)
    mocker.count(min=1, max=None)
    mocker.result("^$")

    with mocker:
        Action, args, kwargs = ActionRegistry.suitable_for("Something blabla", "en-us", getter=language_getter_mock)
Пример #12
0
def test_action_registry_suitable_for_returns_my_action_without_language_item():

    mocker = Mocker()

    class MyActionNoLanguage(ActionBase):
        regex = r"^I do (\w+)\s(\w+) so proudly$"

        def execute(self, context, *args, **kw):
            pass

    language_getter_mock = mocker.mock()
    language_getter_mock.get(ANY)
    mocker.count(min=1, max=None)
    mocker.result("^$")

    with mocker:
        Action, args, kwargs = ActionRegistry.suitable_for(
            "I do unit test so proudly", "en-us", getter=language_getter_mock
        )
        assert Action is MyActionNoLanguage
Пример #13
0
def test_action_registry_suitable_for_returns_my_action_without_language_item(
):

    mocker = Mocker()

    class MyActionNoLanguage(ActionBase):
        regex = r'^I do (\w+)\s(\w+) so proudly$'

        def execute(self, context, *args, **kw):
            pass

    language_getter_mock = mocker.mock()
    language_getter_mock.get(ANY)
    mocker.count(min=1, max=None)
    mocker.result('^$')

    with mocker:
        Action, args, kwargs = ActionRegistry.suitable_for(
            'I do unit test so proudly', 'en-us', getter=language_getter_mock)
        assert Action is MyActionNoLanguage
Пример #14
0
def test_action_registry_suitable_for_returns_my_action():

    mocker = Mocker()

    class MyAction(ActionBase):
        regex = LanguageItem("foo_bar_regex")

        def execute(self, context, *args, **kw):
            pass

    language_getter_mock = mocker.mock()
    language_getter_mock.get(LanguageItem("foo_bar_regex"))
    mocker.result("My regex .+")
    language_getter_mock.get(ANY)
    mocker.count(min=1, max=None)
    mocker.result("^$")

    with mocker:
        Action, args, kwargs = ActionRegistry.suitable_for("My regex baz", "en-us", getter=language_getter_mock)
        assert Action is MyAction
Пример #15
0
def test_action_registry_suitable_for_raises_when_language_getter_can_not_resolve(
):

    mocker = Mocker()

    class MyActionLanguage(ActionBase):
        regex = LanguageItem('foo_bar_regex1')

        def execute(self, context, *args, **kw):
            pass

    language_getter_mock = mocker.mock()
    language_getter_mock.get(LanguageItem('foo_bar_regex1'))
    mocker.result(None)
    language_getter_mock.get(ANY)
    mocker.count(min=1, max=None)
    mocker.result('^$')

    with mocker:
        Action, args, kwargs = ActionRegistry.suitable_for(
            'Something blabla', 'en-us', getter=language_getter_mock)
Пример #16
0
def test_action_registry_suitable_for_returns_my_action():

    mocker = Mocker()

    class MyAction(ActionBase):
        regex = LanguageItem('foo_bar_regex')

        def execute(self, context, *args, **kw):
            pass

    language_getter_mock = mocker.mock()
    language_getter_mock.get(LanguageItem('foo_bar_regex'))
    mocker.result('My regex .+')
    language_getter_mock.get(ANY)
    mocker.count(min=1, max=None)
    mocker.result('^$')

    with mocker:
        Action, args, kwargs = ActionRegistry.suitable_for(
            'My regex baz', 'en-us', getter=language_getter_mock)
        assert Action is MyAction
Пример #17
0
def test_do_not_get_suitable_action():
    Action, args, kw = ActionRegistry.suitable_for(u'Blah bluh foo bar', 'en-us')
    assert Action is None
    assert args is None
    assert kw is None