Ejemplo n.º 1
0
 def test_parsing(self):
     """Test config file parsing."""
     config = WeblateConfig()
     self.assertEqual(config.get("weblate", "url"), wlc.API_URL)
     config.load()
     config.load(TEST_CONFIG)
     self.assertEqual(config.get("weblate", "url"), "https://example.net/")
Ejemplo n.º 2
0
 def test_default_config_values(self):
     """Test default parser values."""
     config = WeblateConfig()
     self.assertEqual(config.get("weblate", "key"), "")
     self.assertEqual(config.get("weblate", "retries"), 0)
     self.assertEqual(
         config.get("weblate", "method_whitelist"),
         "HEAD\nTRACE\nDELETE\nOPTIONS\nPUT\nGET",
     )
     self.assertEqual(config.get("weblate", "backoff_factor"), 0)
     self.assertEqual(config.get("weblate", "status_forcelist"), None)
Ejemplo n.º 3
0
def parse_settings(args, settings):
    """Read settings based on command-line params."""
    config = WeblateConfig(args.config_section)
    if settings is None:
        config.load(args.config)
    else:
        for section, key, value in settings:
            config.set(section, key, value)

    for override in ("key", "url"):
        value = getattr(args, override)
        if value is not None:
            config.set(args.config_section, override, value)

    return config
Ejemplo n.º 4
0
 def test_get_retry_options(self):
     """Test the get_retry_options method when all options are in config."""
     config = WeblateConfig()
     config.load()
     config.load(TEST_CONFIG)
     (
         retries,
         status_forcelist,
         method_whitelist,
         backoff_factor,
     ) = config.get_retry_options()
     self.assertEqual(retries, 999)
     self.assertEqual(status_forcelist, [429, 500, 502, 503, 504])
     self.assertEqual(method_whitelist, ["PUT", "POST"])
     self.assertEqual(backoff_factor, 0.2)
Ejemplo n.º 5
0
def parse_settings(args, settings):
    """Read settings based on command line params."""

    config = WeblateConfig(args.config_section)
    if settings is None:
        config.load(args.config)
    else:
        for section, key, value in settings:
            config.set(section, key, value)

    for override in ("key", "url"):
        value = getattr(args, override)
        if value is not None:
            config.set(args.config_section, override, value)

    return config
Ejemplo n.º 6
0
 def test_json_encoder(self):
     """Test JSON encoder."""
     output = StringIO()
     cmd = Version(args=[], config=WeblateConfig(), stdout=output)
     with self.assertRaises(TypeError):
         cmd.print_json(self)
Ejemplo n.º 7
0
 def test_parsing(self):
     """Test config file parsing."""
     config = WeblateConfig()
     self.assertEqual(config.get("weblate", "url"), wlc.API_URL)
     config.load()
     config.load(TEST_CONFIG)
     self.assertEqual(config.get("weblate", "url"), "https://example.net/")
     self.assertEqual(config.get("weblate", "retries"), "999")
     self.assertEqual(config.get("weblate", "method_whitelist"), "PUT,POST")
     self.assertEqual(config.get("weblate", "backoff_factor"), "0.2")
     self.assertEqual(config.get("weblate", "status_forcelist"),
                      "429,500,502,503,504")