"""Lambda test module.""" import pytest from xmlunittest import XmlTestCase import generate @pytest.mark.usefixtures('transformed_data') class XMLGenerateTestCase(XmlTestCase): """Extend XmlTestCase in order to test XML.""" test_metadata = { 'message_thread_id': 12345, 'message_id': '12345_20200101_000000', 'message_created_date_time': '2020-01-01T00:00:00Z', 'isrc': 12345, 'pline_year': '2002', 'pline_text': '2002 Example Entertainment', 'resource_reference': 'A1', 'title_text': 'Example Title', 'sub_title': 'Single Edit', 'parental_warning_type': 'NotExplicit', 'meta_language_code': 'ENG', 'language_of_performance': 'en', 'display_title': 'Example Title (Single Edit)', 'formal_title': 'Example Title', 'duration': 'PT3M00S', 'display_artists': [ {'fullName': 'BTS', 'artistRole': 'MainArtist'}, {'fullName': 'Pdogg', 'artistRole': 'FeaturedArtist'}, {'fullName': 'Janiya T', 'artistRole': 'Composer'} ], 'label': 'Big Hit Entertainment' } test_metadata_without_version = { 'message_thread_id': 12345, 'message_id': '12345_20200101_000000', 'message_created_date_time': '2020-01-01T00:00:00Z', 'isrc': 12345, 'pline_year': '2002', 'pline_text': '2002 Example Entertainment', 'resource_reference': 'A1', 'title_text': 'Example Title', 'sub_title': '', 'parental_warning_type': 'NotExplicit', 'meta_language_code': 'ENG', 'language_of_performance': 'en', 'display_title': 'Example Title (Single Edit)', 'formal_title': 'Example Title', 'duration': 'PT3M00S', 'display_artists': [ {'fullName': 'BTS', 'artistRole': 'MainArtist'}, {'fullName': 'Pdogg', 'artistRole': 'FeaturedArtist'}, {'fullName': 'Janiya T', 'artistRole': 'Composer'} ], 'label': 'Big Hit Entertainment' } test_metadata_instrumental = { 'message_thread_id': 12345, 'message_id': '12345_20200101_000000', 'message_created_date_time': '2020-01-01T00:00:00Z', 'isrc': 12345, 'pline_year': '2000', 'pline_text': '2000 Sony Classical Records', 'resource_reference': 'A1', 'title_text': 'Rhapsody In Blue', 'sub_title': 'Single Edit', 'parental_warning_type': 'NotExplicit', 'meta_language_code': 'N/A', 'language_of_performance': None, 'display_title': 'Rhapsody In Blue', 'formal_title': 'Rhapsody In Blue', 'duration': 'PT3M00S', 'display_artists': [ {'fullName': 'Pittsburgh Synmphony', 'artistRole': 'MainArtist'}, {'fullName': 'Christopher Wu', 'artistRole': 'MainArtist'}, {'fullName': 'Anne Martindale Williams', 'artistRole': 'MainArtist'} ], 'label': 'Sony Classical Records' } def test_header_nodes(self): """Test that the correct XML nodes are generated.""" root = generate.generate_ern_srr(self.test_metadata) self.assertXmlNode(root) # Test that the expected nodes exist self.assertXpathsExist(root, ('./MessageHeader', './MessageHeader/MessageThreadId', './MessageHeader/MessageId', './MessageHeader/MessageSender', './MessageHeader/MessageSender/PartyId', './MessageHeader/MessageSender/PartyName', './MessageHeader/MessageSender/PartyName/FullName', './MessageHeader/MessageSender/TradingName', './MessageHeader/MessageRecipient', './MessageHeader/MessageRecipient/PartyId', './MessageHeader/MessageRecipient/PartyName', './MessageHeader/MessageRecipient/PartyName/FullName', './MessageHeader/MessageCreatedDateTime', './ResourceList', './ResourceList/SoundRecording', './ResourceList/SoundRecording/SoundRecordingType', './ResourceList/SoundRecording/SoundRecordingId', './ResourceList/SoundRecording/SoundRecordingId/ISRC', './ResourceList/SoundRecording/ResourceReference', './ResourceList/SoundRecording/ReferenceTitle', './ResourceList/SoundRecording/ReferenceTitle/TitleText', './ResourceList/SoundRecording/LanguageOfPerformance', './ResourceList/SoundRecording/Duration', './ResourceList/SoundRecording/SoundRecordingDetailsByTerritory')) # Test that constant values are correct self.assertXpathValues(root, './MessageHeader/MessageSender/PartyId/text()', ('PADPIDA2012041004F')) self.assertXpathValues(root, './MessageHeader/MessageSender/PartyId/@IsDPID', ('true')) self.assertXpathValues(root, './MessageHeader/MessageSender/PartyName/FullName/text()', ('The Orchard Enterprises')) self.assertXpathValues(root, './MessageHeader/MessageSender/PartyName/TradingName/text()', ('The Orchard Enterprises, LLC')) self.assertXpathValues(root, './MessageHeader/MessageRecipient/PartyId/text()', ('PADPIDA2013071501L')) self.assertXpathValues(root, './MessageHeader/MessageRecipient/PartyId/@IsDPID', ('true')) self.assertXpathValues(root, './MessageHeader/MessageRecipient/PartyName/FullName/text()', ('Facebook')) self.assertXpathValues(root, './MessageHeader/MessageCreatedDateTime/text()', ('2020-01-01T00:00:00Z')) self.assertXpathValues(root, './ResourceList/SoundRecording/SoundRecordingType/text()', ('MusicalWorkSoundRecording')) # TODO Test special cases like Remixer def test_namespaces(self): """Test that the correct XML namespaces are present.""" root = generate.generate_ern_srr(self.test_metadata) self.assertXmlNamespace(root, 'ern', 'http://ddex.net/xml/ern/382') self.assertXmlNamespace(root, 'xs', 'http://www.w3.org/2001/XMLSchema-instance') self.assertXmlHasAttribute( root, '{http://www.w3.org/2001/XMLSchema-instance}schemaLocation', expected_value='http://ddex.net/xml/ern/382 http://ddex.net/xml/ern/382/release-notification.xsd') self.assertXmlHasAttribute(root, 'MessageSchemaVersionId', expected_value='ern/382') self.assertXmlHasAttribute( root, 'ReleaseProfileVersionId', expected_value='CommonReleaseTypes/14/SingleResourceRelease') self.assertXmlHasAttribute(root, 'LanguageAndScriptCode', expected_value='en') def test_with_version(self): """Test that SubTitle elements are present when track has version.""" root = generate.generate_ern_srr(self.test_metadata) self.assertXmlNode(root) self.assertXpathsExist(root, ('./ResourceList/SoundRecording/ReferenceTitle/SubTitle', )) self.assertXpathsExist(root, ( './ResourceList/SoundRecording/SoundRecordingDetailsByTerritory/Title/SubTitle', )) def test_without_version(self): """Test that SubTitle elements are not present when track has no version.""" root = generate.generate_ern_srr(self.test_metadata_without_version) self.assertXmlNode(root) self.assertXpathsExist(root, ('./ResourceList[not(.//SubTitle)]', )) def test_instrumental(self): """Test that correct elements are present for instrumental track.""" root = generate.generate_ern_srr(self.test_metadata_instrumental) self.assertXmlNode(root) self.assertXpathsExist(root, ('./ResourceList/SoundRecording/IsInstrumental', )) self.assertXpathValues(root, './ResourceList/SoundRecording/IsInstrumental/text()', ('true')) self.assertXpathsExist(root, ('./ResourceList[not(.//LanguageOfPerformance)]', ))