Exemple #1
0
    def test_makedf_only_required_should_contain_required(self):
        """
        Running makeDockerfile when dfgen was initialized with a file containing only required values,
         Dockerfile output should contain lines only related to the required values.
        """
        os.remove("./dfgen.cfg")
        with open('./dfgen.cfg', 'w') as dfgen_config:
            dfgen_config.write(config_required)

        dfgenerator = dfgen.DFGen()

        dfgenerator.makeDockerfile()
        df_lines = []
        with open('./Dockerfile', 'r') as dockerfile:
            df_lines = dockerfile.readlines()

        for line in df_lines:
            self.assertFalse("RUN pip install" in line)

        fromindex = self._find_str_in_list(df_lines, 'FROM')
        envindex = self._find_str_in_list(
            df_lines, 'ENV DEBIAN_FRONTEND noninteractive')
        aptget_index = self._find_str_in_list(
            df_lines,
            'RUN apt-get update && apt-get -y upgrade && apt-get clean')
        install_index = self._find_str_in_list(
            df_lines, 'RUN apt-get -y install --no-install-recommends')
        useradd_index = self._find_str_in_list(df_lines,
                                               "RUN useradd -m teleceptor")
        user_index = self._find_str_in_list(df_lines, 'USER teleceptor')
        workdir_index = self._find_str_in_list(df_lines,
                                               'WORKDIR /home/teleceptor/')

        self.assertTrue(fromindex < envindex < aptget_index < install_index <
                        useradd_index < user_index < workdir_index)
Exemple #2
0
    def test_makedf_only_required_should_create_file(self):
        os.remove("./dfgen.cfg")
        with open('./dfgen.cfg', 'w') as dfgen_config:
            dfgen_config.write(config_required)

        dfgenerator = dfgen.DFGen()

        dfgenerator.makeDockerfile()
        self.assertTrue(os.path.exists('./Dockerfile'))
Exemple #3
0
    def test_missing_required_should_raise_valueerror(self):
        os.remove("./dfgen.cfg")
        with open('./dfgen.cfg', 'w') as dfgen_config:
            for line in config_required.split('\n'):
                if 'email_address =' in line:
                    continue
                dfgen_config.write(line)

        self.assertRaises(ValueError, lambda: dfgen.DFGen())
Exemple #4
0
 def test_required_and_optional_should_pass(self):
     dfgen.DFGen()
Exemple #5
0
 def test_only_required_should_pass(self):
     os.remove("./dfgen.cfg")
     with open('./dfgen.cfg', 'w') as dfgen_config:
         dfgen_config.write(config_required)
     dfgen.DFGen()
Exemple #6
0
    def test_empty_config_raise_valueerror(self):
        os.remove("./dfgen.cfg")
        with open('./dfgen.cfg', 'w') as dfgen_config:
            dfgen_config.write('')

        self.assertRaises(ValueError, lambda: dfgen.DFGen())
Exemple #7
0
 def test_no_config_should_raise_exception(self):
     #remove dfgen.cfg
     os.remove("./dfgen.cfg")
     self.assertRaises(ValueError, lambda: dfgen.DFGen())