Ejemplo n.º 1
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)
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
 def test_it_should_count_chars_in_a_string(self):
     word = 'abbbcd;;;;;;;;;;;;;;'
     count = Utils.count_occurrences(word)
     self.assertEqual( 1, count.get('a', 0))
     self.assertEqual( 3, count.get('b', 0))
     self.assertEqual(14, count.get(';', 0))
     self.assertEqual( 0, count.get('%', 0))
Ejemplo n.º 4
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'])
Ejemplo n.º 5
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
Ejemplo n.º 6
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'])
Ejemplo n.º 7
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')))
Ejemplo n.º 8
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'])
Ejemplo n.º 9
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')))
Ejemplo n.º 10
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))