"""Integration tests for account creation.""" import json import uuid from datetime import datetime import requests from retry import retry from .integration_test_helper import IntegrationTestHelper data_path = 'tests/test_data/account_creation_data.json' def configure_data(file): """Configure variable data from test data.""" email = IntegrationTestHelper.random_string('@test.com') artist = IntegrationTestHelper.random_string('_artist') id = IntegrationTestHelper.random_string() data = json.load(file) data['payload']['Email'] = email data['payload']['ArtistName__c'] = artist data['payload']['Id'] = id data['payload']['CorrelationId__c'] = str(uuid.uuid4()) return data, email def get_timestamp(): """Return utc timestamp.""" date = str(datetime.date(datetime.utcnow())) full_time = str(datetime.time(datetime.utcnow())) timestamp = date + 'T' + full_time[:-3] + 'Z' return timestamp def get_approval_kafka_headers(timestamp): """Return valid headers for event.gdaApproval topic.""" return [ ('CamelHeader.CamelSalesforceReplayId', b'301'), ('CamelHeader.CamelSalesforceChannel', b'/topic/ContactArtistPushTopic'), ('CamelHeader.CamelSalesforceTopicName', b'ContactArtistPushTopic'), ('CamelHeader.CamelSalesforceCreatedDate', bytes(timestamp, 'utf-8')), ('CamelHeader.CamelSalesforceEventType', b'created') ] def test_account_created(get_consumer, get_producer): """Test gdaSignup topic is created when data is set to approve.""" consumer = get_consumer('dlq.gdaAccountCreation.failures') helper = IntegrationTestHelper() partition, start_position = helper.get_last_partition_position(consumer) f = open(data_path) data, email = configure_data(f) f.close() print(data['payload']) data['payload'] = (json.dumps(data['payload'])) timestamp = get_timestamp() producer = get_producer producer.send( 'event.gdaApproval', json.dumps(data).encode(), headers=get_approval_kafka_headers(timestamp) ) producer.close() url = 'https://qa-ows-users.theorchard.io/users/identity/email/' + email print(url) @retry(AssertionError, tries=40, delay=3) def _assert_user_exists(): """Assert record exists via api call.""" response = requests.get(url) assert response.status_code == 200, 'No record found in ows-users' return response.json() response_message = _assert_user_exists() assert response_message['email'] == email consumer.poll(30000) last_position = helper.get_last_partition_position(consumer)[1] assert last_position == start_position