Ejemplo n.º 1
0
    def test_option_override_with_sqlite_as_db(self):
        sample_config = """
[Database]
type = sqlite

[sqlite]
save_directory = /home/demouser/storage
session_save_directory = /home/demouser/output
session_id_start = 2345

[track_session]
track = True
tracking_db = http://fun.new.machine.edu/tracking
        """
        config_file = "opsim4_options_with_sqlite_testing"
        with open(os.path.join('.', config_file), 'w') as cfile:
            cfile.write(sample_config)

        config = read_file_config(config_file, '.')

        options = collections.namedtuple("options", [
            "db_type", "sqlite_save_dir", "sqlite_session_save_dir",
            "session_id_start", "track_session", "tracking_db"
        ])
        # Set option defaults
        options.db_type = "mysql"
        options.sqlite_save_dir = None
        options.sqlite_session_save_dir = None
        options.session_id_start = None
        options.track_session = False
        options.tracking_db = None

        apply_file_config(config, options)
        self.assertEqual(options.db_type, "sqlite")
        self.assertEqual(options.sqlite_save_dir, "/home/demouser/storage")
        self.assertEqual(options.sqlite_session_save_dir,
                         "/home/demouser/output")
        self.assertEqual(options.session_id_start, 2345)
        self.assertTrue(options.track_session)
        self.assertEqual(options.tracking_db,
                         "http://fun.new.machine.edu/tracking")

        os.remove(config_file)
Ejemplo n.º 2
0
 def test_read_file_section_no_option(self):
     parser = read_file_config(self.config_file, self.config_dir)
     with self.assertRaises(configparser.NoOptionError):
         parser.get("mysql", "save_directory")
Ejemplo n.º 3
0
 def test_read_file_no_config_dir(self):
     with mock.patch.dict("os.environ", {"HOME": "."}, clear=True):
         parser = read_file_config(self.config_file)
         self.assertEqual(parser.get("Database", "type"), "mysql")
Ejemplo n.º 4
0
 def test_read_default_file(self):
     parser = read_file_config(None, self.config_dir)
     self.assertIsNone(parser)
Ejemplo n.º 5
0
 def test_read_no_file(self):
     parser = read_file_config("opsim3", self.config_dir)
     self.assertIsNone(parser)
Ejemplo n.º 6
0
 def test_read_file(self):
     parser = read_file_config(self.config_file, self.config_dir)
     self.assertEqual(parser.get("Database", "type"), "mysql")
     self.assertEqual(parser.get("mysql", "config_path"), "/home/demouser/mysql")
Ejemplo n.º 7
0
 def test_read_file_section_no_option(self):
     parser = read_file_config(self.config_file, self.config_dir)
     with self.assertRaises(configparser.NoOptionError):
         parser.get("sqlite", "config_path")
Ejemplo n.º 8
0
 def test_read_file_no_section(self):
     parser = read_file_config(self.config_file, self.config_dir)
     with self.assertRaises(configparser.NoSectionError):
         parser.get("mysql", "save_directory")
Ejemplo n.º 9
0
 def test_read_file_no_config_dir(self):
     with mock.patch.dict('os.environ', {"HOME": '.'}, clear=True):
         parser = read_file_config(self.config_file)
         self.assertEqual(parser.get("Database", "type"), "sqlite")
Ejemplo n.º 10
0
 def test_read_default_file(self):
     parser = read_file_config(None, self.config_dir)
     self.assertIsNone(parser)
Ejemplo n.º 11
0
 def test_read_no_file(self):
     parser = read_file_config("opsim3", self.config_dir)
     self.assertIsNone(parser)
Ejemplo n.º 12
0
 def test_read_file(self):
     parser = read_file_config(self.config_file, self.config_dir)
     self.assertEqual(parser.get("Database", "type"), "sqlite")
     self.assertEqual(parser.get("sqlite", "save_directory"),
                      "/home/demouser/run/output")