import pytest from ytownership import config from ytownership.connectors.sqs import JSONMessageExt from ytownership.connectors.youtube import ServiceMapping from ytownership.logic import patch_ownership @pytest.mark.xfail(reason='Only manual execution allowed') def test_work_flow(): """ Testing entire workflow. Use real credentials. For work need file test_google_api_key.json in root project directory. Exclusively manual launch test. Test patch ownership, found by first ISRC of test enum. Alteration changing territory list from ['WW'] to ['US','CA'] checking exclude/include type. For manual execution: py.test --runxfail path/to/this/test.py """ youtube_client = ServiceMapping(config.GOOGLE_API_KEY_FILE).youtube_partner pulled_asset_id = patch_ownership.get_asset_id( youtube_client, config.TEST_ISRCS[0]) original_ownership = patch_ownership.get_ownership( youtube_client, pulled_asset_id) message = JSONMessageExt() original_type = original_ownership['general'][0]['type'] # checking for WW or Territories list in returned original_ownership. if original_type == patch_ownership.TYPE_EXCLUDE: message_body = { 'isrc': config.TEST_ISRCS[0], 'territories': ['US', 'CA'] } else: message_body = { 'isrc': config.TEST_ISRCS[0], 'territories': ['WW'] } message.set_body(message_body) message.context.youtube_client = youtube_client response = patch_ownership.patch_ownership(message) assert response.status == 200 patched_ownership = patch_ownership.get_ownership( youtube_client, pulled_asset_id) if original_type == patch_ownership.TYPE_EXCLUDE: assert (patched_ownership['general'][0]['territories'] == message_body['territories']) else: assert 'territories' not in patched_ownership['general'][0] assert patched_ownership['general'][0]['type'] != original_type