コード例 #1
0
def test_parsing_files_with_many_scenarios_returns_parsed_scenarios():
    class DoSomethingAction(ActionBase):
        regex = r'I do something$'
        def execute(context, *args, **kwargs):
            pass

    class DoSomethingElseAction(ActionBase):
        regex = r'I do something else$'
        def execute(context, *args, **kwargs):
            pass

    class DoYetAnotherThingAction(ActionBase):
        regex = r'I do yet another thing$'
        def execute(context, *args, **kwargs):
            pass

    settings = Settings()
    settings.tests_dirs = [abspath(dirname(__file__))]
    settings.file_pattern = "some_test.acc"

    parser = FileParser()

    fixture = parser.get_stories(settings=settings)

    assert_no_invalid_stories(fixture)

    assert len(fixture.stories) == 1, "Expected 1, Actual: %d" % len(fixture.stories)
    assert len(fixture.stories[0].scenarios) == 2
    assert "#some custom comment" in fixture.stories[0].scenarios[1].whens[0].description
コード例 #2
0
ファイル: test_file_parser.py プロジェクト: sardor9/pyccuracy
def test_parsing_files_with_many_scenarios_returns_parsed_scenarios():
    class DoSomethingAction(ActionBase):
        regex = r'I do something$'

        def execute(context, *args, **kwargs):
            pass

    class DoSomethingElseAction(ActionBase):
        regex = r'I do something else$'

        def execute(context, *args, **kwargs):
            pass

    class DoYetAnotherThingAction(ActionBase):
        regex = r'I do yet another thing$'

        def execute(context, *args, **kwargs):
            pass

    settings = Settings()
    settings.tests_dirs = [abspath(dirname(__file__))]
    settings.file_pattern = "some_test.acc"

    parser = FileParser()

    fixture = parser.get_stories(settings=settings)

    assert_no_invalid_stories(fixture)

    assert len(
        fixture.stories) == 1, "Expected 1, Actual: %d" % len(fixture.stories)
    assert len(fixture.stories[0].scenarios) == 2
    assert "#some custom comment" in fixture.stories[0].scenarios[1].whens[
        0].description
コード例 #3
0
def test_parsing_folder_with_no_stories_returns_empty_list():
    settings = Settings()
    settings.tests_dirs = [abspath(join(dirname(__file__), "no_stories_folder"))]
    parser = FileParser()

    fixture = parser.get_stories(settings=settings)
    assert len(fixture.stories) == 0
コード例 #4
0
ファイル: test_file_parser.py プロジェクト: sardor9/pyccuracy
def test_parsing_folder_with_no_stories_returns_empty_list():
    settings = Settings()
    settings.tests_dirs = [
        abspath(join(dirname(__file__), "no_stories_folder"))
    ]
    parser = FileParser()

    fixture = parser.get_stories(settings=settings)
    assert len(fixture.stories) == 0
コード例 #5
0
def test_parsing_files_with_wrong_so_that_returns_no_story_header_list():
    settings = Settings()
    settings.tests_dirs = [abspath(join(dirname(__file__), "invalid_content_stories"))]
    settings.file_pattern = "invalid_so_that.acc"

    parser = FileParser()

    fixture = parser.get_stories(settings=settings)

    assert len(fixture.no_story_header) == 1
    file_path = fixture.no_story_header[0]
    assert file_path.endswith("invalid_so_that.acc")
コード例 #6
0
ファイル: test_file_parser.py プロジェクト: sardor9/pyccuracy
def test_parsing_files_with_wrong_i_want_to_returns_no_story_header_list():
    settings = Settings()
    settings.tests_dirs = [
        abspath(join(dirname(__file__), "invalid_content_stories"))
    ]
    settings.file_pattern = "invalid_i_want_to.acc"

    parser = FileParser()

    fixture = parser.get_stories(settings=settings)

    assert len(fixture.no_story_header) == 1
    file_path = fixture.no_story_header[0]
    assert file_path.endswith("invalid_i_want_to.acc")
コード例 #7
0
    def run_tests(self, context=None, fso=None, **kwargs):
        settings = Settings(kwargs)
        if not context:
            context = Context(settings)

        if not self.runner:
            self.runner = context.settings.worker_threads == 1 and StoryRunner() or ParallelStoryRunner(settings.worker_threads)

        for directory in context.settings.hooks_dir:
            self.import_extra_content(directory, fso=fso)
        
        for directory in context.settings.pages_dir:
            self.import_extra_content(directory, fso=fso)

        if context.settings.custom_actions_dir != context.settings.pages_dir:
            for directory in context.settings.custom_actions_dir:
                self.import_extra_content(directory, fso=fso)
        
        try:
            fixture = self.parser.get_stories(settings)
        except ActionNotFoundError, err:
            self.print_invalid_action(context.settings.default_culture, err)
            if settings.should_throw:
                raise TestFailedError("The test failed!")
            else:
                return None
コード例 #8
0
ファイル: test_page_registry.py プロジェクト: irae/pyccuracy
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
コード例 #9
0
def test_parsing_files_with_empty_content_returns_invalid_files_list():

    mocker = Mocker()

    settings = Settings()
    files = ["some path"]

    story_text = ""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")
    language_mock.get("no_header_failure")
    mocker.result("No header found")

    with mocker:
        parser = FileParser(language=language_mock, file_object=filemock)

        fixture = parser.get_stories(settings=settings)
        assert len(fixture.no_story_header) == 1
        file_path = fixture.no_story_header[0]
        assert file_path == "some path"
コード例 #10
0
def test_parsing_files_with_proper_header_returns_parsed_scenario():

    mocker = Mocker()

    settings = Settings()
    files = ["some path"]

    story_text = """As a someone
I want to do something
So that I'm happy"""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")

    with mocker:
        parser = FileParser(language=language_mock, file_object=filemock)

        fixture = parser.get_stories(settings=settings)
        assert len(fixture.stories) == 1
        assert fixture.stories[0].as_a == "someone"
        assert fixture.stories[0].i_want_to == "do something"
        assert fixture.stories[0].so_that == "I'm happy"
コード例 #11
0
def test_see_summary_for_fixture_returns_proper_string_for_failed_tests():

    mocker = Mocker()

    expected = """================
Test Run Summary
================

Status: FAILED

Test Data Stats
---------------
Successful Stories......0/1 (0.00%)
Failed Stories..........1/1 (100.00%)
Successful Scenarios....0/1 (0.00%)
Failed Scenarios........1/1 (100.00%)"""

    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template)

    with mocker:
        settings = Settings()
        fixture = Fixture()
        action = some_action()
        fixture.append_story(action.scenario.story)
        action.mark_as_failed()
        result = Result(fixture=fixture, template_loader=template_loader_mock)

        summary = result.summary_for(settings.default_culture)
        assert summary == expected
コード例 #12
0
def test_should_catch_assertion_error():

    mocker = Mocker()

    def action_failed_method(context, *args, **kwargs):
        assert False, "bla"

    settings = Settings()
    runner = StoryRunner()
    fixture = Fixture()
    action = some_action()
    fixture.append_story(action.scenario.story)
    action.execute_function = action_failed_method

    context = Object()
    context.browser_driver = mocker.mock()
    context.browser_driver.start_test("http://localhost")
    context.browser_driver.stop_test()
    context.settings = mocker.mock()
    context.settings.on_before_action
    mocker.result(None)
    context.settings.on_action_error
    mocker.result(None)
    context.language = mocker.mock()
    context.language.get('given')
    mocker.result('Given')

    with mocker:
        result = runner.run_stories(settings=settings,
                                    fixture=fixture,
                                    context=context)

        assert isinstance(action.error, AssertionError)
        assert action.error.message == "bla"
コード例 #13
0
def test_story_runner_returns_a_result_with_the_original_Fixture():

    mocker = Mocker()

    settings = Settings()
    fixture = Fixture()
    action = some_action()
    fixture.append_story(action.scenario.story)
    runner = StoryRunner()

    context = Object()
    context.browser_driver = mocker.mock()
    context.browser_driver.start_test("http://localhost")
    context.browser_driver.stop_test()
    context.settings = mocker.mock()
    context.settings.on_before_action
    mocker.result(None)
    context.settings.on_action_successful
    mocker.result(None)

    context.language = mocker.mock()
    context.language.get('given')
    mocker.result('Given')
    context.language.get('when')
    mocker.result('When')
    context.language.get('then')
    mocker.result('Then')

    with mocker:
        result = runner.run_stories(settings, fixture, context=context)

        assert result.fixture == fixture
コード例 #14
0
def test_should_handle_action_errors_successfully():

    mocker = Mocker()

    def action_failed_method(context, *args, **kwargs):
        raise ActionFailedError("bla")

    settings = Settings()
    runner = StoryRunner()
    fixture = Fixture()
    action = some_action()
    fixture.append_story(action.scenario.story)
    action.execute_function = action_failed_method

    context = Object()
    context.browser_driver = mocker.mock()
    context.browser_driver.start_test("http://localhost")
    context.browser_driver.stop_test()
    context.settings = mocker.mock()
    context.settings.on_before_action
    mocker.result(None)
    context.settings.on_action_error
    mocker.result(None)
    context.language = mocker.mock()
    context.language.get('given')
    mocker.result('Given')

    with mocker:
        result = runner.run_stories(settings=settings,
                                    fixture=fixture,
                                    context=context)

        assert fixture.get_status() == Status.Failed
コード例 #15
0
def test_should_execute_scenarios_successfully():

    mocker = Mocker()

    settings = Settings()
    runner = StoryRunner()
    fixture = Fixture()
    fixture.append_story(some_action().scenario.story)

    context = Object()
    context.browser_driver = mocker.mock()
    context.browser_driver.start_test("http://localhost")
    context.browser_driver.stop_test()
    context.settings = mocker.mock()
    context.settings.on_before_action
    mocker.result(None)
    context.settings.on_action_successful
    mocker.result(None)

    context.language = mocker.mock()
    context.language.get('given')
    mocker.result('Given')
    context.language.get('when')
    mocker.result('When')
    context.language.get('then')
    mocker.result('Then')

    with mocker:
        result = runner.run_stories(settings=settings,
                                    fixture=fixture,
                                    context=context)

        assert fixture.get_status() == Status.Successful
コード例 #16
0
def test_see_summary_for_fixture_returns_proper_string_for_no_tests():

    mocker = Mocker()

    expected = """================
Test Run Summary
================

Status: UNKNOWN

Test Data Stats
---------------
Successful Stories......0/0 (0.00%)
Failed Stories..........0/0 (0.00%)
Successful Scenarios....0/0 (0.00%)
Failed Scenarios........0/0 (0.00%)"""

    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template)

    with mocker:
        settings = Settings()
        fixture = Fixture()
        result = Result(fixture=fixture, template_loader=template_loader_mock)

        summary = result.summary_for(settings.default_culture)
        assert summary == expected
コード例 #17
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
コード例 #18
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
コード例 #19
0
ファイル: test_page_registry.py プロジェクト: irae/pyccuracy
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
コード例 #20
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
コード例 #21
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
コード例 #22
0
def test_selenium_driver_calls_proper_selenese_on_click_element():
    
    mocker = Mocker()
    
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.click("some")

    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
    
        driver.click_element("some")
コード例 #23
0
def test_selenium_driver_overrides_start_test_properly():
    
    mocker = Mocker()
    
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.start()

    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
    
        driver.start_test("http://localhost")
コード例 #24
0
def test_selenium_driver_calls_proper_selenese_on_wait_for_page():
    
    mocker = Mocker()
    
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.wait_for_page_to_load(30000)

    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
    
        driver.wait_for_page()
コード例 #25
0
def test_selenium_driver_overrides_page_open_properly():
    
    mocker = Mocker()
    
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.open("http://localhost")

    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
    
        driver.page_open("http://localhost")
コード例 #26
0
def test_selenium_driver_calls_proper_selenese_on_stop_test():
    
    mocker = Mocker()
    
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.stop()

    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
    
        driver.stop_test()
コード例 #27
0
def test_selenium_driver_calls_type_keys():
    
    mocker = Mocker()
    
    input_selector = "//some_xpath"
    text = "text to type"
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.type_keys(input_selector, text)
    
    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
        driver.type_keys(input_selector, text)
コード例 #28
0
def test_wait_for_presence():
    
    mocker = Mocker()
    
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.is_element_present('some element')
    mocker.result(True)
    selenium_mock.is_visible('some element')
    mocker.result(True)

    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
        driver.wait_for_element_present("some element", 1)
コード例 #29
0
def test_selenium_driver_calls_proper_selenese_on_get_title():
    
    mocker = Mocker()
    
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.get_title()
    mocker.result("Some title")

    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
    
        title = driver.get_title()
        assert title == "Some title"
コード例 #30
0
def test_selenium_driver_calls_get_eval():
    
    mocker = Mocker()
    
    javascript = "some javascript"
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.get_eval(javascript)
    mocker.result("ok")
    
    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
        
        assert driver.exec_js(javascript) == "ok"
コード例 #31
0
def test_selenium_driver_raises_on_start_test_when_selenium_cant_start():
    
    mocker = Mocker()
    
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.start()
    mocker.throw(DriverError("invalid usage"))

    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
    
        assert_raises(DriverError, driver.start_test, url="http://localhost", \
                      exc_pattern=re.compile(r"Error when starting selenium. Is it running ?"))
コード例 #32
0
def test_parsing_stories_returns_list():

    mocker = Mocker()

    settings = Settings()
    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result([])

    with mocker:
        parser = FileParser(file_object=filemock)

        fixture = parser.get_stories(settings=settings)
        assert isinstance(fixture, Fixture)
コード例 #33
0
def test_wait_for_disappear_works_even_when_is_visible_raises():
    
    mocker = Mocker()
    
    context = Context(Settings())
    selenium_mock = mocker.mock()
    selenium_mock.is_element_present('some element')
    mocker.count(min=1, max=None)
    mocker.result(True)
    selenium_mock.is_visible('some element')
    mocker.throw(Exception("ERROR: Element some element not found"))

    with mocker:
        driver = SeleniumDriver(context, selenium=selenium_mock)
        driver.wait_for_element_to_disappear("some element", 1)