"""conftest. This file gets picked up when running py.test tests: http://pytest.org/latest/writing_plugins.html#conftest """ import datetime import uuid import pytest from tests.integration.consts import api from tests.integration.test_helpers import api as api_calls from tests.integration.test_helpers import utils @pytest.fixture def podcast_fixture(test_network_id_fixture): """Create podcast and delete after all tests are executed.""" filename = api_calls.asset.add_without_id('podcast', api.ASSET_TYPE_IMAGE) podcast_payload = { 'title': 'My Own Podcast', 'description': 'Test podcast created by api_tests', 'network_id': test_network_id_fixture, 'slug': utils.random_slug(), 'host': 'Peter', 'owner': 'Parker', 'copyright': 'Copyright', 'link': 'http://theorchard.com', 'email': 'coolemail@email.com', 'explicit': 'explicit', 'show_type': 'episodic', 'language': 'English', 'categories': [22], 'artwork_filename': filename } response = api_calls.podcast.create(podcast_payload) response_body = utils.validate_response_status(response) try: yield response_body finally: api_calls.podcast.delete(response_body['id']) @pytest.fixture def episode_fixture(podcast_fixture): """Create episode.""" return utils.validate_response_status( api_calls.episode.create(podcast_fixture['id']) ) @pytest.fixture def updated_episode_fixture(episode_fixture): """Get episode that has been updated.""" new_payload = { 'title': 'New title for the episode', 'description': 'Description for the episode', 'draft': True, 'published_date': ( datetime.datetime.now() + datetime.timedelta(days=1) ).isoformat() } return utils.validate_response_status( api_calls.episode.update( episode_fixture['podcast_id'], episode_fixture['id'], new_payload) ) @pytest.fixture def create_ad_reads_fixture(): """Genereate payload to create adreads item.""" return { 'title': 'api tests host read ad', 'campaign_id': '1', 'order_id': '1', 'advertisement_id': '1', 'roll_type': 'mid', 'assignee_ids': 1, 'copy_url_path': 'some_path.pdf', 'due_date': '2020-02-02', 'status': 'new', 'requires_approval': True } @pytest.fixture def new_user_fixture(test_network_id_fixture): """Create new user item.""" random_name = str(uuid.uuid4()).replace('-', '_') payload = { 'name': random_name, 'email': 'api_podcast_tests_{}@theorchard.com'.format(random_name), 'auth0_user_id': '', 'network_ids': [test_network_id_fixture], 'role': 'admin', 'organization': 'sme' } response_body = utils.validate_response_status( api_calls.user.create(payload) ) try: yield response_body finally: api_calls.user.delete(response_body['id']) @pytest.fixture def test_network_id_fixture(): """Get Network id to be used for integrations tests.""" networks = utils.validate_response_status( api_calls.podcast.get_networks() ) test_network_id = None for network in networks['items']: if network['name'] == 'Orchard Test Network': test_network_id = network['id'] break assert test_network_id is not None, \ 'Expected test network id to be not None' return test_network_id