Exemple #1
0
    def test_build_with_prune(self):
        pkgname = 'new_pkg'

        with temp_chdir() as d:
            runner = CliRunner()
            result = runner.invoke(kecpkg, ['new', pkgname, '--no-venv'])
            package_dir = get_package_dir(pkgname)
            self.assertTrue(os.path.exists(package_dir))

            os.chdir(package_dir)

            result = runner.invoke(kecpkg, ['build', pkgname])
            self.assertEqual(
                result.exit_code, 0,
                "Results of the run were: \n---\n{}\n---".format(
                    result.output))
            self.assertExists(os.path.join(package_dir, 'dist'))

            # check if dist is filled
            package_dir_contents = os.listdir(os.path.join(
                package_dir, 'dist'))
            self.assertTrue(len(package_dir_contents), 1)

            # restart the build, with prune and check if dist still has 1
            result = runner.invoke(kecpkg, ['build', pkgname, '--prune'])
            self.assertEqual(
                result.exit_code, 0,
                "Results of the run were: \n---\n{}\n---".format(
                    result.output))
            self.assertExists(os.path.join(package_dir, 'dist'))

            # check if dist is filled
            package_dir_contents = os.listdir(os.path.join(
                package_dir, 'dist'))
            self.assertTrue(len(package_dir_contents), 1)
Exemple #2
0
    def test_new_non_interactive_no_venv(self):
        pkgname = 'new_pkg'

        with temp_chdir() as d:
            runner = CliRunner()
            result = runner.invoke(kecpkg, ['new', pkgname, '--no-venv'])

            self.assertEqual(result.exit_code, 0)

            self.assertTrue(os.path.exists(os.path.join(d, pkgname)))
            self.assertTrue(os.path.exists(os.path.join(d, pkgname, 'script.py')))
            self.assertTrue(os.path.exists(os.path.join(d, pkgname, 'package_info.json')))
            self.assertTrue(os.path.exists(os.path.join(d, pkgname, 'README.md')))
            self.assertTrue(os.path.exists(os.path.join(d, pkgname, 'requirements.txt')))
            self.assertTrue(os.path.exists(os.path.join(d, pkgname, '.gitignore')))
            self.assertTrue(os.path.exists(os.path.join(d, pkgname, '.kecpkg_settings.json')))
            self.assertTrue(os.path.exists(os.path.join(d, pkgname, '.idea')))
            self.assertTrue(os.path.exists(os.path.join(d, pkgname, '.env')))
            self.assertTrue(os.path.exists(os.path.join(d, pkgname, '.idea', 'runConfigurations')))
            self.assertTrue(
                os.path.exists(os.path.join(d, pkgname, '.idea', 'runConfigurations', 'Build_the_kecpkg.xml')))
            self.assertTrue(
                os.path.exists(os.path.join(d, pkgname, '.idea', 'runConfigurations', 'Upload_the_kecpkg.xml')))

            self.assertFalse(os.path.exists(os.path.join(d, pkgname, 'venv')))
Exemple #3
0
    def test_build_with_alternate_config(self):
        pkgname = 'new_pkg'
        alt_settings = 'alt-settings.json'

        with temp_chdir() as d:
            runner = CliRunner()
            result = runner.invoke(kecpkg, ['new', pkgname, '--no-venv'])
            package_dir = get_package_dir(pkgname)
            self.assertTrue(os.path.exists(package_dir))

            # set alternative settings path
            settings = copy_default_settings()
            settings["package_name"] = pkgname
            save_settings(settings,
                          package_dir=package_dir,
                          settings_filename=alt_settings)

            os.chdir(package_dir)

            result = runner.invoke(
                kecpkg, ['build', pkgname, '--config', alt_settings])
            self.assertEqual(
                result.exit_code, 0,
                "Results of the run were: \n---\n{}\n---".format(
                    result.output))
            self.assertExists(os.path.join(package_dir, 'dist'))

            dist_dir_contents = os.listdir(os.path.join(package_dir, 'dist'))
            self.assertTrue(len(dist_dir_contents), 1)
            self.assertTrue(
                pkgname in dist_dir_contents[0],
                "the name of the pkg `{}` should be in the name of "
                "the built kecpkg `{}`".format(pkgname, dist_dir_contents[0]))
Exemple #4
0
    def test_new_non_iteractive_with_alternate_script(self):
        pkgname = 'new_pkg'

        with temp_chdir() as d:
            runner = CliRunner()
            result = runner.invoke(kecpkg, ['new', pkgname, '--script', 'foobar', '--no-venv'])

            self.assertEqual(result.exit_code, 0)

            self.assertTrue(os.path.exists(os.path.join(d, pkgname, 'foobar.py')))
Exemple #5
0
    def test_purge_non_interactive(self):
        pkgname = 'new_pkg'

        with temp_chdir() as d:
            runner = CliRunner()
            result = runner.invoke(kecpkg, ['new', pkgname, '--no-venv'])
            package_dir = get_package_dir(pkgname)
            self.assertTrue(os.path.exists(package_dir))

            result = runner.invoke(kecpkg, ['purge', pkgname, '--force'])
            self.assertFalse(os.path.exists(package_dir))
Exemple #6
0
    def test_new_non_interactive_with_alternate_venv_name(self):
        pkgname = 'new_pkg'
        venv_name = '_v'

        with temp_chdir() as d:
            runner = CliRunner()
            result = runner.invoke(kecpkg, ['new', pkgname, '--venv', venv_name])

            self.assertEqual(result.exit_code, 0)

            self.assertTrue(os.path.exists(os.path.join(d, pkgname, venv_name)))
            self.assertTrue(os.path.exists(os.path.join(d, pkgname, venv_name, 'bin', 'activate')))
Exemple #7
0
    def test_upload_non_interactive(self):
        pkgname = 'new_pkg'
        env = Env.read_envfile()

        self.assertTrue(
            os.environ.get('KECHAIN_URL'),
            "KECHAIN_URL is not set in environment, cannot perform this test")

        with temp_chdir() as d:
            runner = CliRunner()
            result = runner.invoke(kecpkg, ['new', pkgname, '--no-venv'])
            package_dir = get_package_dir(pkgname)
            self.assertTrue(os.path.exists(package_dir))

            os.chdir(package_dir)

            result = runner.invoke(kecpkg, ['build', pkgname])
            self.assertEqual(result.exit_code, 0)
            self.assertExists(os.path.join(package_dir, 'dist'))
            pkgpath = os.path.join(package_dir, 'dist',
                                   '{}-0.0.1-py3.5.kecpkg'.format(pkgname))
            self.assertExists(pkgpath)

            result = runner.invoke(
                kecpkg,
                [
                    'upload',
                    pkgname,
                    '--url',
                    os.environ.get('KECHAIN_URL'),
                    '--token',
                    os.environ.get('KECHAIN_TOKEN'),
                    '--scope-id',
                    os.environ.get('KECHAIN_SCOPE_ID'),
                    '--kecpkg',
                    pkgpath,
                    '--store'  # store the service_id in the settings (for teardown)
                ])
            self.assertEqual(result.exit_code, 0)

            # teardown the just uploaded service
            from kecpkg.settings import load_settings
            settings = load_settings(package_dir=get_package_dir(pkgname))

            from pykechain import get_project
            scope = get_project(url=os.environ.get('KECHAIN_URL'),
                                token=os.environ.get('KECHAIN_TOKEN'),
                                scope_id=os.environ.get('KECHAIN_SCOPE_ID'))
            service = scope.service(pk=settings.get('service_id'))
            service.delete()
Exemple #8
0
    def test_build_with_extra_ignores(self):
        pkgname = 'new_pkg'

        with temp_chdir() as d:
            runner = CliRunner()
            result = runner.invoke(kecpkg, ['new', pkgname, '--no-venv'])
            package_dir = get_package_dir(pkgname)
            self.assertTrue(os.path.exists(package_dir))
            ensure_dir_exists(os.path.join(package_dir, 'data'))

            # add additional files (to exclude for building later)
            touch_file(os.path.join(package_dir, 'data', 'somefile.txt'))
            touch_file(
                os.path.join(package_dir, 'local_extra_file.someext.txt'))

            os.chdir(package_dir)

            # check if those files exists
            package_dir_contents = os.listdir(os.path.join(package_dir))
            self.assertTrue(
                'local_extra_file.someext.txt' in package_dir_contents)
            self.assertTrue('data' in package_dir_contents)

            # set exclude_paths in settings
            settings = copy_default_settings()
            settings["exclude_paths"] = ["data", "local_extra_file.*"]
            save_settings(settings, package_dir=package_dir)

            # run the builder
            result = runner.invoke(kecpkg, ['build', pkgname, '--verbose'])
            self.assertEqual(
                result.exit_code, 0,
                "Results of the run were: \n---\n{}\n---".format(
                    result.output))
            self.assertExists(os.path.join(package_dir, 'dist'))

            # check the zip such that the extra files are not packaged
            dist_list = os.listdir(os.path.join(package_dir, 'dist'))
            zipfile = ZipFile(os.path.join(package_dir, 'dist', dist_list[0]),
                              'r')
            contents = zipfile.namelist()

            self.assertFalse('local_extra_file.someext.txt' in contents)
            self.assertFalse('data' in contents)
Exemple #9
0
    def test_import_key(self):
        with temp_chdir() as d:
            create_file('TESTKEY.asc',
                        TEST_THIS_IS_NOT_A_SECRET_KEY__NO_REALLY_NOT)
            result = self.runner.invoke(
                kecpkg, ['sign', '--import-key', 'TESTKEY.asc'])
            self.assertEqual(
                result.exit_code, 0,
                "Results of the run were: \n---\n{}\n---".format(
                    result.output))

            # teardown
            result = self.runner.invoke(kecpkg, [
                'sign', '--delete-key',
                TEST_THIS_IS_NOT_A_SECRET_KEY_FINGERPRINT
            ])
            self.assertEqual(
                result.exit_code, 0,
                "Results of the run were: \n---\n{}\n---".format(
                    result.output))