Skip to content

Commit

Permalink
test: pytestify "tests/unittests/config/test_cc_timezone.py" (canonic…
Browse files Browse the repository at this point in the history
…al#5885)

Refactors the code in the file "tests/unittests/config/test_cc_timezone.py" 
using pytest. This helps remove dependance of this test on 
"tests/unittests/helpers.py:FileSystemMockingTestCase"

Fixes: part of canonicalGH-5760
  • Loading branch information
MaheshG11 authored and mathmarchand committed Nov 29, 2024
1 parent 4a5b550 commit c9e27e7
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions tests/unittests/config/test_cc_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,35 @@
# This file is part of cloud-init. See LICENSE file for license information.

import logging
import shutil
import tempfile
from io import BytesIO

from configobj import ConfigObj

from cloudinit import util
from cloudinit.config import cc_timezone
from tests.unittests import helpers as t_help
from tests.unittests.util import get_cloud

LOG = logging.getLogger(__name__)


class TestTimezone(t_help.FilesystemMockingTestCase):
def setUp(self):
super(TestTimezone, self).setUp()
self.new_root = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.new_root)
self.patchUtils(self.new_root)
self.patchOS(self.new_root)

def test_set_timezone_sles(self):
class TestTimezone:

def test_set_timezone_sles(self, fake_filesystem):
cfg = {
"timezone": "Tatooine/Bestine",
}
cc = get_cloud("sles")

# Create a dummy timezone file
dummy_contents = "0123456789abcdefgh"
util.write_file(
"/usr/share/zoneinfo/%s" % cfg["timezone"], dummy_contents
)

cc_timezone.handle("cc_timezone", cfg, cc, [])

contents = util.load_binary_file("/etc/sysconfig/clock")
n_cfg = ConfigObj(BytesIO(contents))
self.assertEqual({"TIMEZONE": cfg["timezone"]}, dict(n_cfg))

assert {"TIMEZONE": cfg["timezone"]} == dict(n_cfg)

contents = util.load_text_file("/etc/localtime")
self.assertEqual(dummy_contents, contents.strip())
assert dummy_contents == contents.strip()

0 comments on commit c9e27e7

Please sign in to comment.