Beispiel #1
0
def test_pyccuracy_core_run_tests():
    context_mock, fso_mock = make_context_and_fso_mocks()
    context_mock.settings.write_report = False
    context_mock.language = Mock()
    context_mock.language.key = "pt-br"

    context_mock.browser_driver.expects(once()).method('start_test')
    context_mock.browser_driver.expects(once()).method('stop_test')

    results_mock = Mock()
    suite_mock = Mock()
    suite_mock.no_story_header = []

    runner_mock = Mock()
    parser_mock = Mock()
    parser_mock.used_actions = []
    parser_mock.expects(once()).method('get_stories').will(return_value(suite_mock))
    runner_mock.expects(once()).method('run_stories').will(return_value(results_mock))

    results_mock.expects(once()).summary_for(eq('en-us')).will(return_value('my results'))
    pc = PyccuracyCore(parser_mock, runner_mock)
    
    assert pc.run_tests(should_throw=False, context=context_mock, fso=fso_mock) == results_mock

    parser_mock.verify()
    runner_mock.verify()
    context_mock.verify()
    results_mock.verify()
    suite_mock.verify()
    fso_mock.verify()
Beispiel #2
0
def test_pyccuracy_core_run_tests_works_when_None_Result_returned_from_story_runner():
    context_mock, fso_mock = make_context_and_fso_mocks()
    context_mock.browser_driver.expects(once()).method('start_test')
    context_mock.browser_driver.expects(once()).method('stop_test')
    context_mock.language = Mock()
    context_mock.language.key = "pt-br"

    suite_mock = Mock()
    suite_mock.no_story_header = []

    runner_mock = Mock()
    parser_mock = Mock()
    parser_mock.used_actions = []
    parser_mock.expects(once()).method('get_stories').will(return_value(suite_mock))
    runner_mock.expects(once()).method('run_stories').will(return_value(None))

    pc = PyccuracyCore(parser_mock, runner_mock)

    assert pc.run_tests(should_throw=False, context=context_mock, fso=fso_mock) == None

    parser_mock.verify()
    runner_mock.verify()
    context_mock.verify()
    suite_mock.verify()
    fso_mock.verify()
Beispiel #3
0
    def do_run_tests_should_throw():
        context_mock, fso_mock = make_context_and_fso_mocks()
        context_mock.settings.write_report = False

        context_mock.browser_driver.expects(once()).method("start_test")
        context_mock.browser_driver.expects(once()).method("stop_test")
        context_mock.language = Mock()
        context_mock.language.key = "key"

        results_mock = Mock()
        suite_mock = Mock()
        suite_mock.no_story_header = []

        runner_mock = Mock()
        parser_mock = Mock()
        parser_mock.used_actions = []

        parser_mock.expects(once()).method("get_stories").will(return_value(suite_mock))
        runner_mock.expects(once()).method("run_stories").will(return_value(results_mock))

        results_mock.expects(once()).summary_for(eq("en-us")).will(return_value(""))
        results_mock.expects(once()).get_status().will(return_value(Status.Failed))
        pc = PyccuracyCore(parser_mock, runner_mock)
        pc.run_tests(should_throw=True, context=context_mock, fso=fso_mock)

        parser_mock.verify()
        runner_mock.verify()
        context_mock.verify()
        results_mock.verify()
        suite_mock.verify()
        fso_mock.verify()
Beispiel #4
0
def test_pyccuracy_core_run_tests():
    mocker = Mocker()
    context_mock, fso_mock = make_context_and_fso_mocks(mocker)
    context_mock.settings.write_report
    mocker.result(False)

    suite_mock = mocker.mock()
    suite_mock.no_story_header
    mocker.result([])
    suite_mock.stories
    mocker.result(['some story'])

    runner_mock = mocker.mock()
    parser_mock = mocker.mock()
    parser_mock.used_actions
    mocker.count(min=1, max=None)
    mocker.result([])
    
    results_mock = mocker.mock()
    results_mock.summary_for('en-us')
    mocker.result('my results')
    
    parser_mock.get_stories(ANY)
    mocker.result(suite_mock)
    runner_mock.run_stories(KWARGS)
    mocker.result(results_mock)
    
    with mocker:
        pc = PyccuracyCore(parser_mock, runner_mock)
    
        #TODO: falha
        results = pc.run_tests(should_throw=False, context=context_mock, fso=fso_mock)
        assert results == results_mock, results
    def do_run_tests_should_throw():
        context_mock, fso_mock = make_context_and_fso_mocks()
        context_mock.settings.write_report = False

        context_mock.browser_driver.expects(once()).method('start_test')
        context_mock.browser_driver.expects(once()).method('stop_test')

        results_mock = Mock()
        suite_mock = Mock()

        runner_mock = Mock()
        parser_mock = Mock()

        parser_mock.expects(once()).method('get_stories').will(return_value(suite_mock))
        runner_mock.expects(once()).method('run_stories').will(return_value(results_mock))

        results_mock.expects(once()).summary_for(eq('en-us')).will(return_value(''))
        results_mock.expects(once()).get_status().will(return_value(Status.Failed))
        pc = PyccuracyCore(parser_mock, runner_mock)
        pc.run_tests(should_throw=True, context=context_mock, fso=fso_mock)

        parser_mock.verify()
        runner_mock.verify()
        context_mock.verify()
        results_mock.verify()
        suite_mock.verify()
        fso_mock.verify()
Beispiel #6
0
def test_pyccuracy_core_run_tests_works_when_None_Result_returned_from_story_runner():
    
    mocker = Mocker()
    
    context_mock, fso_mock = make_context_and_fso_mocks(mocker)
    context_mock.settings.write_report
    mocker.result(False)
        
    suite_mock = mocker.mock()
    suite_mock.no_story_header
    mocker.result([])
    suite_mock.stories
    mocker.result(['some story'])

    runner_mock = mocker.mock()
    parser_mock = mocker.mock()
    parser_mock.used_actions
    mocker.count(min=1, max=None)
    mocker.result([])

    parser_mock.get_stories(ANY)
    mocker.result(suite_mock)
    runner_mock.run_stories(KWARGS)
    mocker.result(None)

    with mocker:
        pc = PyccuracyCore(parser_mock, runner_mock)
    
        assert pc.run_tests(should_throw=False, context=context_mock, fso=fso_mock) == None
Beispiel #7
0
 def testAcceptanceWithPyccuracy(self):
     """Execute acceptance tests running Pyccuracy Core"""
     core = PyccuracyCore()
     result = core.run_tests(
             #base_url="http://myserver/index",
             tests_dir=ACC_TESTS_DIR,
             custom_actions_dir=CUSTOM_ACTIONS_DIR,
             pages_dir=CUSTOM_PAGES_DIR,
             write_report=False,
             default_culture="pt-br",
             browser_to_run="firefox",
             browser_driver="selenium",
             should_throw="should_throw",
             workers=1,
             verbosity=2,)
Beispiel #8
0
def test_pyccuracy_core_instantiation():
    class MyParser:
        pass

    class MyRunner:
        pass

    pc = PyccuracyCore(MyParser(), MyRunner())
    assert isinstance(pc, PyccuracyCore)
    assert isinstance(pc.parser, MyParser)
    assert isinstance(pc.runner, MyRunner)
Beispiel #9
0
    def do_run_tests_should_throw():
        
        mocker = Mocker()
        
        context_mock, fso_mock = make_context_and_fso_mocks(mocker)
        context_mock.settings.write_report
        mocker.result(False)

        context_mock.language = mocker.mock()
        context_mock.language.key
        mocker.result("key")

        results_mock = mocker.mock()
        results_mock.summary_for('en-us')
        mocker.result('')
        results_mock.get_status()
        mocker.result(Status.Failed)
        
        suite_mock = mocker.mock()
        suite_mock.no_story_header
        mocker.result([])
        suite_mock.stories
        mocker.result(['some story'])

        runner_mock = mocker.mock()
        parser_mock = mocker.mock()
        parser_mock.used_actions
        mocker.count(min=1, max=None)
        mocker.result([])
    
        parser_mock.get_stories(ANY)
        mocker.result(suite_mock)
        runner_mock.run_stories(KWARGS)
        mocker.result(results_mock)

        with mocker:
            pc = PyccuracyCore(parser_mock, runner_mock)
            pc.run_tests(should_throw=True, context=context_mock, fso=fso_mock)
def main(arguments=sys.argv[1:]):
    """ Main function - parses args and runs action """
    global no_progress
    global scenarios_ran

    scenarios_ran = 0

    extra_browser_driver_arguments = "\n\nThe following extra browser driver arguments " \
                                     " are supported in the key=value format:\n\nSelenium Browser Driver:\n" \
                                     "* selenium.server=ip or name of selenium server or grid\n" \
                                     "* selenium.port=port of the given selenium server or grid\n"

    parser = optparse.OptionParser(usage="%prog or type %prog -h (--help) for help" + extra_browser_driver_arguments, description=__doc__, version=__version_string__)
    parser.add_option("-p", "--pattern", dest="pattern", default="*.acc", help="File pattern. Defines which files will get executed [default: %default].")
    parser.add_option("-s", "--scenarios", dest="scenarios_to_run", default=None, help="Run only the given scenarios, comma separated. I.e: --scenarios=1,4,9")
    parser.add_option("-l", "--language", dest="language", default="en-us", help="Language. Defines which language the dictionary will be loaded with  [default: %default].")
    parser.add_option("-L", "--languagesdir", dest="languages_dir", default=None, help="Languages Directory. Defines where Pyccuracy will search for language dictionaries  [default: %default].")
    parser.add_option("-d", "--dir", action="append", dest="dir", default=[], help="Tests directory. Defines where the tests to be executed are [default: %default]. Note: this is recursive, so all the tests under the current directory get executed.")
    parser.add_option("-a", "--actionsdir", action="append", dest="actions_dir", default=[], help="Actions directory. Defines where the Pyccuracy actions are. Chances are you don't need to change this parameter [default: %default].")
    parser.add_option("-A", "--customactionsdir", action="append", dest="custom_actions_dir", default=[], help="Custom Actions directory. Defines where the Pyccuracy custom actions are. If you don't change this parameter Pyccuracy will use the tests directory [default: %default].")
    parser.add_option("-P", "--pagesdir", action="append", dest="pages_dir", default=[], help="Pages directory. Defines where the Pyccuracy custom pages are. If you don't change this parameter Pyccuracy will use the tests directory [default: %default].")
    parser.add_option("-u", "--url", dest="url", default=None, help="Base URL. Defines a base url against which the tests will get executed. For more details check the documentation [default: %default].")
    parser.add_option("-b", "--browser", dest="browser_to_run", default="firefox", help="Browser to run. Browser driver will use it to run tests [default: %default].")
    parser.add_option("-w", "--workers", dest="workers", default=1, help="Workers to run in parallel [default: %default].")

    #browser driver
    parser.add_option("-e", "--browserdriver", dest="browser_driver", default="selenium", help="Browser Driver to be used on tests. [default: %default].")

    #throws
    parser.add_option("-T", "--throws", dest="should_throw", default=False, help="Should Throw. Defines whether Pyccuracy console should throw an exception when tests fail. This is useful to set to True if you are running Pyccuracy inside unit tests [default: %default].")

    #reporter
    parser.add_option("-R", "--report", dest="write_report", default="true", help="Should write report. Defines if Pyccuracy should write an html report after each run [default: %default].")
    parser.add_option("-D", "--reportdir", dest="report_dir", default=os.curdir, help="Report directory. Defines the directory to write the report in [default: %default].")
    parser.add_option("-F", "--reportfile", dest="report_file_name", default="report.html", help="Report file. Defines the file name to write the report with [default: %default].")

    #verbosity
    parser.add_option("-v", "--verbosity", dest="verbosity", default="3", help="Verbosity. 0 - does not show any output, 1 - shows text progress, 2 - shows animated progress bar, 3 - shows action by action [default: %default].")

    options, args = parser.parse_args(arguments)

    workers = options.workers and int(options.workers) or None
    pyc = PyccuracyCore()

    if not options.dir:
        options.dir = [os.curdir]

    extra_args = {}
    if args:
        for arg in args:
            if not "=" in arg:
                raise ValueError("The specified extra argument should be in the form of key=value and not %s" % arg)
            key, value = arg.split('=')
            extra_args[key] = value

    verbosity = int(options.verbosity)

    create_progress(verbosity)

    on_before_action_handler = None
    on_action_successful_handler = None
    on_action_error_handler = None
    on_scenario_started_handler = None
    on_scenario_completed_handler = update_progress
    on_section_started = None

    if verbosity == 3:
        on_before_action_handler = before_action
        on_action_successful_handler = action_successful
        on_action_error_handler = action_error
        on_scenario_started_handler = scenario_started
        on_scenario_completed_handler = scenario_completed
        on_section_started = section_started_handler

    result = pyc.run_tests(actions_dir=options.actions_dir,
                           custom_actions_dir=options.custom_actions_dir,
                           pages_dir=options.pages_dir,
                           languages_dir=options.languages_dir,
                           file_pattern=options.pattern,
                           scenarios_to_run=options.scenarios_to_run,
                           tests_dirs=options.dir,
                           base_url=options.url,
                           default_culture=options.language,
                           write_report=options.write_report.lower() == "true",
                           report_file_dir=options.report_dir,
                           report_file_name=options.report_file_name,
                           browser_to_run=options.browser_to_run,
                           browser_driver=options.browser_driver,
                           should_throw=options.should_throw,
                           workers=workers,
                           extra_args=extra_args,
                           on_scenario_started=on_scenario_started_handler,
                           on_scenario_completed=on_scenario_completed_handler,
                           on_before_action=on_before_action_handler,
                           on_action_successful=on_action_successful_handler,
                           on_action_error=on_action_error_handler,
                           on_section_started = on_section_started,
                           verbosity=int(options.verbosity))

    if not result or result.get_status() != "SUCCESSFUL":
        return 1

    return 0
Beispiel #11
0
def main(arguments=sys.argv[1:]):
    """ Main function - parses args and runs action """
    global no_progress
    global scenarios_ran

    scenarios_ran = 0

    extra_browser_driver_arguments = "\n\nThe following extra browser driver arguments " \
                                     " are supported in the key=value format:\n\nSelenium Browser Driver:\n" \
                                     "* selenium.server=ip or name of selenium server or grid\n" \
                                     "* selenium.port=port of the given selenium server or grid\n"

    parser = optparse.OptionParser(usage="%prog or type %prog -h (--help) for help" + extra_browser_driver_arguments, description=__doc__, version=__version_string__)
    parser.add_option("-p", "--pattern", dest="pattern", default="*.acc", help="File pattern. Defines which files will get executed [default: %default].")
    parser.add_option("-s", "--scenarios", dest="scenarios_to_run", default=None, help="Run only the given scenarios, comma separated. I.e: --scenarios=1,4,9")
    parser.add_option("-l", "--language", dest="language", default="en-us", help="Language. Defines which language the dictionary will be loaded with  [default: %default].")
    parser.add_option("-L", "--languagesdir", dest="languages_dir", default=None, help="Languages Directory. Defines where Pyccuracy will search for language dictionaries  [default: %default].")
    parser.add_option("-d", "--dir", action="append", dest="dir", default=[], help="Tests directory. Defines where the tests to be executed are [default: %default]. Note: this is recursive, so all the tests under the current directory get executed.")
    parser.add_option("-a", "--actionsdir", action="append", dest="actions_dir", default=[], help="Actions directory. Defines where the Pyccuracy actions are. Chances are you don't need to change this parameter [default: %default].")
    parser.add_option("-A", "--customactionsdir", action="append", dest="custom_actions_dir", default=[], help="Custom Actions directory. Defines where the Pyccuracy custom actions are. If you don't change this parameter Pyccuracy will use the tests directory [default: %default].")
    parser.add_option("-P", "--pagesdir", action="append", dest="pages_dir", default=[], help="Pages directory. Defines where the Pyccuracy custom pages are. If you don't change this parameter Pyccuracy will use the tests directory [default: %default].")
    parser.add_option("-H", "--hooksdir", action="append", dest="hooks_dir", default=[], help="Hooks directory. Defines where Pyccuracy hooks are. If you don't change this parameter Pyccuracy will use the tests directory [default: %default].")
    parser.add_option("-u", "--url", dest="url", default=None, help="Base URL. Defines a base url against which the tests will get executed. For more details check the documentation [default: %default].")
    parser.add_option("-b", "--browser", dest="browser_to_run", default="firefox", help="Browser to run. Browser driver will use it to run tests [default: %default].")
    parser.add_option("-w", "--workers", dest="workers", default=1, help="Workers to run in parallel [default: %default].")

    #browser driver
    parser.add_option("-e", "--browserdriver", dest="browser_driver", default="selenium", help="Browser Driver to be used on tests. [default: %default].")

    #throws
    parser.add_option("-T", "--throws", dest="should_throw", default=False, help="Should Throw. Defines whether Pyccuracy console should throw an exception when tests fail. This is useful to set to True if you are running Pyccuracy inside unit tests [default: %default].")

    #reporter
    parser.add_option("-R", "--report", dest="write_report", default="true", help="Should write report. Defines if Pyccuracy should write an html report after each run [default: %default].")
    parser.add_option("-D", "--reportdir", dest="report_dir", default=os.curdir, help="Report directory. Defines the directory to write the report in [default: %default].")
    parser.add_option("-F", "--reportfile", dest="report_file_name", default="report.html", help="Report file. Defines the file name to write the report with [default: %default].")

    #verbosity
    parser.add_option("-v", "--verbosity", dest="verbosity", default="3", help="Verbosity. 0 - does not show any output, 1 - shows text progress, 2 - shows animated progress bar, 3 - shows action by action [default: %default].")
    parser.add_option("--suppresswarnings", action="store_true", dest="suppress_warnings", default=False, help="Suppress Pyccuracy warnings [default: %default].")

    options, args = parser.parse_args(arguments)

    workers = options.workers and int(options.workers) or None
    pyc = PyccuracyCore()

    if not options.dir:
        options.dir = [os.curdir]

    extra_args = {}
    if args:
        for arg in args:
            if not "=" in arg:
                raise ValueError("The specified extra argument should be in the form of key=value and not %s" % arg)
            key, value = arg.split('=')
            extra_args[key] = value

    verbosity = int(options.verbosity)

    create_progress(verbosity)

    on_before_action_handler = None
    on_action_successful_handler = None
    on_action_error_handler = None
    on_scenario_started_handler = None
    on_scenario_completed_handler = update_progress
    on_section_started = None

    if verbosity == 3:
        on_before_action_handler = before_action
        on_action_successful_handler = action_successful
        on_action_error_handler = action_error
        on_scenario_started_handler = scenario_started
        on_scenario_completed_handler = scenario_completed
        on_section_started = section_started_handler

    result = pyc.run_tests(actions_dir=options.actions_dir,
                           custom_actions_dir=options.custom_actions_dir,
                           pages_dir=options.pages_dir,
                           hooks_dir=options.hooks_dir,
                           languages_dir=options.languages_dir,
                           file_pattern=options.pattern,
                           scenarios_to_run=options.scenarios_to_run,
                           tests_dirs=options.dir,
                           base_url=options.url,
                           default_culture=options.language,
                           write_report=options.write_report.lower() == "true",
                           report_file_dir=options.report_dir,
                           report_file_name=options.report_file_name,
                           browser_to_run=options.browser_to_run,
                           browser_driver=options.browser_driver,
                           should_throw=options.should_throw,
                           workers=workers,
                           extra_args=extra_args,
                           on_scenario_started=on_scenario_started_handler,
                           on_scenario_completed=on_scenario_completed_handler,
                           on_before_action=on_before_action_handler,
                           on_action_successful=on_action_successful_handler,
                           on_action_error=on_action_error_handler,
                           on_section_started=on_section_started,
                           verbosity=int(options.verbosity),
                           suppress_warnings=options.suppress_warnings)

    if not result or result.get_status() != "SUCCESSFUL":
        return 1

    return 0