예제 #1
0
    def test_config_exists_in_custom_path(self):
        with open('config.ini', 'w') as f:
            custom_conf = ConfigParser()
            custom_conf.add_section('Section5')
            custom_conf.set('Section5', 'Option7', 'Value11')
            custom_conf.set('Section5', 'Option8', 'Value12')
            custom_conf.add_section('Section6')
            custom_conf.set('Section6', 'Option9', 'Value13')
            custom_conf.write(f)

        from libmozdata import config
        config.set_config(config.ConfigIni('config.ini'))

        self.assertEqual(config.get('Section5', 'Option7'), 'Value11')
        self.assertEqual(config.get('Section5', 'Option7', 'Default'),
                         'Value11')
        self.assertEqual(config.get('Section5', 'Option8'), 'Value12')
        self.assertEqual(config.get('Section5', 'Option8', 'Default'),
                         'Value12')
        self.assertEqual(config.get('Section6', 'Option9'), 'Value13')
        self.assertEqual(config.get('Section6', 'Option9', 'Default'),
                         'Value13')
        self.assertIsNone(config.get('Section5', 'Option9'))
        self.assertEqual(config.get('Section5', 'Option9', 'Default'),
                         'Default')
예제 #2
0
    def test_config_get_with_type(self):
        with open('mozdata.ini', 'w') as f:
            custom_conf = ConfigParser()
            custom_conf.add_section('Section')
            custom_conf.set('Section', 'Option', 'Value')
            custom_conf.set('Section', 'Option2', '123')
            custom_conf.add_section('Section2')
            custom_conf.set('Section2', 'Option', 'Value1, Value2, Value3')
            custom_conf.write(f)

        from libmozdata import config

        self.assertEqual(config.get('Section', 'Option'), 'Value')
        self.assertEqual(config.get('Section', 'Option2', type=int), 123)
        self.assertEqual(config.get('Section', 'Option2', type=str), '123')
        self.assertEqual(config.get('Section2', 'Option', type=list),
                         ['Value1', 'Value2', 'Value3'])
        self.assertEqual(config.get('Section2', 'Option', type=set),
                         {'Value1', 'Value2', 'Value3'})
예제 #3
0
def get_bugzilla_http_client():
    """ Copied from libmozdata.connection.Connection and libmozdata.bugzilla.Bugzilla
    """
    http_client = requests.Session()
    status_forcelist = [429]
    retries = Retry(total=256, backoff_factor=1, status_forcelist=status_forcelist)
    bugzilla_url = config.get("Bugzilla", "URL", "https://bugzilla.mozilla.org")
    bugzilla_api_url = bugzilla_url + "/rest/bug"
    http_client.mount(bugzilla_url, HTTPAdapter(max_retries=retries))

    return http_client, bugzilla_api_url
예제 #4
0
    def test_config_exists_in_cwd(self):
        with open('mozdata.ini', 'w') as f:
            custom_conf = ConfigParser()
            custom_conf.add_section('Section')
            custom_conf.set('Section', 'Option', 'Value')
            custom_conf.set('Section', 'Option2', 'Value2')
            custom_conf.add_section('Section2')
            custom_conf.set('Section2', 'Option', 'Value3')
            custom_conf.write(f)

        from libmozdata import config

        self.assertEqual(config.get('Section', 'Option'), 'Value')
        self.assertEqual(config.get('Section', 'Option', 'Default'), 'Value')
        self.assertEqual(config.get('Section', 'Option2'), 'Value2')
        self.assertEqual(config.get('Section', 'Option2', 'Default'), 'Value2')
        self.assertEqual(config.get('Section2', 'Option'), 'Value3')
        self.assertEqual(config.get('Section2', 'Option', 'Default'), 'Value3')
        self.assertIsNone(config.get('Section', 'Option3'))
        self.assertEqual(config.get('Section', 'Option3', 'Default'),
                         'Default')
예제 #5
0
    def test_config_exists_in_home(self):
        with open(os.path.expanduser('~/.mozdata.ini'), 'w') as f:
            custom_conf = ConfigParser()
            custom_conf.add_section('Section3')
            custom_conf.set('Section3', 'Option5', 'Value8')
            custom_conf.set('Section3', 'Option6', 'Value9')
            custom_conf.add_section('Section4')
            custom_conf.set('Section4', 'Option7', 'Value10')
            custom_conf.write(f)

        from libmozdata import config

        self.assertEqual(config.get('Section3', 'Option5'), 'Value8')
        self.assertEqual(config.get('Section3', 'Option5', 'Default'),
                         'Value8')
        self.assertEqual(config.get('Section3', 'Option6'), 'Value9')
        self.assertEqual(config.get('Section3', 'Option6', 'Default'),
                         'Value9')
        self.assertEqual(config.get('Section4', 'Option7'), 'Value10')
        self.assertEqual(config.get('Section4', 'Option7', 'Default'),
                         'Value10')
        self.assertIsNone(config.get('Section3', 'Option7'))
        self.assertEqual(config.get('Section3', 'Option7', 'Default'),
                         'Default')
예제 #6
0
 def test_config_doesnt_exist(self):
     from libmozdata import config
     self.assertIsNone(config.get('Section', 'Option'))
     self.assertEqual(config.get('Section', 'Option', 'Default'), 'Default')