Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: mock network functions so tests work with no network #312

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dnf install python3-requests python3-cryptography python3-libvirt python3-lxml p

If you wish to test on EL 7, make that:

yum install python-requests python-cryptography libvirt-python python-lxml python-libguestfs pytest python-monotonic
yum install python-requests python-cryptography libvirt-python python-lxml python-libguestfs pytest python-monotonic python-mock

then run the tests:

Expand Down
9 changes: 8 additions & 1 deletion tests/guest/test_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from io import StringIO
import logging
import os
try:
from unittest import mock
except ImportError:
import mock

# Find oz library
prefix = '.'
Expand Down Expand Up @@ -72,7 +76,10 @@ def setup_guest(xml, macaddress=None):
config = configparser.ConfigParser()
config.read_file(StringIO("[libvirt]\nuri=qemu:///session\nbridge_name=%s" % route))

guest = oz.GuestFactory.guest_factory(tdl, config, None, macaddress=macaddress)
# mock this - it's used in RedHatLinuxCDYumGuest._check_url() -
# so the tests can run without a network connection
with mock.patch("oz.ozutil.http_get_header", return_value={}):
guest = oz.GuestFactory.guest_factory(tdl, config, None, macaddress=macaddress)
return guest

tdlxml = """
Expand Down
7 changes: 6 additions & 1 deletion tests/tdl/test_tdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import sys
import os
try:
from unittest import mock
except ImportError:
import mock

try:
import lxml.etree
Expand Down Expand Up @@ -100,7 +104,8 @@
}

# Test that iterates over all .tdl files
def test_all():
@mock.patch("oz.ozutil.http_download_file")
def test_all(fakedl):
for (tdl, expected_pass) in list(tests.items()):

# locate full path for tdl file
Expand Down