def test_TSSCFactory_run_step_config_only_sub_step_and_is_dict_rather_then_array(
):
    config = {'tssc-config': {'foo': {'implementer': 'FooStepImplementer'}}}
    factory = TSSCFactory(config, 'results.yml')
    TSSCFactory.register_step_implementer(FooStepImplementer)

    factory.run_step('foo')
Esempio n. 2
0
def test_mvn_quickstart_single_jar_no_pom():
    with TempDirectory() as temp_dir:
        temp_dir.write('src/main/java/com/mycompany/app/App.java',b'''package com.mycompany.app;
public class App {
    public static void main( String[] args ) {
        System.out.println( "Hello World!" );
    }
}''')
        pom_file_path = os.path.join(temp_dir.path, 'pom.xml')
        config = {
            'tssc-config': {
                'package': {
                    'implementer': 'Maven',
                }
            }
        }
        expected_step_results = {
            'tssc-results': {
                'package': {
                    'artifacts': {
                        'my-app-1.0-SNAPSHOT.jar': os.path.join(temp_dir.path, 'target', 'my-app-1.0-SNAPSHOT.jar')
                    }
                }
            }
        }
        factory = TSSCFactory(config)
        with pytest.raises(ValueError):
            factory.run_step('package')
 def test_mvn_quickstart_single_jar_java_error(self, mvn_mock):
     with TempDirectory() as temp_dir:
         temp_dir.write(
             'src/main/java/com/mycompany/app/App.java',
             b'''package com.mycompany.app;
 public class Fail {
     public static void main( String[] args ) {
         System.out.println( "Hello World!" );
     }
 }''')
         temp_dir.write(
             'pom.xml', b'''<project>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.mycompany.app</groupId>
     <artifactId>my-app</artifactId>
     <version>1.0</version>
 </project>''')
         pom_file_path = os.path.join(temp_dir.path, 'pom.xml')
         config = {
             'tssc-config': {
                 'package': {
                     'implementer': 'Maven',
                     'config': {
                         'pom-file': str(pom_file_path)
                     }
                 }
             }
         }
         factory = TSSCFactory(config)
         with self.assertRaisesRegex(RuntimeError, 'Error invoking mvn:.*'):
             factory.run_step('package')
def test_TSSCFactory_run_step_config_specfied_StepImplementer_does_not_exist():
    config = {'tssc-config': {'foo': [{'implementer': 'DoesNotExist'}]}}
    factory = TSSCFactory(config, 'results.yml')
    TSSCFactory.register_step_implementer(FooStepImplementer)

    with pytest.raises(TSSCException):
        factory.run_step('foo')
    def test_pom_file_missing_version(self):
        with TempDirectory() as temp_dir:
            temp_dir.write(
                'pom.xml', b'''<project>
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.mycompany.app</groupId>
        <artifactId>my-app</artifactId>
    </project>''')
            pom_file_path = os.path.join(temp_dir.path, 'pom.xml')

            config = {
                'tssc-config': {
                    'generate-metadata': {
                        'implementer': 'Maven',
                        'config': {
                            'pom-file': str(pom_file_path)
                        }
                    }
                }
            }
            factory = TSSCFactory(config)

        with self.assertRaisesRegex(ValueError,
                                    r"Given pom file does not exist:"):
            factory.run_step('generate-metadata')
    def test_unit_test_missing_surefire_plugin_in_pom(self):
        group_id = 'com.mycompany.app'
        artifact_id = 'my-app'
        version = '1.0'
        with TempDirectory() as temp_dir:
            temp_dir.write(
                'pom.xml',
                bytes(
                    '''<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
  xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <modelVersion>4.0.0</modelVersion>
        <groupId>{group_id}</groupId>
        <artifactId>{artifact_id}</artifactId>
        <version>{version}</version>
</project>'''.format(group_id=group_id,
                     artifact_id=artifact_id,
                     version=version), 'utf-8'))
            pom_file_path = os.path.join(temp_dir.path, 'pom.xml')
            config = {
                'tssc-config': {
                    'unit-test': {
                        'implementer': 'Maven',
                        'config': {
                            'pom-file': str(pom_file_path)
                        }
                    }
                }
            }
            factory = TSSCFactory(config)
            with self.assertRaisesRegex(
                    ValueError,
                    'Unit test dependency "maven-surefire-plugin" missing from POM.'
            ):
                factory.run_step('unit-test')
    def run_step_test_with_result_validation(self,
                                             temp_dir,
                                             step_name,
                                             config,
                                             expected_step_results,
                                             runtime_args=None,
                                             environment=None,
                                             expected_stdout=None,
                                             expected_stderr=None):
        results_dir_path = os.path.join(temp_dir.path, 'tssc-results')
        working_dir_path = os.path.join(temp_dir.path, 'tssc-working')

        factory = TSSCFactory(config,
                              results_dir_path,
                              work_dir_path=working_dir_path)
        if runtime_args:
            factory.config.set_step_config_overrides(step_name, runtime_args)

        out = StringIO()
        err = StringIO()
        with redirect_stdout(out), redirect_stderr(err):
            factory.run_step(step_name, environment)

        if expected_stdout is not None:
            self.assertRegex(out.getvalue(), expected_stdout)

        if expected_stderr is not None:
            self.assertRegex(err.getvalue(), expected_stderr)

        results_file_name = "tssc-results.yml"
        with open(os.path.join(results_dir_path, results_file_name),
                  'r') as step_results_file:
            actual_step_results = yaml.safe_load(step_results_file.read())

            self.assertEqual(actual_step_results, expected_step_results)
def test_TSSCFactory_run_step_config_implementer_specfied_and_no_sub_step_config_specified_StepImplementer(
):
    config = {'tssc-config': {'foo': [{'implementer': 'FooStepImplementer'}]}}
    factory = TSSCFactory(config, 'results.yml')
    TSSCFactory.register_step_implementer(FooStepImplementer)

    factory.run_step('foo')
def test_TSSCFactory_run_step_default_StepImplementer_for_step_without_config(
):
    config = {'tssc-config': {}}
    factory = TSSCFactory(config, 'results.yml')
    TSSCFactory.register_step_implementer(FooStepImplementer, True)

    factory.run_step('foo')
Esempio n. 10
0
def _run_step_implementer_test(config, step, expected_step_results, test_dir):
    results_dir_path = os.path.join(test_dir.path, 'tssc-results')
    factory = TSSCFactory(config, results_dir_path)
    factory.run_step(step)

    with open(os.path.join(results_dir_path, "tssc-results.yml"), 'r') as step_results_file:
        step_results = yaml.safe_load(step_results_file.read())
        assert step_results == expected_step_results
Esempio n. 11
0
def test_TSSCFactory_run_step_no_default_StepImplementer_for_step_without_config(
):
    config = {'tssc-config': {}}
    factory = TSSCFactory(config, 'results.yml')
    TSSCFactory.register_step_implementer(FooStepImplementer)

    with pytest.raises(TSSCException):
        factory.run_step('foo')
Esempio n. 12
0
 def test_uat_mandatory_selenium_hub_url_missing(self, _mvn_mock):
     """Test when mandatory selenium hub url is missing."""
     config = {'tssc-config': {'uat': {'implementer': 'Maven'}}}
     factory = TSSCFactory(config)
     error_message = '.* is missing the required configuration keys ' \
         '\\(\\[\'selenium-hub-url\'\\]\\).*'
     with self.assertRaisesRegex(AssertionError, error_message):
         factory.run_step('uat')
 def test_unit_test_runtime_pom_file_missing(self, mvn_mock):
     config = {'tssc-config': {'unit-test': {'implementer': 'Maven'}}}
     factory = TSSCFactory(config)
     with self.assertRaisesRegex(
             ValueError,
             "Given pom file does not exist: does-not-exist-pom.xml"):
         factory.config.set_step_config_overrides(
             'unit-test', {'pom-file': 'does-not-exist-pom.xml'})
         factory.run_step('unit-test')
    def test_init_invalid_config(self):
        config = {
            'blarg-config': {
            }
        }

        with self.assertRaisesRegex(
                AssertionError,
                r"Failed to add invalid TSSC config. Missing expected top level key \(tssc-config\): {'blarg-config': {}}"):
            TSSCFactory(config)
    def test_run_step_config_only_sub_step_and_is_dict_rather_then_array(self):
        config = {
            'tssc-config': {
                'foo': {
                        'implementer': 'tests.helpers.sample_step_implementers.FooStepImplementer'
                }
            }
        }
        factory = TSSCFactory(config, 'results.yml')

        factory.run_step('foo')
    def test_run_step_with_no_config(self):
        config = {
            'tssc-config': {
            }
        }
        factory = TSSCFactory(config, 'results.yml')

        with self.assertRaisesRegex(
                AssertionError,
                r"Can not run step \(foo\) because no step configuration provided."):
            factory.run_step('foo')
Esempio n. 17
0
 def test_uat_mandatory_target_base_url_missing(self, _mvn_mock):
     """Test when mandatory target base url is missing."""
     config = {'tssc-config': {'uat': {'implementer': 'Maven'}}}
     factory = TSSCFactory(config)
     with self.assertRaisesRegex(ValueError,
                                 'No target base url was specified'):
         factory.config.set_step_config_overrides(
             'uat', {
                 'selenium-hub-url': SELENIUM_HUB_URL,
             })
         factory.run_step('uat')
Esempio n. 18
0
def test_runtime_pom_file_missing ():
    config = {
        'tssc-config': {
            'package': {
                'implementer': 'Maven'
            }
        }
    }
    factory = TSSCFactory(config)
    with pytest.raises(ValueError):
        factory.run_step('package', {'pom-file': 'does-not-exist-pom.xml'})
    def test_init_with_config_object(self):
        config = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': {
                    'implementer': 'foo'
                }
            }
        }
        tssc_config = Config(config)
        factory = TSSCFactory(tssc_config, 'results.yml')

        self.assertEqual(factory.config, tssc_config)
    def test_run_step_config_implementer_specfied_and_no_sub_step_config_specified_StepImplementer(self):
        config = {
            'tssc-config': {
                'foo': [
                    {
                        'implementer': 'tests.helpers.sample_step_implementers.FooStepImplementer'
                    }
                ]
            }
        }
        factory = TSSCFactory(config, 'results.yml')

        factory.run_step('foo')
    def test_init_with_dict(self):
        config = {
            Config.TSSC_CONFIG_KEY: {
                'step-foo': {
                    'implementer': 'foo'
                }
            }
        }
        factory = TSSCFactory(config, 'results.yml')

        sub_step_configs = factory.config.get_sub_step_configs('step-foo')

        self.assertEqual(len(sub_step_configs), 1)
Esempio n. 22
0
def test_config_file_pom_file_missing():
    config = {
        'tssc-config': {
            'generate-metadata': {
                'implementer': 'Maven',
                'config': {
                    'pom-file': 'does-not-exist.pom'
                }
            }
        }
    }
    factory = TSSCFactory(config)
    with pytest.raises(ValueError):
        factory.run_step('generate-metadata')
Esempio n. 23
0
def test_config_file_pom_file_none_value():
    config = {
        'tssc-config': {
            'generate-metadata': {
                'implementer': 'Maven',
                'config': {
                    'pom-file': None
                }
            }
        }
    }
    factory = TSSCFactory(config)
    with pytest.raises(ValueError):
        factory.run_step('generate-metadata')
Esempio n. 24
0
 def test_uat_runtime_pom_file_missing(self, _mvn_mock):
     """Test when pom file is invalid."""
     config = {'tssc-config': {'uat': {'implementer': 'Maven'}}}
     factory = TSSCFactory(config)
     with self.assertRaisesRegex(
             ValueError,
             'Given pom file does not exist: does-not-exist-pom.xml'):
         factory.config.set_step_config_overrides(
             'uat', {
                 'pom-file': 'does-not-exist-pom.xml',
                 'selenium-hub-url': SELENIUM_HUB_URL,
                 'target-base-url': TARGET_BASE_URL
             })
         factory.run_step('uat')
Esempio n. 25
0
    def _run_step_implementer_test(self,
                                   config,
                                   step,
                                   expected_step_results,
                                   test_dir,
                                   environment=None):

        results_dir_path = os.path.join(test_dir.path, 'tssc-results')
        factory = TSSCFactory(config, results_dir_path)
        factory.run_step(step_name=step, environment=environment)

        with open(os.path.join(results_dir_path, "tssc-results.yml"),
                  'r') as step_results_file:
            step_results = yaml.safe_load(step_results_file.read())
            self.assertEqual(step_results, expected_step_results)
 def test_unit_test_config_file_pom_file_missing(self, mvn_mock):
     config = {
         'tssc-config': {
             'unit-test': {
                 'implementer': 'Maven',
                 'config': {
                     'pom-file': 'does-not-exist.pom'
                 }
             }
         }
     }
     factory = TSSCFactory(config)
     with self.assertRaisesRegex(
             ValueError,
             'Given pom file does not exist: does-not-exist.pom'):
         factory.run_step('unit-test')
    def test_runtime_pom_file_missing(self):
        config = {
            'tssc-config': {
                'generate-metadata': {
                    'implementer': 'Maven'
                }
            }
        }
        factory = TSSCFactory(config)
        with self.assertRaisesRegex(
                ValueError,
                r"Given pom file does not exist: does-not-exist-pom.xml"):

            factory.config.set_step_config_overrides(
                'generate-metadata', {'pom-file': 'does-not-exist-pom.xml'})
            factory.run_step('generate-metadata')
 def test_config_file_pom_file_missing(self):
     config = {
         'tssc-config': {
             'generate-metadata': {
                 'implementer': 'Maven',
                 'config': {
                     'pom-file': 'does-not-exist.pom'
                 }
             }
         }
     }
     factory = TSSCFactory(config)
     with self.assertRaisesRegex(
             ValueError,
             r"Given pom file does not exist: does-not-exist.pom"):
         factory.run_step('generate-metadata')
    def test_run_step_config_specfied_StepImplementer_does_not_exist(self):
        config = {
            'tssc-config': {
                'foo': [
                    {
                        'implementer': 'DoesNotExist'
                    }
                ]
            }
        }
        factory = TSSCFactory(config, 'results.yml')

        with self.assertRaisesRegex(
                TSSCException,
                r"Could not dynamically load step \(foo\) step implementer \(DoesNotExist\) from module \(tssc.step_implementers.foo\) with class name \(DoesNotExist\)"):
            factory.run_step('foo')
 def test_config_file_package_file_none_value(self):
     config = {
         'tssc-config': {
             'generate-metadata': {
                 'implementer': 'Npm',
                 'config': {
                     'package-file': None
                 }
             }
         }
     }
     factory = TSSCFactory(config)
     with self.assertRaisesRegex(
             AssertionError,
             r"The runtime step configuration \(\{'package-file': None\}\) is missing the required configuration keys \(\['package-file'\]\)"
     ):
         factory.run_step('generate-metadata')