import numpy as np import pytest from src.backend import models from src.backend.constants import FlagResolutions class TestNewAudit: model = models.NewAudit def test_new_audit(self): new_audit = self.model(label_id=1) assert new_audit.label_id == 1 assert new_audit.audit_audio is True def test_new_audit_no_audit_type_included(self): with pytest.raises(ValueError): self.model( label_id=1, audit_audio=False, audit_video=False, audit_art_track=False ) class TestNewAuditFlag: model = models.NewAuditFlag _sample_data = { "row_idx": 1, "upc": "123", "isrc": "456", "asset_id": "789", "video_id": "101112", "text": "text", "details": "details", } def test_new_audit_flag(self): instance = self.model(**self._sample_data) for key, value in self._sample_data.items(): assert getattr(instance, key) == value def test_flag_text_stripped(self): instance = self.model(**self._sample_data | {"text": " test "}) assert instance.text == "test" def test_flag_text_mandatory(self): with pytest.raises(ValueError): self.model(**self._sample_data | {"text": None}) def test_one_of_isrc_upc_video_id_is_mandatory(self): with pytest.raises(ValueError): self.model( **self._sample_data | {"isrc": None, "upc": None, "video_id": None} ) def test_upc_casted_to_string(self): instance = self.model(**self._sample_data | {"upc": 123}) assert instance.upc == "123" @pytest.mark.parametrize("nan", [np.nan, float("nan")]) def test_nan_converted_to_none(self, nan): instance = self.model(**self._sample_data, resolution=nan) assert instance.resolution is None @pytest.mark.parametrize("container_type", [set, list, tuple]) def test_details_as_containers_concatenaded_string(self, container_type): instance = self.model( **self._sample_data | {"details": container_type(["a", "b", "c"])} ) assert instance.details == "a, b, c" def test_resolution_must_be_none_or_flagresolution(self): with pytest.raises(ValueError): self.model( **self._sample_data, resolution="resolution", ) def test_resolution_subtype_must_be_none_or_flagresolution(self): with pytest.raises(ValueError): self.model( **self._sample_data, resolution_subtype="resolution_subtype", ) def test_resolution_and_resolution_subtype_are_flagresolutions(self): instance = self.model( **self._sample_data, resolution=FlagResolutions.IGNORE, resolution_subtype=FlagResolutions.ASSET_OK, ) assert instance.resolution == FlagResolutions.IGNORE assert instance.resolution_subtype == FlagResolutions.ASSET_OK def test_resolution_should_not_be_none_if_resolution_subtype_is_not_none(self): with pytest.raises(ValueError): self.model( **self._sample_data, resolution=None, resolution_subtype="resolution_subtype", )