Exemplo n.º 1
0
 def test_export_config_file_when_was_present_in_env_data(self):
     self.assertEqual(
         env.BoothEnv(
             "report processor", {
                 "name": "booth-name",
                 "config_file": {
                     "content": "a\nb",
                 },
                 "key_file": {
                     "content": "secure",
                 },
                 "key_path": "/path/to/file.key",
             }).export(), {
                 "config_file": {
                     "content": "a\nb",
                     "can_overwrite_existing_file": False,
                     "no_existing_file_expected": False,
                     "is_binary": False,
                 },
                 "key_file": {
                     "content": "secure",
                     "can_overwrite_existing_file": False,
                     "no_existing_file_expected": False,
                     "is_binary": True,
                 },
             })
Exemplo n.º 2
0
 def test_get_content_from_file(self, mock_real_file):
     mock_real_file.return_value = mock.MagicMock(read=mock.MagicMock(
         return_value="content"))
     self.assertEqual(
         "content",
         env.BoothEnv("report processor", env_data={
             "name": "booth"
         }).get_config_content())
Exemplo n.º 3
0
 def test_push_config(self, mock_real_file):
     mock_file = mock.MagicMock(
         assert_no_conflict_with_existing=mock.MagicMock(),
         write=mock.MagicMock(),
     )
     mock_real_file.return_value = mock_file
     env.BoothEnv("report processor", env_data={
         "name": "booth"
     }).push_config("a")
     mock_file.write.assert_called_once_with("a")
Exemplo n.º 4
0
 def test_invalid_instance(self):
     # pylint: disable=no-self-use
     assert_raise_library_error(
         lambda: env.BoothEnv("/tmp/booth/booth", {}),
         fixture.error(
             report_codes.BOOTH_INVALID_NAME,
             name="/tmp/booth/booth",
             reason="contains illegal character '/'",
         ),
     )
Exemplo n.º 5
0
 def test_invalid_instance(self):
     # pylint: disable=no-self-use
     assert_raise_library_error(
         lambda: env.BoothEnv("/tmp/booth/booth", {}),
         fixture.error(
             report_codes.BOOTH_INVALID_NAME,
             name="/tmp/booth/booth",
             forbidden_characters="/",
         ),
     )
Exemplo n.º 6
0
 def test_real_conf_ghost_key(self):
     # pylint: disable=no-self-use
     assert_raise_library_error(
         lambda: env.BoothEnv(
             "my_booth", {"key_data": "some key data".encode("utf-8")}),
         fixture.error(
             report_codes.LIVE_ENVIRONMENT_NOT_CONSISTENT,
             mocked_files=[file_type_codes.BOOTH_KEY],
             required_files=[file_type_codes.BOOTH_CONFIG],
         ),
     )
Exemplo n.º 7
0
    def test_create_config(self, mock_real_file, mock_set_keyfile_access):
        # pylint: disable=unused-argument
        mock_file = mock.MagicMock(
            assert_no_conflict_with_existing=mock.MagicMock(),
            write=mock.MagicMock(),
        )
        mock_real_file.return_value = mock_file

        env.BoothEnv("report processor", env_data={
            "name": "booth"
        }).create_config("a", can_overwrite_existing=True)

        self.assertEqual(mock_file.assert_no_conflict_with_existing.mock_calls,
                         [mock.call('report processor', True)])
        self.assertEqual(mock_file.write.mock_calls, [mock.call('a')])
Exemplo n.º 8
0
 def test_invalid_instance_ghost(self):
     # pylint: disable=no-self-use
     assert_raise_library_error(
         lambda: env.BoothEnv(
             "../../booth/booth", {
                 "config_data": "some config data",
                 "key_data": "some key data",
                 "key_path": "some key path",
             }),
         fixture.error(
             report_codes.BOOTH_INVALID_NAME,
             name="../../booth/booth",
             reason="contains illegal character '/'",
         ),
     )
Exemplo n.º 9
0
    def test_ghost(self):
        config_data = "some config_data".encode("utf-8")
        key_data = "some key_data".encode("utf-8")
        key_path = "some key path"
        my_env = env.BoothEnv(
            "my_booth",
            {
                "config_data": config_data,
                "key_data": key_data,
                "key_path": key_path,
            },
        )
        self.assertEqual("my_booth", my_env.instance_name)
        self.assertTrue(isinstance(my_env.config.raw_file, GhostFile))
        self.assertTrue(isinstance(my_env.key.raw_file, GhostFile))
        with self.assertRaises(AssertionError) as cm:
            dummy_path = my_env.config_path
        self.assertEqual(
            "Reading config path is supported only in live environment",
            str(cm.exception),
        )
        self.assertEqual(key_path, my_env.key_path)
        self.assertEqual(
            [file_type_codes.BOOTH_CONFIG, file_type_codes.BOOTH_KEY],
            my_env.ghost_file_codes,
        )
        self.assertEqual(
            {
                "config_file": {
                    "content": config_data
                },
                "key_file": {
                    "content": key_data
                },
            },
            my_env.export(),
        )

        site_list = ["site1", "site2"]
        arbitrator_list = ["arbitrator1"]
        facade = my_env.create_facade(site_list, arbitrator_list)
        self.assertEqual(site_list, facade.get_sites())
        self.assertEqual(arbitrator_list, facade.get_arbitrators())
Exemplo n.º 10
0
    def test_real(self):
        my_env = env.BoothEnv("my_booth", {})
        self.assertEqual("my_booth", my_env.instance_name)
        self.assertFalse(isinstance(my_env.config.raw_file, GhostFile))
        self.assertFalse(isinstance(my_env.key.raw_file, GhostFile))
        self.assertEqual(
            os.path.join(settings.booth_config_dir, "my_booth.conf"),
            my_env.config_path)
        self.assertEqual(
            os.path.join(settings.booth_config_dir, "my_booth.key"),
            my_env.key_path)
        self.assertEqual([], my_env.ghost_file_codes)
        self.assertEqual({}, my_env.export())

        site_list = ["site1", "site2"]
        arbitrator_list = ["arbitrator1"]
        facade = my_env.create_facade(site_list, arbitrator_list)
        self.assertEqual(site_list, facade.get_sites())
        self.assertEqual(arbitrator_list, facade.get_arbitrators())
Exemplo n.º 11
0
 def test_do_not_export_config_file_when_no_provided(self):
     self.assertEqual(
         env.BoothEnv("report processor", {
             "name": "booth"
         }).export(), {})
Exemplo n.º 12
0
 def test_default_instance(self):
     self.assertEqual(env.BoothEnv(None, {}).instance_name, "booth")