def test(unprocessed_queue, unprocessed_bucket, issued_bucket, unwrap, wrap): config = Config.from_environ() document_store_address = config['DocumentStore']['Address'] # overriding safe VisibilityTimeout config['Worker']['Polling']['VisibilityTimeout'] = 1 queue_test_wait_time_seconds = config['Worker']['Polling'][ 'VisibilityTimeout'] * 2 document_v2 = DOCUMENT_V2_TEMPLATE.substitute( DocumentStoreAddress=document_store_address) document_v2 = json.loads(document_v2) wrapped_document_v2 = wrap(document_v2, '2.0') document_v3 = DOCUMENT_V3_TEMPLATE.substitute( DocumentStoreAddress=document_store_address) document_v3 = json.loads(document_v3) wrapped_document_v3 = wrap(document_v3, '3.0') worker = Worker(config) index = 1 # checking both schema versions to test auto version definition for document in [document_v2, document_v3]: key = f'document-{index}' unprocessed_bucket.Object(key).put(Body=json.dumps(document)) worker.poll() issued_document = json.load(issued_bucket.Object(key).get()['Body']) assert unwrap(issued_document) == document index += 1 time.sleep(queue_test_wait_time_seconds) index = 1 # checking both schema versions to test auto version definition for wrapped documents for document in [wrapped_document_v2, wrapped_document_v3]: key = f'wrapped-document-{index}' unprocessed_bucket.Object(key).put(Body=json.dumps(document)) worker.poll() issued_document = json.load(issued_bucket.Object(key).get()['Body']) assert unwrap(issued_document) == unwrap(document) index += 1 time.sleep(queue_test_wait_time_seconds) # check that all messages were processed assert not unprocessed_queue.receive_messages( WaitTimeSeconds=queue_test_wait_time_seconds, MaxNumberOfMessages=1, VisibilityTimeout=0) # Checking issuing already issued wrapped document # it should be moved to issued bucket without calling contract.issue method # after signature and document store verifications passed key = 'issued-wrapped-document' assert worker.is_issued_document(wrapped_document_v2) unprocessed_bucket.Object(key).put(Body=json.dumps(wrapped_document_v2)) worker.poll() issued_document = json.load(issued_bucket.Object(key).get()['Body']) assert issued_document == wrapped_document_v2
# preparing queues message_received_event_queue = empty_queue('message-received-event') message_sent_event_queue = empty_queue('message-sent-event') message_event_queue = empty_queue('message-event') message_sent_event = {'receiver': 'AU', 'text': '1'} message_received_event = {'receiver': 'AU', 'text': '2'} # emitting two events with wait_for_blocks(2): MessageSent(message_sent_event['receiver'], message_sent_event['text']) MessageReceived(message_received_event['receiver'], message_received_event['text']) # poll method should pick them all and send them to the corresponding receivers worker.poll() # both events should go into general message queue messages = queue_messages(message_event_queue) assert messages == [message_sent_event, message_received_event] # and each event type should go into the corresponding queue messages = queue_messages(message_received_event_queue) assert messages == [message_received_event] messages = queue_messages(message_sent_event_queue) assert messages == [message_sent_event] # clearing queues message_received_event_queue = empty_queue('message-received-event') message_sent_event_queue = empty_queue('message-sent-event')