Esempio n. 1
0
 def test_it_should_raise_exception_config_file_not_exists(self):
     try:
         Utils.get_variables_from_file(os.path.abspath('unexistent.conf'))
         self.fail("it should not get here")
     except Exception, e:
         self.assertEqual(
             "%s: file not found" % os.path.abspath('unexistent.conf'),
             str(e))
Esempio n. 2
0
    def test_it_should_not_change_python_path(self):
        original_paths = []
        for path in sys.path:
            original_paths.append(path)

        Utils.get_variables_from_file(os.path.abspath('sample.py'))

        self.assertEqual(original_paths, sys.path)
Esempio n. 3
0
    def test_it_should_not_change_python_path(self):
        original_paths = []
        for path in sys.path:
            original_paths.append(path)

        Utils.get_variables_from_file(os.path.abspath('sample.py'))

        self.assertEqual(original_paths, sys.path)
Esempio n. 4
0
 def test_it_should_raise_exception_config_file_has_a_sintax_problem(self):
     f = open('sample.py', 'a')
     f.write('\nimport some_not_imported_module\n')
     f.close()
     try:
         Utils.get_variables_from_file(os.path.abspath('sample.py'))
         self.fail("it should not get here")
     except Exception, e:
         self.assertEqual("error interpreting config file 'sample.py': No module named some_not_imported_module", str(e))
Esempio n. 5
0
 def test_it_should_raise_exception_config_file_has_a_sintax_problem(self):
     f = open('sample.py', 'a')
     f.write('\nimport some_not_imported_module\n')
     f.close()
     try:
         Utils.get_variables_from_file(os.path.abspath('sample.py'))
         self.fail("it should not get here")
     except Exception, e:
         self.assertEqual(
             "error interpreting config file 'sample.py': No module named some_not_imported_module",
             str(e))
Esempio n. 6
0
 def test_it_should_extract_variables_from_a_config_file_with_py_extension(self):
     variables = Utils.get_variables_from_file(os.path.abspath('sample.py'))
     self.assertEqual('root', variables['DATABASE_USER'])
     self.assertEqual('migration_example_env1', variables['ENV1_DATABASE_NAME'])
     self.assertEqual('migration_example', variables['DATABASE_NAME'])
     self.assertEqual('example', variables['DATABASE_MIGRATIONS_DIR'])
     self.assertEqual(True, variables['UTC_TIMESTAMP'])
     self.assertEqual('localhost', variables['DATABASE_HOST'])
     self.assertEqual('', variables['DATABASE_PASSWORD'])
Esempio n. 7
0
 def test_it_should_extract_variables_from_a_config_file_with_py_extension(
         self):
     variables = Utils.get_variables_from_file(os.path.abspath('sample.py'))
     self.assertEqual('root', variables['DATABASE_USER'])
     self.assertEqual('migration_example_env1',
                      variables['ENV1_DATABASE_NAME'])
     self.assertEqual('migration_example', variables['DATABASE_NAME'])
     self.assertEqual('example', variables['DATABASE_MIGRATIONS_DIR'])
     self.assertEqual(True, variables['UTC_TIMESTAMP'])
     self.assertEqual('localhost', variables['DATABASE_HOST'])
     self.assertEqual('', variables['DATABASE_PASSWORD'])
Esempio n. 8
0
    def _get_commands(self):
        try:
            variables = Utils.get_variables_from_file(self.abspath, self.script_encoding)
            SQL_UP = Migration.ensure_sql_unicode(variables['SQL_UP'], self.script_encoding)
            SQL_DOWN = Migration.ensure_sql_unicode(variables['SQL_DOWN'], self.script_encoding)
        except KeyError:
            raise Exception("migration file is incorrect; it does not define 'SQL_UP' or 'SQL_DOWN' (%s)" % self.abspath)

        if SQL_UP is None or SQL_UP == "":
            raise Exception("migration command 'SQL_UP' is empty (%s)" % self.abspath)

        if SQL_DOWN is None or SQL_DOWN == "":
            raise Exception("migration command 'SQL_DOWN' is empty (%s)" % self.abspath)

        return SQL_UP, SQL_DOWN
Esempio n. 9
0
    def _get_commands(self):
        try:
            variables = Utils.get_variables_from_file(self.abspath,
                                                      self.script_encoding)
            SQL_UP = Migration.ensure_sql_unicode(variables['SQL_UP'],
                                                  self.script_encoding)
            SQL_DOWN = Migration.ensure_sql_unicode(variables['SQL_DOWN'],
                                                    self.script_encoding)
        except KeyError:
            raise Exception(
                "migration file is incorrect; it does not define 'SQL_UP' or 'SQL_DOWN' (%s)"
                % self.abspath)

        if SQL_UP is None or SQL_UP == "":
            raise Exception("migration command 'SQL_UP' is empty (%s)" %
                            self.abspath)

        if SQL_DOWN is None or SQL_DOWN == "":
            raise Exception("migration command 'SQL_DOWN' is empty (%s)" %
                            self.abspath)

        return SQL_UP, SQL_DOWN
Esempio n. 10
0
 def test_it_should_extract_variables_from_a_file_with_python_code(self):
     variables = Utils.get_variables_from_file(
         os.path.abspath('sample2.conf'))
     self.assertEqual('51', variables['SOME_CONSTANT'])
Esempio n. 11
0
 def test_it_should_delete_compiled_module_file(self):
     Utils.get_variables_from_file(os.path.abspath('sample.py'))
     self.assertFalse(os.path.exists(os.path.abspath('sample.pyc')))
Esempio n. 12
0
 def test_it_should_extract_variables_from_a_file_with_python_code(self):
     variables = Utils.get_variables_from_file(os.path.abspath('sample2.conf'))
     self.assertEqual('51', variables['SOME_CONSTANT'])
Esempio n. 13
0
 def test_it_should_delete_compiled_module_file(self):
     Utils.get_variables_from_file(os.path.abspath('sample.py'))
     self.assertFalse(os.path.exists(os.path.abspath('sample.pyc')))
Esempio n. 14
0
 def test_it_should_raise_exception_config_file_not_exists(self):
     try:
         Utils.get_variables_from_file(os.path.abspath('unexistent.conf'))
         self.fail("it should not get here")
     except Exception, e:
         self.assertEqual("%s: file not found" % os.path.abspath('unexistent.conf'), str(e))