# Copyright © The Debusine Developers
# See the AUTHORS file at the top-level directory of this distribution
#
# This file is part of Debusine. It is subject to the license terms
# in the LICENSE file found in the top-level directory of this
# distribution. No part of Debusine, including this file, may be copied,
# modified, propagated, or distributed except according to the terms
# contained in the LICENSE file.

"""Tests for the DB-aware mock field resolver."""

from debusine.artifacts.models import CollectionCategory
from debusine.db.tasks.mock_resolver import MockFieldResolver
from debusine.db.tasks.models import DBArtifactInfo, DBInputCollectionSingle
from debusine.test.django import TestCase


class MockFieldResolverTests(TestCase):
    """Tests for :py:class:`MockFieldResolver`."""

    def test_set_artifact(self) -> None:
        resolver = MockFieldResolver()
        artifact = self.playground.create_minimal_binary_package_artifact()
        resolver.set_artifact("test", artifact)
        self.assertEqual(
            resolver.field_values["test"],
            DBArtifactInfo.from_artifact(
                artifact, lookup=artifact.id, label="test"
            ),
        )

    def test_set_collection(self) -> None:
        resolver = MockFieldResolver()
        collection = self.playground.create_collection(
            name="sid", category=CollectionCategory.SUITE
        )
        resolver.set_collection("test", collection)
        self.assertEqual(
            resolver.field_values["test"],
            DBInputCollectionSingle.from_collection(
                collection, lookup=collection.id, label="test"
            ),
        )
