Esempio n. 1
0
    def set_up(self):
        self.path.project = self.path.engine.parent
        self.path.state = self.path.engine.parent.joinpath("state")
        self.path.samples = self.path.engine.joinpath("samples")

        if not self.path.state.exists():
            self.path.state.mkdir()

        if self.settings.get("kaching", False):
            kaching.start()

        self.python_package = hitchpython.PythonPackage(
            python_version="3.5.0"  #self.preconditions['python_version']
        )
        self.python_package.build()

        self.python = self.python_package.cmd.python
        self.pip = self.python_package.cmd.pip

        self.cli_steps = hitchcli.CommandLineStepLibrary(
            default_timeout=int(self.settings.get("cli_timeout", 720)))

        self.cd = self.cli_steps.cd
        self.run = self.cli_steps.run
        self.expect = self.cli_steps.expect
        self.send_control = self.cli_steps.send_control
        self.send_line = self.cli_steps.send_line
        self.exit_with_any_code = self.cli_steps.exit_with_any_code
        self.exit = self.cli_steps.exit
        self.finish = self.cli_steps.finish

        if "files" in self.preconditions:
            self.path.state.rmtree(ignore_errors=True)
            self.path.state.mkdir()
            for filename, contents in self.preconditions['files'].items():
                self.path.state.joinpath(filename).write_text(contents)

        if "state" in self.preconditions:
            self.path.state.rmtree(ignore_errors=True)
            self.path.samples.joinpath(self.preconditions['state'])\
                             .copytree(self.path.state)

        run(self.pip("uninstall", "hitchmysql", "-y").ignore_errors())
        run(self.pip("uninstall", "hitchtest", "-y").ignore_errors())
        run(
            self.pip("install",
                     ".").in_dir(self.path.project.joinpath("..", "test")))
        run(
            self.pip("install", ".").in_dir(
                self.path.project.joinpath("..", "commandlib")))
        run(self.pip("install", ".").in_dir(self.path.project))
        run(self.pip("install", "ipykernel"))
        run(self.pip("install", "pip", "--upgrade"))
        run(self.pip("install", "pygments", "--upgrade"))

        self.services = hitchserve.ServiceBundle(self.path.project,
                                                 startup_timeout=8.0,
                                                 shutdown_timeout=1.0)
Esempio n. 2
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.path.project = self.path.engine.parent

        if self.path.state.exists():
            self.path.state.rmtree(ignore_errors=True)
        self.path.state.mkdir()

        for filename, text in self.preconditions.get("files", {}).items():
            filepath = self.path.state.joinpath(filename)
            if not filepath.dirname().exists():
                filepath.dirname().mkdir()
            filepath.write_text(text)

        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0')
        )
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Install debugging packages
        with hitchtest.monitor([self.path.engine.joinpath("debugrequirements.txt")]) as changed:
            if changed:
                run(self.pip("install", "-r", "debugrequirements.txt").in_dir(self.path.engine))

        # Uninstall and reinstall
        run(self.pip("uninstall", "hitchtrigger", "-y").ignore_errors())
        run(self.pip("install", ".").in_dir(self.path.project))

        run(self.pip("install", "peewee=={0}".format(self.preconditions['peewee_version'])))
        run(self.pip("install", "humanize=={0}".format(self.preconditions['humanize_version'])))

        self.services = hitchserve.ServiceBundle(
            str(self.path.project),
            startup_timeout=8.0,
            shutdown_timeout=1.0
        )

        self.services['IPython'] = hitchpython.IPythonKernelService(self.python_package)

        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services['IPython'].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(self.ipython_kernel_filename)

        self.run_command = self.ipython_step_library.run
        self.assert_true = self.ipython_step_library.assert_true
        self.assert_exception = self.ipython_step_library.assert_exception
        self.shutdown_connection = self.ipython_step_library.shutdown_connection
        self.run_command("import os")
        self.run_command("os.chdir('{}')".format(self.path.state))

        for line in self.settings['always run']:
            self.run_command(line)
Esempio n. 3
0
    def set_up(self):
        if self.path.state.exists():
            self.path.state.rmtree(ignore_errors=True)
        self.path.state.mkdir()

        for filename, text in self.preconditions.get("files", {}).items():
            filepath = self.path.state.joinpath(filename)
            if not filepath.dirname().exists():
                filepath.dirname().mkdir()
            filepath.write_text(str(text))

        for filename, text in self.preconditions.get("variables", {}).items():
            filepath = self.path.state.joinpath(filename)
            if not filepath.dirname().exists():
                filepath.dirname().mkdir()
            filepath.write_text(str(text))

        self.path.engine.joinpath("code_that_does_things.py").copy(self.path.state)

        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', self.preconditions['python version'])
        )
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        with hitchtest.monitor([self.path.keypath.joinpath("debugrequirements.txt")]) as changed:
            if changed:
                self.pip("install", "-r", "debugrequirements.txt").in_dir(self.path.keypath).run()

        self.pip("uninstall", "hitchdoc", "-y").ignore_errors().run()
        self.pip("install", ".").in_dir(self.path.project).run()

        self.services = hitchserve.ServiceBundle(
            str(self.path.project),
            startup_timeout=8.0,
            shutdown_timeout=1.0
        )

        self.services['IPython'] = hitchpython.IPythonKernelService(self.python_package)

        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services['IPython'].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(self.ipython_kernel_filename)

        self.run("import os")
        self.run("from path import Path")
        self.run("os.chdir('{}')".format(self.path.state))
        self.run("from code_that_does_things import *")

        for var, value in self.preconditions.get("variables", {}).items():
            self.run("{0} = Path('{0}').bytes().decode('utf8')".format(var))
Esempio n. 4
0
    def set_up(self):
        """Ensure virtualenv present, then run all services."""
        python_package = hitchpython.PythonPackage(
            python_version=self.preconditions['python_version']
        )
        python_package.build()
        python_package.verify()

        call([
            python_package.pip, "install", "-r",
            path.join(PROJECT_DIRECTORY, "requirements/local.txt")
        ])

        postgres_package = hitchpostgres.PostgresPackage(
            version=self.settings["postgres_version"],
        )
        postgres_package.build()
        postgres_package.verify()

        redis_package = hitchredis.RedisPackage(version="2.8.4")
        redis_package.build()
        redis_package.verify()

        self.services = hitchserve.ServiceBundle(
            project_directory=PROJECT_DIRECTORY,
            startup_timeout=float(self.settings["startup_timeout"]),
            shutdown_timeout=5.0,
        )

        postgres_user = hitchpostgres.PostgresUser("{{cookiecutter.repo_name}}", "password")

        self.services['Postgres'] = hitchpostgres.PostgresService(
            postgres_package=postgres_package,
            users=[postgres_user, ],
            databases=[hitchpostgres.PostgresDatabase("{{cookiecutter.repo_name}}", postgres_user), ]
        )

        self.services['HitchSMTP'] = hitchsmtp.HitchSMTPService(port=1025)

        self.services['Django'] = hitchpython.DjangoService(
            python=python_package.python,
            port=8000,
            version=str(self.settings.get("django_version")),
            settings="config.settings.local",
            needs=[self.services['Postgres'], ],
            env_vars=self.settings['environment_variables'],
        )

        self.services['Redis'] = hitchredis.RedisService(
            redis_package=redis_package,
            port=16379,
        )
Esempio n. 5
0
 def set_up_service(self, name, args):
     """Start specified MockHTTP services."""
     if not hasattr(self, 'services') or self.services is None:
         self.services = hitchserve.ServiceBundle(
             self.path.state,
             startup_timeout=8.0,
             shutdown_timeout=1.0,
         )
     self.services[name] = hitchserve.Service(
         command=self.hitchhttpcmd(*args).in_dir(self.path.state),
         log_line_ready_checker=lambda line: "HitchHttp running" in line,
         directory=str(self.path.state),
     )
Esempio n. 6
0
    def set_up(self):
        """Ensure virtualenv present, then run all services."""
        python_package = hitchpython.PythonPackage(
            python_version=self.settings['python_version']
        )
        python_package.build()

        call([
            python_package.pip, 'install', '-r',
            path.join(PROJECT_DIRECTORY, 'requirements/local.txt')
        ])

        postgres_package = hitchpostgres.PostgresPackage()
        postgres_package.build()

        redis_package = hitchredis.RedisPackage()
        redis_package.build()

        self.services = hitchserve.ServiceBundle(
            project_directory=PROJECT_DIRECTORY,
            startup_timeout=float(self.settings['startup_timeout']),
            shutdown_timeout=float(self.settings['shutdown_timeout']),
        )

        postgres_user = hitchpostgres.PostgresUser('{{cookiecutter.repo_name}}', 'password')

        self.services['Postgres'] = hitchpostgres.PostgresService(
            postgres_package=postgres_package,
            users=[postgres_user, ],
            databases=[hitchpostgres.PostgresDatabase('{{cookiecutter.repo_name}}', postgres_user), ]
        )

        self.services['HitchSMTP'] = hitchsmtp.HitchSMTPService(port=1025)

        self.services['Django'] = hitchpython.DjangoService(
            python=python_package.python,
            port=8000,
            settings='config.settings.local',
            needs=[self.services['Postgres'], ],
            env_vars=self.settings['environment_variables'],
        )

        self.services['Redis'] = hitchredis.RedisService(
            redis_package=redis_package,
            port=16379,
        )
Esempio n. 7
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.path.state = self.path.gen.joinpath("state")

        if self.path.state.exists():
            self.path.state.rmtree()
        self.path.state.mkdir()

        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0'))
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Install debugging packages
        with hitchtest.monitor(
            [self.path.key.joinpath("debugrequirements.txt")]) as changed:
            if changed:
                run(
                    self.pip("install", "-r",
                             "debugrequirements.txt").in_dir(self.path.key))

        # Uninstall and reinstall
        with hitchtest.monitor(
                pathq(self.path.project.joinpath("hitchhttp")).ext(
                    "py")) as changed:
            if changed:
                run(self.pip("uninstall", "hitchhttp", "-y").ignore_errors())
                run(self.pip("install", ".").in_dir(self.path.project))

        self.path.state.joinpath("example.yaml").write_text(
            self.preconditions['example.yaml'])
        self.path.state.joinpath("myserver.py").write_text(
            self.preconditions['code'])

        self.services = hitchserve.ServiceBundle(
            str(self.path.project),
            startup_timeout=2.0,
            shutdown_timeout=2.0,
        )
Esempio n. 8
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0')
        )
        self.python_package.build()

        # Uninstall and reinstall
        call([self.python_package.pip, "install", "ipython==1.2.1", ], stdout=PIPE)
        call([self.python_package.pip, "install", "pyzmq", ], stdout=PIPE)
        call([self.python_package.pip, "install", "flake8", ], stdout=PIPE)
        call([self.python_package.pip, "uninstall", "dumbyaml", "-y"], stdout=PIPE)
        #chdir(PROJECT_DIRECTORY)
        #check_call([self.python_package.python, "setup.py", "install"], stdout=PIPE)
        
        run(Command([self.python_package.python, "setup.py", "install"]).in_dir(PROJECT_DIRECTORY))
        #print(Command([self.python_package.python, "setup.py", "install"]).arguments)


        self.services = hitchserve.ServiceBundle(
            PROJECT_DIRECTORY,
            startup_timeout=8.0,
            shutdown_timeout=1.0
        )
        
        self.services['IPython'] = hitchpython.IPythonKernelService(self.python_package)
        
        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services['IPython'].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(self.ipython_kernel_filename)
        
        self.run_command = self.ipython_step_library.run
        self.assert_true = self.ipython_step_library.assert_true
        self.assert_exception = self.ipython_step_library.assert_exception
        self.shutdown_connection = self.ipython_step_library.shutdown_connection
        self.run_command("import dumbyaml")
        self.run_command("import yaml")
Esempio n. 9
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.doc = hitchdoc.Recorder(
            hitchdoc.HitchStory(self),
            self.path.gen.joinpath('storydb.sqlite'),
        )

        if self.path.gen.joinpath("state").exists():
            self.path.gen.joinpath("state").rmtree(ignore_errors=True)
        self.path.gen.joinpath("state").mkdir()
        self.path.state = self.path.gen.joinpath("state")

        for filename, text in self.preconditions.get("files", {}).items():
            filepath = self.path.state.joinpath(filename)
            if not filepath.dirname().exists():
                filepath.dirname().mkdir()
            filepath.write_text(text)

        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0'))
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Install debugging packages
        with hitchtest.monitor(
            [self.path.key.joinpath("debugrequirements.txt")]) as changed:
            if changed:
                run(
                    self.pip("install", "-r",
                             "debugrequirements.txt").in_dir(self.path.key))

        # Uninstall and reinstall
        run(self.pip("uninstall", "strictyaml", "-y").ignore_errors())
        run(self.pip("install", ".").in_dir(self.path.project))
        run(
            self.pip(
                "install", "ruamel.yaml=={0}".format(
                    self.preconditions["ruamel version"])))

        self.services = hitchserve.ServiceBundle(str(self.path.project),
                                                 startup_timeout=8.0,
                                                 shutdown_timeout=1.0)

        self.services['IPython'] = hitchpython.IPythonKernelService(
            self.python_package)

        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services[
            'IPython'].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(
            self.ipython_kernel_filename)

        self.shutdown_connection = self.ipython_step_library.shutdown_connection
        self.ipython_step_library.run("import os")
        self.ipython_step_library.run("import sure")
        self.ipython_step_library.run("from path import Path")
        self.ipython_step_library.run("os.chdir('{}')".format(self.path.state))

        for filename, text in self.preconditions.get("files", {}).items():
            self.ipython_step_library.run(
                """{} = Path("{}").bytes().decode("utf8")""".format(
                    filename.replace(".yaml", ""), filename))
Esempio n. 10
0
    def set_up(self):
        """Ensure virtualenv present, then run all services."""
        python_package = hitchpython.PythonPackage(
            python_version=self.settings['python_version'])
        python_package.build()

        call([
            python_package.pip, "install", "-r",
            path.join(PROJECT_DIRECTORY, "requirements/local.txt")
        ])

        postgres_package = hitchpostgres.PostgresPackage()
        postgres_package.build()

        redis_package = hitchredis.RedisPackage()
        redis_package.build()

        self.services = hitchserve.ServiceBundle(
            project_directory=PROJECT_DIRECTORY,
            startup_timeout=float(self.settings["startup_timeout"]),
            shutdown_timeout=float(self.settings["shutdown_timeout"]),
        )

        postgres_user = hitchpostgres.PostgresUser("django_bootstrap",
                                                   "password")

        self.services['Postgres'] = hitchpostgres.PostgresService(
            postgres_package=postgres_package,
            users=[
                postgres_user,
            ],
            databases=[
                hitchpostgres.PostgresDatabase("django_bootstrap",
                                               postgres_user),
            ])

        self.services['HitchSMTP'] = hitchsmtp.HitchSMTPService(port=1025)

        self.services['Django'] = hitchpython.DjangoService(
            python=python_package.python,
            port=8000,
            settings="config.settings.local",
            needs=[
                self.services['Postgres'],
            ],
            env_vars=self.settings['environment_variables'],
        )

        self.services['Redis'] = hitchredis.RedisService(
            redis_package=redis_package,
            port=16379,
        )

        self.services['Firefox'] = hitchselenium.SeleniumService(
            xvfb=self.settings.get("xvfb", False),
            no_libfaketime=True,
        )

        #        import hitchcron
        #        self.services['Cron'] = hitchcron.CronService(
        #            run=self.services['Django'].manage("trigger").command,
        #            every=1,
        #            needs=[ self.services['Django'], ],
        #        )

        self.services.startup(interactive=False)

        # Docs : https://hitchtest.readthedocs.org/en/latest/plugins/hitchselenium.html
        self.driver = self.services['Firefox'].driver

        self.webapp = hitchselenium.SeleniumStepLibrary(
            selenium_webdriver=self.driver,
            wait_for_timeout=5,
        )

        # Add selenium steps
        self.click = self.webapp.click
        self.wait_to_appear = self.webapp.wait_to_appear
        self.wait_to_contain = self.webapp.wait_to_contain
        self.wait_for_any_to_contain = self.webapp.wait_for_any_to_contain
        self.click_and_dont_wait_for_page_load = self.webapp.click_and_dont_wait_for_page_load

        # Configure selenium driver
        self.driver.set_window_size(self.settings['window_size']['height'],
                                    self.settings['window_size']['width'])
        self.driver.set_window_position(0, 0)
        self.driver.implicitly_wait(2.0)
        self.driver.accept_next_alert = True
Esempio n. 11
0
    def set_up(self):
        """Ensure virtualenv present, then run all services."""
        python_package = hitchpython.PythonPackage(
            python_version=self.preconditions['python_version']
        )
        python_package.build()
        python_package.verify()

        call([
            python_package.pip, "install", "-r",
            path.join(PROJECT_DIRECTORY, "requirements/local.txt")
        ])

        postgres_package = hitchpostgres.PostgresPackage(
            version=self.settings["postgres_version"],
        )
        postgres_package.build()
        postgres_package.verify()

        redis_package = hitchredis.RedisPackage(version="2.8.4")
        redis_package.build()
        redis_package.verify()

        self.services = hitchserve.ServiceBundle(
            project_directory=PROJECT_DIRECTORY,
            startup_timeout=float(self.settings["startup_timeout"]),
            shutdown_timeout=5.0,
        )

        postgres_user = hitchpostgres.PostgresUser("studentloan5", "password")

        self.services['Postgres'] = hitchpostgres.PostgresService(
            postgres_package=postgres_package,
            users=[postgres_user, ],
            databases=[hitchpostgres.PostgresDatabase("studentloan5", postgres_user), ]
        )

        self.services['HitchSMTP'] = hitchsmtp.HitchSMTPService(port=1025)

        self.services['Django'] = hitchpython.DjangoService(
            python=python_package.python,
            port=8000,
            version=str(self.settings.get("django_version")),
            settings="config.settings.local",
            needs=[self.services['Postgres'], ],
            env_vars=self.settings['environment_variables'],
        )

        self.services['Redis'] = hitchredis.RedisService(
            redis_package=redis_package,
            port=16379,
        )

        self.services['Firefox'] = hitchselenium.SeleniumService(
            xvfb=self.settings.get("quiet", False),
            no_libfaketime=True,
        )

#        import hitchcron
#        self.services['Cron'] = hitchcron.CronService(
#            run=self.services['Django'].manage("trigger").command,
#            every=1,
#            needs=[ self.services['Django'], ],
#        )

        self.services.startup(interactive=False)

        # Configure selenium driver
        self.driver = self.services['Firefox'].driver
        self.driver.set_window_size(self.settings['window_size']['height'], self.settings['window_size']['width'])
        self.driver.set_window_position(0, 0)
        self.driver.implicitly_wait(2.0)
        self.driver.accept_next_alert = True
Esempio n. 12
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.path.project = self.path.engine.parent

        if self.path.state.exists():
            self.path.state.rmtree(ignore_errors=True)
        self.path.state.mkdir()

        for script, text in self.preconditions.get("scripts", {}).items():
            script_file = self.path.state.joinpath(script)
            if not script_file.dirname().exists():
                script_file.dirname().mkdir()
            script_file.write_text(text)
            script_file.chmod("u+x")

        for script, text in self.preconditions.get("files", {}).items():
            script_file = self.path.state.joinpath(script)
            if not script_file.dirname().exists():
                script_file.dirname().mkdir()
            script_file.write_text(text)

        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0'))
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Uninstall and reinstall
        run(self.pip("install", "flake8"))
        run(self.pip("install", "ipython==1.2.1").ignore_errors())
        run(self.pip("install", "pyzmq").ignore_errors())
        run(self.pip("uninstall", "commandlib", "-y").ignore_errors())
        run(self.pip("install", ".").in_dir(self.path.project))

        if "pexpect_version" in self.preconditions:
            run(
                self.pip(
                    "install", "pexpect=={0}".format(
                        self.preconditions['pexpect_version'])))

        self.services = hitchserve.ServiceBundle(str(self.path.project),
                                                 startup_timeout=8.0,
                                                 shutdown_timeout=1.0)

        self.services['IPython'] = hitchpython.IPythonKernelService(
            self.python_package)

        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services[
            'IPython'].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(
            self.ipython_kernel_filename)

        self.run_command = self.ipython_step_library.run
        self.assert_true = self.ipython_step_library.assert_true
        self.assert_exception = self.ipython_step_library.assert_exception
        self.shutdown_connection = self.ipython_step_library.shutdown_connection
        self.run_command("from commandlib import Command, run")
        self.run_command("import os")
        self.run_command("os.chdir('{}')".format(self.path.state))