From 27695671adf54c2295a2e64292a9c6b255711ef3 Mon Sep 17 00:00:00 2001 From: Brian Scholer <1260690+briantist@users.noreply.github.com> Date: Sun, 8 Oct 2023 12:25:55 -0400 Subject: [PATCH] centralize fixture --- tests/unit/models/test_collectiondata.py | 35 +++++++---------------- tests/unit/models/test_collectiongroup.py | 17 ----------- 2 files changed, 11 insertions(+), 41 deletions(-) diff --git a/tests/unit/models/test_collectiondata.py b/tests/unit/models/test_collectiondata.py index 4cf4f70..2ebc252 100644 --- a/tests/unit/models/test_collectiondata.py +++ b/tests/unit/models/test_collectiondata.py @@ -145,51 +145,38 @@ def test_collectiondata_compare_versioninfo( assert (col < ver) == (col.is_prerelease) -def test_collectiondata_compare_othertypes(mocker: MockFixture): +def test_collectiondata_compare_othertypes(mocker: MockFixture, collection_data: CollectionData): spy_eq = mocker.spy(CollectionData, '__eq__') spy_lt = mocker.spy(CollectionData, '__lt__') - coldata = CollectionData( - collection_info={}, - created_datetime=datetime.now(timezone.utc), - modified_datetime=datetime.now(timezone.utc), - filename='fname', - mime_type='mime', - size=0, - namespace='ns', - name='col', - version='1.2.3', - sha256='a', - ) - standin = 5 - assert coldata != mocker.sentinel.whatever - spy_eq.assert_called_once_with(coldata, mocker.sentinel.whatever) + assert collection_data != mocker.sentinel.whatever + spy_eq.assert_called_once_with(collection_data, mocker.sentinel.whatever) assert spy_eq.spy_return is NotImplemented spy_eq.reset_mock() - assert coldata != standin - spy_eq.assert_called_once_with(coldata, standin) + assert collection_data != standin + spy_eq.assert_called_once_with(collection_data, standin) assert spy_eq.spy_return is NotImplemented spy_eq.reset_mock() - assert standin != coldata - spy_eq.assert_called_once_with(coldata, standin) + assert standin != collection_data + spy_eq.assert_called_once_with(collection_data, standin) assert spy_eq.spy_return is NotImplemented spy_eq.reset_mock() rmsg = r"not supported between instances of 'CollectionData' and" with pytest.raises(TypeError, match=rmsg): - assert not (coldata < standin) - spy_lt.assert_called_once_with(coldata, standin) + assert not (collection_data < standin) + spy_lt.assert_called_once_with(collection_data, standin) assert spy_lt.spy_return is NotImplemented spy_lt.reset_mock() with pytest.raises(TypeError, match=rmsg): - assert not (coldata > standin) - spy_lt.assert_called_once_with(coldata, standin) + assert not (collection_data > standin) + spy_lt.assert_called_once_with(collection_data, standin) assert spy_lt.spy_return is NotImplemented spy_lt.reset_mock() diff --git a/tests/unit/models/test_collectiongroup.py b/tests/unit/models/test_collectiongroup.py index da58e23..48cb7e5 100644 --- a/tests/unit/models/test_collectiongroup.py +++ b/tests/unit/models/test_collectiongroup.py @@ -5,28 +5,11 @@ import re from semver import VersionInfo -from datetime import datetime, timezone from pytest_mock import MockFixture from galactory.models import CollectionData, CollectionGroup -@pytest.fixture -def collection_data() -> CollectionData: - return CollectionData( - collection_info={}, - namespace='ns', - name='name', - created_datetime=datetime.now(timezone.utc), - modified_datetime=datetime.now(timezone.utc), - filename='fake-file', - mime_type='fake-file', - sha256='m-m-m-my-sha-', - size=0, - version='0.0.0', - ) - - @pytest.mark.parametrize('name', ['collection_name', 'name2']) @pytest.mark.parametrize('namespace', ['a_namespace', 'ns1']) def test_collectiongroup_init(namespace, name):