Exemple #1
0
    def test_write_working_file_touch(self):
        config = Config({
            'step-runner-config': {
                'foo': {
                    'implementer':
                    'tests.helpers.sample_step_implementers.FooStepImplementer',
                    'config': {}
                }
            }
        })
        step_config = config.get_step_config('foo')
        sub_step = step_config.get_sub_step(
            'tests.helpers.sample_step_implementers.FooStepImplementer')

        with TempDirectory() as test_dir:
            working_dir_path = os.path.join(test_dir.path,
                                            'step-runner-working')
            step = FooStepImplementer(workflow_result=WorkflowResult(),
                                      parent_work_dir_path=working_dir_path,
                                      config=sub_step)

            step.write_working_file('foo/test.json')

            working_file_path = os.path.join(working_dir_path,
                                             'foo/foo/test.json')
            self.assertTrue(os.path.exists(working_file_path))

            with open(working_file_path, 'r') as working_file:
                self.assertEqual(working_file.read(), '')
Exemple #2
0
    def test_create_working_dir_sub_dir(self):
        config = Config({
            'step-runner-config': {
                'foo': {
                    'implementer':
                    'tests.helpers.sample_step_implementers.FooStepImplementer',
                    'config': {}
                }
            }
        })
        step_config = config.get_step_config('foo')
        sub_step = step_config.get_sub_step(
            'tests.helpers.sample_step_implementers.FooStepImplementer')

        with TempDirectory() as test_dir:
            working_dir_path = os.path.join(test_dir.path,
                                            'step-runner-working')
            step = FooStepImplementer(workflow_result=WorkflowResult(),
                                      parent_work_dir_path=working_dir_path,
                                      config=sub_step)

            sub = step.create_working_dir_sub_dir('folder1')
            self.assertEqual(sub, f'{working_dir_path}/foo/folder1')
            self.assertEqual(True, os.path.isdir(sub))

            sub = step.create_working_dir_sub_dir('folder1/folder2/folder3')
            self.assertEqual(
                sub, f'{working_dir_path}/foo/folder1/folder2/folder3')
            self.assertEqual(True, os.path.isdir(sub))
    def test_write_working_file(self):
        config = Config({
            'step-runner-config': {
                'foo': {
                    'implementer':
                    'tests.helpers.sample_step_implementers.FooStepImplementer',
                    'config': {}
                }
            }
        })
        step_config = config.get_step_config('foo')
        sub_step = step_config.get_sub_step(
            'tests.helpers.sample_step_implementers.FooStepImplementer')

        with TempDirectory() as test_dir:
            results_dir_path = os.path.join(test_dir.path,
                                            'step-runner-results')
            working_dir_path = os.path.join(test_dir.path,
                                            'step-runner-working')
            step = FooStepImplementer(
                results_dir_path=results_dir_path,
                results_file_name='step-runner-results.yml',
                work_dir_path=working_dir_path,
                config=sub_step)

            step.write_working_file('test-working-file', b'hello world')

            with open(os.path.join(working_dir_path, 'foo', 'test-working-file'), 'r') \
                    as working_file:
                self.assertEqual(working_file.read(), 'hello world')
Exemple #4
0
    def test_get_config_value(self):
        """Test get config value"""
        config = Config({
            'tssc-config': {
                'foo': {
                    'implementer':
                    'tests.helpers.sample_step_implementers.FooStepImplementer',
                    'config': {
                        'test': 'hello world'
                    }
                }
            }
        })
        step_config = config.get_step_config('foo')
        sub_step = (step_config.get_sub_step(
            'tests.helpers.sample_step_implementers.FooStepImplementer'))

        with TempDirectory() as test_dir:
            results_dir_path = os.path.join(test_dir.path, 'tssc-results')
            working_dir_path = os.path.join(test_dir.path, 'tssc-working')
            step = FooStepImplementer(results_dir_path=results_dir_path,
                                      results_file_name='tssc-results.yml',
                                      work_dir_path=working_dir_path,
                                      config=sub_step)

            self.assertEqual(step.get_config_value('test'), 'hello world')
            self.assertIsNone(step.get_config_value('does-not-exist'))
Exemple #5
0
    def test_write_working_file_touch(self):
        """Test write working file touch"""
        config = Config({
            'tssc-config': {
                'foo': {
                    'implementer':
                    'tests.helpers.sample_step_implementers.FooStepImplementer',
                    'config': {}
                }
            }
        })
        step_config = config.get_step_config('foo')
        sub_step = (step_config.get_sub_step(
            'tests.helpers.sample_step_implementers.FooStepImplementer'))

        with TempDirectory() as test_dir:
            results_dir_path = os.path.join(test_dir.path, 'tssc-results')
            working_dir_path = os.path.join(test_dir.path, 'tssc-working')
            step = FooStepImplementer(results_dir_path=results_dir_path,
                                      results_file_name='tssc-results.yml',
                                      work_dir_path=working_dir_path,
                                      config=sub_step)

            step.write_working_file('test.json')

            working_file_path = os.path.join(working_dir_path, 'foo/test.json')
            self.assertTrue(os.path.exists(working_file_path))

            with open(working_file_path, 'r') as working_file:
                self.assertEqual(working_file.read(), '')
Exemple #6
0
    def test_get_step_results(self):
        """Test get step results"""
        implementer = 'tests.helpers.sample_step_implementers.WriteConfigAsResultsStepImplementer'
        config = Config({
            'tssc-config': {
                'write-config-as-results': {
                    'implementer': implementer,
                    'config': {
                        'config-1': "config-1",
                        'foo': "bar",
                    }
                },
                'foo': {
                    'implementer':
                    'tests.helpers.sample_step_implementers.FooStepImplementer',
                    'config': {}
                }
            }
        })
        write_config_as_results_step_config_sub_step = (config.get_step_config(
            'write-config-as-results').get_sub_step(implementer))

        foo_step_config = config.get_step_config('foo')
        foo_sub_step = (foo_step_config.get_sub_step(
            'tests.helpers.sample_step_implementers.FooStepImplementer'))

        with TempDirectory() as test_dir:
            results_dir_path = os.path.join(test_dir.path, 'tssc-results')
            write_config_step = WriteConfigAsResultsStepImplementer(
                results_dir_path=results_dir_path,
                results_file_name='tssc-results.yml',
                work_dir_path='tssc-working',
                config=write_config_as_results_step_config_sub_step)

            write_config_step.run_step()

            # verify step can return it's own results
            results_from_same_step = write_config_step.get_step_results(
                'write-config-as-results')
            self.assertEqual(results_from_same_step, {
                'config-1': "config-1",
                'foo': "bar",
            })

            # verify step can return results from a previous step
            foo_step = FooStepImplementer(results_dir_path=results_dir_path,
                                          results_file_name='tssc-results.yml',
                                          work_dir_path='tssc-working',
                                          config=foo_sub_step)

            results_from_diff_step = foo_step.get_step_results(
                'write-config-as-results')
            self.assertEqual(results_from_diff_step, {
                'config-1': "config-1",
                'foo': "bar",
            })
Exemple #7
0
    def test_create_working_dir_sub_dir(self):
        """Test create sub directory in working directory"""
        config = Config({
            'tssc-config': {
                'foo': {
                    'implementer':
                    'tests.helpers.sample_step_implementers.FooStepImplementer',
                    'config': {
                        'test': 'hello world',
                        'env-config-override-key': 'override-me',
                        'username': '******',
                        'password': '******'
                    },
                    'environment-config': {
                        'SAMPLE-ENV-1': {
                            'env-config-override-key':
                            'step env config - env 1 value - 1'
                        },
                        'SAMPLE-ENV-2': {
                            'env-config-override-key':
                            'step env config - env 2 value - 1'
                        }
                    },
                }
            }
        })
        step_config = config.get_step_config('foo')
        sub_step = (step_config.get_sub_step(
            'tests.helpers.sample_step_implementers.FooStepImplementer'))

        with TempDirectory() as test_dir:
            results_dir_path = os.path.join(test_dir.path, 'tssc-results')
            working_dir_path = os.path.join(test_dir.path, 'tssc-working')
            new_dir_path = os.path.join(working_dir_path, 'foo', 'test')
            step = FooStepImplementer(results_dir_path=results_dir_path,
                                      results_file_name='tssc-results.yml',
                                      work_dir_path=working_dir_path,
                                      config=sub_step,
                                      environment='SAMPLE-ENV-1')

            self.assertFalse(
                os.path.isdir(new_dir_path),
                msg='Sub directory in working directory should not exist yet')
            new_dir_created_path = step.create_working_dir_sub_dir('test')
            self.assertTrue(new_dir_created_path == new_dir_path,
                            msg='Sub directory created in the wrong place')
            self.assertTrue(
                os.path.isdir(new_dir_path),
                msg='Sub directory in working directory should exist')
    def test_from_step_implementer_with_env(self):
        config = Config({
            'step-runner-config': {
                'foo': {
                    'implementer':
                    'tests.helpers.sample_step_implementers.FooStepImplementer',
                    'config': {}
                }
            }
        })
        step_config = config.get_step_config('foo')
        sub_step = step_config.get_sub_step(
            'tests.helpers.sample_step_implementers.FooStepImplementer')

        step = FooStepImplementer(workflow_result=WorkflowResult(),
                                  parent_work_dir_path=None,
                                  config=sub_step,
                                  environment='blarg')

        step_result = StepResult.from_step_implementer(step)

        expected_step_result = StepResult(
            step_name='foo',
            sub_step_name=
            'tests.helpers.sample_step_implementers.FooStepImplementer',
            sub_step_implementer_name=
            'tests.helpers.sample_step_implementers.FooStepImplementer',
            environment='blarg')

        self.assertEqual(step_result, expected_step_result)
    def test_get_config_value_with_env(self):
        config = Config({
            'step-runner-config': {
                'foo': {
                    'implementer':
                    'tests.helpers.sample_step_implementers.FooStepImplementer',
                    'config': {
                        'test': 'hello world',
                        'env-config-override-key': 'override-me'
                    },
                    'environment-config': {
                        'SAMPLE-ENV-1': {
                            'env-config-override-key':
                            'step env config - env 1 value - 1'
                        },
                        'SAMPLE-ENV-2': {
                            'env-config-override-key':
                            'step env config - env 2 value - 1'
                        }
                    },
                }
            }
        })
        step_config = config.get_step_config('foo')
        sub_step = step_config.get_sub_step(
            'tests.helpers.sample_step_implementers.FooStepImplementer')

        with TempDirectory() as test_dir:
            results_dir_path = os.path.join(test_dir.path,
                                            'step-runner-results')
            working_dir_path = os.path.join(test_dir.path,
                                            'step-runner-working')
            step = FooStepImplementer(
                results_dir_path=results_dir_path,
                results_file_name='step-runner-results.yml',
                work_dir_path=working_dir_path,
                config=sub_step,
                environment='SAMPLE-ENV-1')

            self.assertEqual(step.get_config_value('test'), 'hello world')
            self.assertIsNone(step.get_config_value('does-not-exist'))
            self.assertEqual(step.get_config_value('env-config-override-key'),
                             'step env config - env 1 value - 1')
    def test_has_config_value(self):
        config = Config({
            'step-runner-config': {
                'foo': {
                    'implementer':
                    'tests.helpers.sample_step_implementers.FooStepImplementer',
                    'config': {
                        'test': 'hello world',
                        'env-config-override-key': 'override-me',
                        'username': '******',
                        'password': '******'
                    },
                    'environment-config': {
                        'SAMPLE-ENV-1': {
                            'env-config-override-key':
                            'step env config - env 1 value - 1'
                        },
                        'SAMPLE-ENV-2': {
                            'env-config-override-key':
                            'step env config - env 2 value - 1'
                        }
                    },
                }
            }
        })
        step_config = config.get_step_config('foo')
        sub_step = step_config.get_sub_step(
            'tests.helpers.sample_step_implementers.FooStepImplementer')

        with TempDirectory() as test_dir:
            results_dir_path = os.path.join(test_dir.path,
                                            'step-runner-results')
            working_dir_path = os.path.join(test_dir.path,
                                            'step-runner-working')
            step = FooStepImplementer(
                results_dir_path=results_dir_path,
                results_file_name='step-runner-results.yml',
                work_dir_path=working_dir_path,
                config=sub_step,
                environment='SAMPLE-ENV-1')

            self.assertFalse(step.has_config_value('bar'))
            self.assertFalse(step.has_config_value(['bar']))

            self.assertFalse(step.has_config_value(['username', 'foo'], False))
            self.assertTrue(step.has_config_value(['username', 'foo'], True))

            self.assertTrue(
                step.has_config_value(['username', 'password'], False))
            self.assertTrue(
                step.has_config_value(['username', 'password'], True))
    def test_result_files_and_paths(self):
        # overkill on tests here
        config = Config({
            'step-runner-config': {
                'foo': {
                    'implementer':
                    'tests.helpers.sample_step_implementers.FooStepImplementer',
                    'config': {}
                }
            }
        })
        step_config = config.get_step_config('foo')
        sub_step = step_config.get_sub_step(
            'tests.helpers.sample_step_implementers.FooStepImplementer')

        with TempDirectory() as test_dir:
            results_dir_path = os.path.join(test_dir.path, 'myresults')
            working_dir_path = os.path.join(test_dir.path, 'mytesting')
            step = FooStepImplementer(results_dir_path=results_dir_path,
                                      results_file_name='myfile',
                                      work_dir_path=working_dir_path,
                                      config=sub_step)

            self.assertEqual(f'{results_dir_path}/myfile',
                             step.results_file_path)

            self.assertEqual(f'{results_dir_path}', step.results_dir_path)

            self.assertEqual(f'{working_dir_path}', step.work_dir_path)

            self.assertEqual(f'{working_dir_path}/foo',
                             step.work_dir_path_step)

            self.assertEqual(
                f'{working_dir_path}/myfile.pkl',
                step._StepImplementer__workflow_result_pickle_file_path)