コード例 #1
0
 def test_data_path_returns_file_path_with_defined_data_paths(
     self, key, path_basename
 ):
     """When key is defined in Config.data_paths return data_path value."""
     cfg = UAConfig({"data_dir": "/my/dir"})
     private_path = "/my/dir/{}/{}".format(PRIVATE_SUBDIR, path_basename)
     assert private_path == cfg.data_path(key=key)
コード例 #2
0
 def test_write_datetime(self, tmpdir):
     cfg = UAConfig({"data_dir": tmpdir.strpath})
     key = "test_key"
     dt = datetime.datetime.now()
     cfg.write_cache(key, dt)
     with open(cfg.data_path(key)) as f:
         assert dt.isoformat() == f.read().strip('"')
コード例 #3
0
    def test_cache_file_is_written_world_readable(self, _m_getuid,
                                                  _m_get_available_resources,
                                                  tmpdir):
        cfg = UAConfig({"data_dir": tmpdir.strpath})
        cfg.status()

        assert 0o644 == stat.S_IMODE(
            os.lstat(cfg.data_path("status-cache")).st_mode)
コード例 #4
0
 def test_data_path_returns_file_path_with_undefined_data_paths(
     self, key, path_basename
 ):
     """When key is not in Config.data_paths the key is used to data_dir"""
     cfg = UAConfig({"data_dir": "/my/d"})
     assert "/my/d/{}/{}".format(PRIVATE_SUBDIR, key) == cfg.data_path(
         key=key
     )
コード例 #5
0
    def test_delete_cache_properly_clears_all_caches_simple(
            self, tmpdir, property_name, data_path_name, expected_null_value):
        """
        Ensure that delete_cache clears the cache for simple attributes

        (Simple in this context means those that are simply read from the
        filesystem and returned.)
        """
        property_value = 'our-value'
        cfg = UAConfig({'data_dir': tmpdir.strpath})

        data_path = cfg.data_path(data_path_name)
        with open(data_path, 'w') as f:
            f.write(property_value)

        before_prop_value = getattr(cfg, property_name)
        assert before_prop_value == property_value

        cfg.delete_cache()

        after_prop_value = getattr(cfg, property_name)
        assert expected_null_value == after_prop_value
コード例 #6
0
    def test_cache_file_is_written_world_readable(
        self,
        _m_getuid,
        _m_get_available_resources,
        _m_should_reboot,
        m_remove_notice,
        tmpdir,
    ):
        cfg = UAConfig({"data_dir": tmpdir.strpath})
        status.status(cfg=cfg)

        assert 0o644 == stat.S_IMODE(
            os.lstat(cfg.data_path("status-cache")).st_mode)

        expected_calls = [
            mock.call(
                "",
                messages.ENABLE_REBOOT_REQUIRED_TMPL.format(
                    operation="fix operation"),
            )
        ]

        assert expected_calls == m_remove_notice.call_args_list
コード例 #7
0
 def test_permissions(self, tmpdir, datapath, mode):
     cfg = UAConfig({"data_dir": tmpdir.strpath})
     cfg.data_paths = {"path": datapath}
     cfg.write_cache("path", "")
     assert mode == stat.S_IMODE(os.lstat(cfg.data_path("path")).st_mode)
コード例 #8
0
 def test_data_path_returns_public_path_for_public_datapath(self):
     cfg = UAConfig({"data_dir": "/my/d"})
     cfg.data_paths["test_path"] = DataPath("test_path", False)
     assert "/my/d/test_path" == cfg.data_path("test_path")
コード例 #9
0
 def test_data_path_returns_data_dir_path_without_key(self):
     """The data_path method returns the data_dir when key is absent."""
     cfg = UAConfig({"data_dir": "/my/dir"})
     assert "/my/dir/{}".format(PRIVATE_SUBDIR) == cfg.data_path()
コード例 #10
0
 def test_data_path_returns_file_path_with_undefined_data_paths(
         self, key, path_basename):
     """When key is not in Config.data_paths the key is used to data_dir"""
     cfg = UAConfig({'data_dir': '/my/d'})
     assert '/my/d/%s/%s' % (PRIVATE_SUBDIR, key) == cfg.data_path(key=key)
コード例 #11
0
 def test_data_path_returns_file_path_with_defined_data_paths(
         self, key, path_basename):
     """When key is defined in Config.data_paths return data_path value."""
     cfg = UAConfig({'data_dir': '/my/dir'})
     private_path = '/my/dir/%s/%s' % (PRIVATE_SUBDIR, path_basename)
     assert private_path == cfg.data_path(key=key)
コード例 #12
0
 def test_data_path_returns_data_dir_path_without_key(self):
     """The data_path method returns the data_dir when key is absent."""
     cfg = UAConfig({'data_dir': '/my/dir'})
     assert '/my/dir/%s' % PRIVATE_SUBDIR == cfg.data_path()
コード例 #13
0
 def test_data_path_returns_file_path_with_public_data_paths(
         self, key, path_basename):
     """When private is False Config.data_paths return a public path."""
     cfg = UAConfig({'data_dir': '/my/d'})
     assert '/my/d/%s' % key == cfg.data_path(key=key, private=False)
コード例 #14
0
 def test_data_path_returns_file_path_with_defined_data_paths(
         self, key, path_basename):
     """When key is defined in Config.data_paths return data_path value."""
     cfg = UAConfig({'data_dir': '/my/dir'})
     assert '/my/dir/%s' % path_basename == cfg.data_path(key=key)