Beispiel #1
0
    def test_config_file(self):
        """
        Test the configuration with a regular config file
        """
        # Get the current directory and pass it the path of test_config.ini
        scitokens.set_config(os.path.join(self.dir_path, "test_config.ini"))

        self.assertEqual(scitokens.utils.config.get("log_file"), "")
        self.assertEqual(scitokens.utils.config.get("log_level"), "DEBUG")
Beispiel #2
0
    def test_passing_config(self):
        """
        Test the passing of a configuration parser object
        """
        new_config = configparser.ConfigParser()
        new_config.add_section("scitokens")
        new_config.set("scitokens", "log_level", "WARNING")

        scitokens.set_config(new_config)

        self.assertEqual(scitokens.utils.config.get("log_level"), "WARNING")
Beispiel #3
0
    def test_passing_config_log(self):
        """
        Test the with log_file
        """

        new_config = configparser.ConfigParser()
        new_config.add_section("scitokens")
        new_config.set("scitokens", "log_level", "WARNING")
        tmp_file = tempfile.NamedTemporaryFile()
        new_config.set("scitokens", "log_file", tmp_file.name)

        scitokens.set_config(new_config)

        self.assertEqual(scitokens.utils.config.get("log_level"), "WARNING")
        self.assertEqual(scitokens.utils.config.get("log_file"), tmp_file.name)

        # Log a line
        logger = logging.getLogger("scitokens")
        logger.error("This is an error")
        tmp_file.flush()
        print(os.path.getsize(tmp_file.name))
        self.assertTrue(os.path.getsize(tmp_file.name) > 0)

        tmp_file.close()
Beispiel #4
0
 def tearDown(self):
     # Clear the config back to defaults each time
     scitokens.set_config()