Exemplo n.º 1
0
 def test_read_config_file(self) -> Any:
     with self.assertRaises(IOError):
         server.read_config_file("nonexistentfile.conf")
     current_dir = os.path.dirname(os.path.abspath(__file__))
     bot_conf1 = server.read_config_file(
         os.path.join(current_dir, "test.conf"))
     expected_config1 = {
         'helloworld': {
             'email': '*****@*****.**',
             'key': 'value',
             'site': 'http://localhost',
         },
         'giphy': {
             'email': '*****@*****.**',
             'key': 'value2',
             'site': 'http://localhost',
         }
     }
     assert json.dumps(bot_conf1,
                       sort_keys=True) == json.dumps(expected_config1,
                                                     sort_keys=True)
     bot_conf2 = server.read_config_file(
         os.path.join(current_dir, "test.conf"), "redefined_bot")
     expected_config2 = {
         'redefined_bot': {
             'email': '*****@*****.**',
             'key': 'value',
             'site': 'http://localhost',
         }
     }
     assert json.dumps(bot_conf2,
                       sort_keys=True) == json.dumps(expected_config2,
                                                     sort_keys=True)
Exemplo n.º 2
0
 def test_read_config_file(self) -> None:
     with self.assertRaises(IOError):
         server.read_config_file("nonexistentfile.conf")
     current_dir = os.path.dirname(os.path.abspath(__file__))
     bot_conf1 = server.read_config_file(os.path.join(current_dir, "test.conf"))
     expected_config1 = {
         'helloworld': {
             'email': '*****@*****.**',
             'key': 'value',
             'site': 'http://localhost',
             'token': 'abcd1234',
         },
         'giphy': {
             'email': '*****@*****.**',
             'key': 'value2',
             'site': 'http://localhost',
             'token': 'abcd1234',
         }
     }
     assert json.dumps(bot_conf1, sort_keys=True) == json.dumps(expected_config1, sort_keys=True)
     bot_conf2 = server.read_config_file(os.path.join(current_dir, "test.conf"), "redefined_bot")
     expected_config2 = {
         'redefined_bot': {
             'email': '*****@*****.**',
             'key': 'value',
             'site': 'http://localhost',
             'token': 'abcd1234',
         }
     }
     assert json.dumps(bot_conf2, sort_keys=True) == json.dumps(expected_config2, sort_keys=True)
Exemplo n.º 3
0
    def test_read_config_file(self) -> None:
        with self.assertRaises(IOError):
            server.read_config_file("nonexistentfile.conf")
        current_dir = os.path.dirname(os.path.abspath(__file__))

        # No bot specified; should read all bot configs.
        bot_conf1 = server.read_config_file(
            os.path.join(current_dir, "test.conf"))
        expected_config1 = {
            "helloworld": {
                "email": "*****@*****.**",
                "key": "value",
                "site": "http://localhost",
                "token": "abcd1234",
            },
            "giphy": {
                "email": "*****@*****.**",
                "key": "value2",
                "site": "http://localhost",
                "token": "abcd1234",
            },
        }
        assert json.dumps(bot_conf1,
                          sort_keys=True) == json.dumps(expected_config1,
                                                        sort_keys=True)

        # Specified bot exists; should read only that section.
        bot_conf3 = server.read_config_file(
            os.path.join(current_dir, "test.conf"), "giphy")
        expected_config3 = {
            "giphy": {
                "email": "*****@*****.**",
                "key": "value2",
                "site": "http://localhost",
                "token": "abcd1234",
            }
        }
        assert json.dumps(bot_conf3,
                          sort_keys=True) == json.dumps(expected_config3,
                                                        sort_keys=True)

        # Specified bot doesn't exist; should read the first section of the config.
        bot_conf2 = server.read_config_file(
            os.path.join(current_dir, "test.conf"), "redefined_bot")
        expected_config2 = {
            "redefined_bot": {
                "email": "*****@*****.**",
                "key": "value",
                "site": "http://localhost",
                "token": "abcd1234",
            }
        }
        assert json.dumps(bot_conf2,
                          sort_keys=True) == json.dumps(expected_config2,
                                                        sort_keys=True)
Exemplo n.º 4
0
    def test_read_config_file(self) -> None:
        with self.assertRaises(IOError):
            server.read_config_file("nonexistentfile.conf")
        current_dir = os.path.dirname(os.path.abspath(__file__))

        # No bot specified; should read all bot configs.
        bot_conf1 = server.read_config_file(
            os.path.join(current_dir, "test.conf"))
        expected_config1 = {
            'helloworld': {
                'email': '*****@*****.**',
                'key': 'value',
                'site': 'http://localhost',
                'token': 'abcd1234',
            },
            'giphy': {
                'email': '*****@*****.**',
                'key': 'value2',
                'site': 'http://localhost',
                'token': 'abcd1234',
            }
        }
        assert json.dumps(bot_conf1,
                          sort_keys=True) == json.dumps(expected_config1,
                                                        sort_keys=True)

        # Specified bot exists; should read only that section.
        bot_conf3 = server.read_config_file(
            os.path.join(current_dir, "test.conf"), "giphy")
        expected_config3 = {
            'giphy': {
                'email': '*****@*****.**',
                'key': 'value2',
                'site': 'http://localhost',
                'token': 'abcd1234',
            }
        }
        assert json.dumps(bot_conf3,
                          sort_keys=True) == json.dumps(expected_config3,
                                                        sort_keys=True)

        # Specified bot doesn't exist; should read the first section of the config.
        bot_conf2 = server.read_config_file(
            os.path.join(current_dir, "test.conf"), "redefined_bot")
        expected_config2 = {
            'redefined_bot': {
                'email': '*****@*****.**',
                'key': 'value',
                'site': 'http://localhost',
                'token': 'abcd1234',
            }
        }
        assert json.dumps(bot_conf2,
                          sort_keys=True) == json.dumps(expected_config2,
                                                        sort_keys=True)