"""Unit Tests for vendor_dms_master_restriction model.""" from abacus_legacy_sync.models.vendor_dms_master_restriction import ( VendorDmsMasterRestriction, ) from tests.utils.factories import ( CustomerMasterMasterFactory, DistributionTypeFactory, VendorContractFactory, VendorDmsMasterRestrictionFactory, ) def test_create_vendor_dms_master_restriction(): """Test to create a vendor_dms_master_restriction.""" assert VendorDmsMasterRestriction.count() == 0 vendor_contract = VendorContractFactory.create() distribution_type = DistributionTypeFactory.create() customer_master_master = CustomerMasterMasterFactory.create() VendorDmsMasterRestriction.create( customer_master_master_id=customer_master_master.customer_master_master_id, distribution_type_id=distribution_type.distribution_type_id, vendor_contract_id=vendor_contract.vendor_contract_id, ) result = VendorDmsMasterRestriction.query.all() assert len(result) == 1 assert ( result[0].customer_master_master_id == customer_master_master.customer_master_master_id ) assert result[0].distribution_type_id == distribution_type.distribution_type_id assert result[0].vendor_contract_id == vendor_contract.vendor_contract_id def test_get_by_criteria(): """Test to get vendor_dms_master_restriction's by distribution_type_id and vendor_contract_id.""" # noqa: E501 vendor_contract = VendorContractFactory.create() distribution_types = [ DistributionTypeFactory.create(distribution_type_name=distribution_type_name) for distribution_type_name in ['Full Track', 'Tone'] ] customer_master_master = CustomerMasterMasterFactory.create() [ VendorDmsMasterRestrictionFactory.create( customer_master_master=customer_master_master, distribution_type=distribution_type, vendor_contract=vendor_contract, ) for distribution_type in distribution_types ] result = VendorDmsMasterRestriction.get_by_criteria( distribution_types[1].distribution_type_id, vendor_contract.vendor_contract_id ) assert len(result) == 1 assert ( result[0].customer_master_master_id == customer_master_master.customer_master_master_id ) assert result[0].distribution_type_id == distribution_types[1].distribution_type_id assert result[0].vendor_contract_id == vendor_contract.vendor_contract_id def test_delete_by_ids(): """Test to delete vendor_dms_master_restriction's by ids.""" vendor_contract = VendorContractFactory.create() distribution_types = [ DistributionTypeFactory.create(distribution_type_name=distribution_type_name) for distribution_type_name in ['Full Track', 'Tone'] ] customer_master_master = CustomerMasterMasterFactory.create() vendor_dms_master_restrictions = [ VendorDmsMasterRestrictionFactory.create( customer_master_master=customer_master_master, distribution_type=distribution_type, vendor_contract=vendor_contract, ) for distribution_type in distribution_types ] vendor_dms_master_restrictions_ids = [ vendor_dms_master_restriction.restriction_id for vendor_dms_master_restriction in vendor_dms_master_restrictions ] assert VendorDmsMasterRestriction.count() == 2 VendorDmsMasterRestriction.delete_by_ids(vendor_dms_master_restrictions_ids) assert VendorDmsMasterRestriction.count() == 0 def test_update_by_ids(): """Test to update vendor_dms_master_restriction's by ids.""" vendor_contract = VendorContractFactory.create() distribution_type = DistributionTypeFactory.create() customer_master_masters = [ CustomerMasterMasterFactory.create(customer_name=customer_name) for customer_name in ['eMusic', 'Buymusic'] ] customer_master_master_3 = CustomerMasterMasterFactory.create( customer_name='Audio Lunchbox' ) vendor_dms_master_restrictions = [ VendorDmsMasterRestrictionFactory.create( customer_master_master=customer_master_master, distribution_type=distribution_type, vendor_contract=vendor_contract, ) for customer_master_master in customer_master_masters ] assert ( vendor_dms_master_restrictions[1].customer_master_master_id == customer_master_masters[1].customer_master_master_id ) VendorDmsMasterRestriction.update_by_ids( { vendor_dms_master_restrictions[ 1 ].customer_master_master_id: customer_master_master_3.customer_master_master_id } ) result = VendorDmsMasterRestriction.query.all() assert ( result[1].customer_master_master_id == customer_master_master_3.customer_master_master_id )