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

Remove pytest-mock dependency #2005

Merged
merged 1 commit into from
Oct 29, 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
4 changes: 2 additions & 2 deletions requirements-dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pip-tools
pytest
pytest-cov
pytest-django
pytest-mock
pytest-playwright
pytest-randomly
tox
Expand All @@ -15,5 +14,6 @@ tox
# See https://github.com/microsoft/playwright-python/issues/2190
git+https://github.com/microsoft/playwright-python.git@d9cdfbb1e178b6770625e9f857139aff77516af0#egg=playwright

# coverage 7.6.2 dropped support for Python 3.8, so pinning it for now.
# These dependencies dropped support for Python 3.8, so pinning them for now.
coverage[toml]==7.6.1
pytest-randomly==3.15.0
13 changes: 5 additions & 8 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ olefile==0.47
# opf-fido
opf-fido @ git+https://github.com/artefactual-labs/fido.git@564ceb8018a8650fe931cf20e6780ee008e60fca
# via -r requirements.txt
orjson==3.10.9
orjson==3.10.10
# via -r requirements.txt
packaging==24.1
# via
Expand Down Expand Up @@ -213,7 +213,6 @@ pytest==8.3.3
# pytest-base-url
# pytest-cov
# pytest-django
# pytest-mock
# pytest-playwright
# pytest-randomly
pytest-base-url==2.1.0
Expand All @@ -222,8 +221,6 @@ pytest-cov==5.0.0
# via -r requirements-dev.in
pytest-django==4.9.0
# via -r requirements-dev.in
pytest-mock==3.14.0
# via -r requirements-dev.in
pytest-playwright==0.5.2
# via -r requirements-dev.in
pytest-randomly==3.15.0
Expand Down Expand Up @@ -286,7 +283,7 @@ tomli==2.0.2
# pyproject-api
# pytest
# tox
tox==4.23.1
tox==4.23.2
# via -r requirements-dev.in
typing-extensions==4.12.2
# via
Expand All @@ -302,7 +299,7 @@ urllib3==2.2.3
# amclient
# elasticsearch
# requests
virtualenv==20.27.0
virtualenv==20.27.1
# via tox
wheel==0.44.0
# via pip-tools
Expand All @@ -317,13 +314,13 @@ zope-event==5.0
# via
# -r requirements.txt
# gevent
zope-interface==7.1.0
zope-interface==7.1.1
# via
# -r requirements.txt
# gevent

# The following packages are considered to be unsafe in a requirements file:
pip==24.2
pip==24.3.1
# via pip-tools
setuptools==75.2.0
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ prometheus_client
python-dateutil
requests
unidecode
whitenoise

# Required by LDAP authentication
django-auth-ldap
Expand All @@ -42,3 +41,4 @@ mozilla-django-oidc
django-auth-ldap==5.0.0
gevent==24.2.1
jsonschema-specifications==2023.12.1
whitenoise==6.7.0
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ olefile==0.47
# via opf-fido
opf-fido @ git+https://github.com/artefactual-labs/fido.git@564ceb8018a8650fe931cf20e6780ee008e60fca
# via -r requirements.in
orjson==3.10.9
orjson==3.10.10
# via -r requirements.in
packaging==24.1
# via gunicorn
Expand Down Expand Up @@ -170,7 +170,7 @@ zipp==3.20.2
# importlib-resources
zope-event==5.0
# via gevent
zope-interface==7.1.0
zope-interface==7.1.1
# via gevent

# The following packages are considered to be unsafe in a requirements file:
Expand Down
49 changes: 36 additions & 13 deletions tests/MCPClient/test_antivirus.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from collections import OrderedDict
from collections import namedtuple
from unittest import mock

import archivematica_clamscan
import pytest
Expand Down Expand Up @@ -79,30 +80,39 @@ def version_attrs(self):


def setup_test_scan_file_mocks(
mocker,
get_scanner,
file_already_scanned_mock,
file_objects_get,
file_already_scanned=False,
file_size=1024,
scanner_should_except=False,
scanner_passed=False,
):
file_already_scanned_mock.return_value = file_already_scanned
file_objects_get.return_value = FileMock(size=file_size)
deps = namedtuple("deps", ["file_already_scanned", "file_get", "scanner"])(
file_already_scanned=mocker.patch(
"archivematica_clamscan.file_already_scanned",
return_value=file_already_scanned,
),
file_get=mocker.patch(
"main.models.File.objects.get", return_value=FileMock(size=file_size)
),
file_already_scanned=file_already_scanned_mock,
file_get=file_objects_get,
scanner=ScannerMock(should_except=scanner_should_except, passed=scanner_passed),
)

mocker.patch("archivematica_clamscan.get_scanner", return_value=deps.scanner)
get_scanner.return_value = deps.scanner

return deps


def test_scan_file_already_scanned(mocker):
deps = setup_test_scan_file_mocks(mocker, file_already_scanned=True)
@mock.patch("archivematica_clamscan.file_already_scanned")
@mock.patch("main.models.File.objects.get")
@mock.patch("archivematica_clamscan.get_scanner")
def test_scan_file_already_scanned(
get_scanner, file_objects_get, file_already_scanned_mock
):
deps = setup_test_scan_file_mocks(
get_scanner,
file_already_scanned_mock,
file_objects_get,
file_already_scanned=True,
)

exit_code = archivematica_clamscan.scan_file([], **dict(args))

Expand Down Expand Up @@ -160,8 +170,21 @@ def test_scan_file_already_scanned(mocker):
),
],
)
def test_scan_file(mocker, setup_kwargs, exit_code, queue_event_params, settings):
setup_test_scan_file_mocks(mocker, **setup_kwargs)
@mock.patch("archivematica_clamscan.file_already_scanned")
@mock.patch("main.models.File.objects.get")
@mock.patch("archivematica_clamscan.get_scanner")
def test_scan_file(
get_scanner,
file_objects_get,
file_already_scanned_mock,
setup_kwargs,
exit_code,
queue_event_params,
settings,
):
setup_test_scan_file_mocks(
get_scanner, file_already_scanned_mock, file_objects_get, **setup_kwargs
)

# Here the user configurable thresholds for maimum file size, and maximum
# scan size are being tested. The scan size is offset so as to enable the
Expand Down
Loading
Loading