-
-
Save Debakel/637ef714fea9375191ba7ff6e500d62a to your computer and use it in GitHub Desktop.
File.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pytest import mark | |
from core.factories import TargetRightsFactory, ExceptionalTargetRightsFactory, RightFactory | |
from custom.factories import ProcessingTypeFactory | |
from lateral.factories import AssetSubTypeFactory | |
from validator.compliance_check import FetchTargetRights | |
from validator.factories import AssetFactory, UsageFactory, UsageAssetsFactory | |
@mark.django_db | |
def test_fetch_target_rights_load_extra_data(cc_test_result): | |
target_rights = TargetRightsFactory(product_type=cc_test_result.product.product_type, | |
media_type=cc_test_result.product.media_type) | |
check = FetchTargetRights() | |
data = {} | |
check.load_extra_data(test_result=cc_test_result, data=data) | |
assert data['target_rights'] == target_rights | |
@mark.django_db | |
def test_fetch_target_rights_load_extra_data_with_exception(cc_test_result): | |
exceptional_target_right = ExceptionalTargetRightsFactory( | |
product=cc_test_result.product) | |
check = FetchTargetRights() | |
data = {} | |
check.load_extra_data(test_result=cc_test_result, data=data) | |
assert data['target_rights'] == exceptional_target_right | |
@mark.django_db | |
def test_fetch_target_rights_load_extra_data_no_target_rights(cc_test_result): | |
check = FetchTargetRights() | |
data = {} | |
assert cc_test_result.passed | |
check.load_extra_data(test_result=cc_test_result, data=data) | |
assert data['target_rights'] is None | |
assert not cc_test_result.passed | |
@mark.django_db | |
def test_fetch_target_rights_load_extra_data_common_checks(cc_test_result): | |
asset = AssetFactory() | |
right1 = RightFactory(plausibility_check_relevant=True, right_source='P&M') | |
right1.asset_subtypes.add(asset.subtype) | |
right2 = RightFactory(plausibility_check_relevant=True, right_source='BEA') | |
right2.asset_subtypes.add(asset.subtype) | |
right3 = RightFactory(plausibility_check_relevant=True, right_source='COV') | |
right3.asset_subtypes.add(asset.subtype) | |
right4 = RightFactory(plausibility_check_relevant=False, right_source='P&M') | |
right4.asset_subtypes.add(asset.subtype) | |
right5 = RightFactory(plausibility_check_relevant=True, right_source='P&M') | |
right6 = RightFactory(plausibility_check_relevant=True, right_source='EDI') | |
right6.asset_subtypes.add(asset.subtype) | |
right7 = RightFactory(plausibility_check_relevant=True, right_source='DOW') | |
right7.asset_subtypes.add(asset.subtype) | |
target_right = TargetRightsFactory( | |
product_type=cc_test_result.product.product_type, | |
media_type=cc_test_result.product.media_type) | |
target_right.rights.add(right1, right2, right3, right4, right5) | |
usage = UsageFactory(product=cc_test_result.product, psp_id=cc_test_result.psp_id) | |
usage_asset = UsageAssetsFactory( | |
usage=usage, asset=asset, cover=True, downloadability=True, editability=True) | |
check = FetchTargetRights() | |
data = {'ua_ids': (usage_asset.id,)} | |
check.load_extra_data(test_result=cc_test_result, data=data) | |
right_dict = data.get('target_rights_dict') | |
right_ids = right_dict[usage_asset.id] | |
assert right1.id in right_ids and right2.id in right_ids and right3.id in right_ids and right6.id in right_ids and \ | |
right7.id in right_ids, \ | |
"Die ersten 3 Rechte und Recht 6 und 7 müssen in der Liste enthalten sein, da alle Bedingungen erfüllt sind." | |
assert right4.id not in right_ids, \ | |
"Recht 4 darf nicht in der Rechteliste sein, da es nicht plausibility_check_relevant ist" | |
assert right5.id not in right_ids, \ | |
"Recht 5 darf nicht in der Rechteliste sein, da es nicht für diesen Asset-Subtype benötigt wird" | |
@mark.django_db | |
def test_fetch_target_rights_load_extra_data_PuM(cc_test_result): | |
asset1 = AssetFactory() | |
asset2 = AssetFactory() | |
right1 = RightFactory(changeable_for_product=True) | |
right1.asset_subtypes.add(asset1.subtype) | |
right2 = RightFactory(changeable_for_product=True) | |
target_right = TargetRightsFactory(product_type=cc_test_result.product.product_type, | |
media_type=cc_test_result.product.media_type) | |
target_right.rights.add(right1, right2) | |
usage = UsageFactory(product=cc_test_result.product) | |
usage_asset1 = UsageAssetsFactory(usage=usage, asset=asset1) | |
usage_asset2 = UsageAssetsFactory(usage=usage, asset=asset2) | |
check = FetchTargetRights() | |
data = {'ua_ids': (usage_asset1.id, usage_asset2.id)} | |
check.load_extra_data(test_result=cc_test_result, data=data) | |
right_dict = data.get('target_rights_dict') | |
right_ids = right_dict[usage_asset1.id] | |
assert right1.id in right_ids, "Recht-{} muss in der Rechteliste zur UsageAsset-{} sein".format( | |
right1.id, usage_asset1) | |
assert right2.id not in right_ids, "Recht-{} darf nicht in der Rechteliste zur UsageAsset-{} sein".format( | |
right2.id, usage_asset1) | |
right_ids = right_dict.get(usage_asset2.id, tuple()) | |
assert len(right_ids) == 0, "Die UsageAsset-{} darf kein Recht in der Liste haben".format( | |
usage_asset2) | |
@mark.django_db | |
def test_fetch_target_rights_load_extra_data_BEA(cc_test_result): | |
processing_type1 = ProcessingTypeFactory() | |
processing_type2 = ProcessingTypeFactory() | |
a_subtype = AssetSubTypeFactory() | |
asset1 = AssetFactory(subtype=a_subtype) | |
asset2 = AssetFactory(subtype=a_subtype) | |
asset3 = AssetFactory(subtype=a_subtype) | |
right1 = RightFactory(right_source='BEA') | |
right1.asset_subtypes.add(a_subtype) | |
right1.processing_types.add(processing_type1) | |
right2 = RightFactory(right_source='BEA') | |
right2.asset_subtypes.add(a_subtype) | |
usage = UsageFactory(product=cc_test_result.product) | |
usage_asset1 = UsageAssetsFactory(usage=usage, asset=asset1) | |
usage_asset2 = UsageAssetsFactory(usage=usage, asset=asset2) | |
usage_asset2.processing_types.add(processing_type1) | |
usage_asset3 = UsageAssetsFactory(usage=usage, asset=asset3) | |
usage_asset3.processing_types.add(processing_type2) | |
check = FetchTargetRights() | |
data = {'ua_ids': (usage_asset1.id, usage_asset2.id)} | |
check.load_extra_data(test_result=cc_test_result, data=data) | |
right_dict = data.get('target_rights_dict') | |
right_ids = right_dict[usage_asset1.id] | |
assert right1.id in right_ids and right2.id in right_ids, \ | |
"Beide Rechte müssen in der Rechteliste sein, da am UsageAsset-{} keine Bearbeitungsart definiert ist".format( | |
usage_asset1.id) | |
right_ids = right_dict[usage_asset2.id] | |
assert right1.id in right_ids, \ | |
"Recht-{} muss in der Rechteliste sein, da UsageAsset-{} die Bearbeitungsart {} hat".format( | |
right1.id, usage_asset2.id, processing_type1.name) | |
assert right2.id not in right_ids, \ | |
"Recht-{} darf nicht in der Rechteliste sein, da es keine Bearbeitungsart vorgibt, " \ | |
"UsageAsset-{} aber eine Bearbeitungsart verwendet.".format( | |
right2.id, usage_asset2.id) | |
right_ids = right_dict.get(usage_asset3.id, ()) | |
assert right1.id not in right_ids, \ | |
"Recht.id-{} darf nicht in der Rechteliste sein, da UsageAsset-{} die Bearbeitungsart {} hat," \ | |
" das Recht aber nur die Bearbeitungsart {}".format( | |
right1.id, usage_asset3.id, processing_type2.name, right1.processing_types.first()) | |
assert right2.id not in right_ids, \ | |
"Recht.id-{} darf nicht in der Rechteliste sein, da es keine Bearbeitungsart vorgibt, " \ | |
"UsageAsset-{} aber eine Bearbeitungsart verwendet.".format( | |
right2.id, usage_asset3.id) | |
@mark.django_db | |
def test_fetch_target_rights_load_extra_data_COV(cc_test_result): | |
asset1 = AssetFactory() | |
asset2 = AssetFactory() | |
right = RightFactory(right_source='COV') | |
right.asset_subtypes.add(asset1.subtype, asset2.subtype) | |
usage = UsageFactory(product=cc_test_result.product) | |
usage_asset1 = UsageAssetsFactory(usage=usage, asset=asset1, cover=True) | |
usage_asset2 = UsageAssetsFactory(usage=usage, asset=asset2, cover=False) | |
check = FetchTargetRights() | |
data = {'ua_ids': (usage_asset1.id, usage_asset2.id)} | |
check.load_extra_data(test_result=cc_test_result, data=data) | |
right_dict = data.get('target_rights_dict') | |
right_ids = right_dict[usage_asset1.id] | |
assert right.id in right_ids, "Das Recht muss in der Rechteliste sein, da Cover=True ist" | |
right_ids = right_dict[usage_asset2.id] | |
assert right.id not in right_ids, "Das Recht darf nicht in der Rechteliste sein, da Cover=False ist" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment