def test_manual_email_lambda(botos, manual_email): item1, _, _ = subscription.subscribe(botos, '*****@*****.**') item2, _, _ = subscription.subscribe(botos, '*****@*****.**') assert len(subscription.get_subscribers(botos)) == 2 res = botos.client('lambda').invoke(FunctionName='manual_email', Payload=json.dumps({ 'subject': 's', 'body_text': 't', 'body_html': 'h' })) returned = json.loads(res['Payload'].read())['results'] assert len(returned) == 1 res = botos.client('lambda').invoke(FunctionName='manual_email', Payload=json.dumps({ 'dry_run': False, 'subject': 's', 'body_text': 't', 'body_html': 'h' })) returned = json.loads(res['Payload'].read())['results'] assert len(returned) == 2 subscription.unsubscribe(botos, '*****@*****.**', item1['id']) subscription.unsubscribe(botos, '*****@*****.**', item2['id']) assert len(subscription.get_subscribers(botos)) == 0
def test_unsub_mismatch(botos): item1, _, _ = subscription.subscribe(botos, '*****@*****.**') assert len(subscription.get_subscribers(botos)) == 1 result = subscription.unsubscribe(botos, '*****@*****.**', 'invalid') assert result is None assert len(subscription.get_subscribers(botos)) == 1
def test_manual_email_dry_run(botos): item1, _, _ = subscription.subscribe(botos, '*****@*****.**') item2, _, _ = subscription.subscribe(botos, '*****@*****.**') assert len(subscription.get_subscribers(botos)) == 2 results = subscription.send_manual_email(botos, 'sub', 'text', 'html') assert len(results) == 1 results = subscription.send_manual_email(botos, 'sub', 'text', 'html', dry_run=False) assert len(results) == 2 subscription.unsubscribe(botos, '*****@*****.**', item1['id']) subscription.unsubscribe(botos, '*****@*****.**', item2['id']) assert len(subscription.get_subscribers(botos)) == 0
def handler(event, context): queue = settings.botos.resource('sqs').Queue(settings.list_queue_url) results = [] start_time = datetime.datetime.now() while (datetime.datetime.now() - start_time).total_seconds() < settings.ingest_soft_timeout_secs: logger.info('receiving messages') messages = queue.receive_messages( MaxNumberOfMessages=10, WaitTimeSeconds=settings.queue_wait_secs, AttributeNames=['All'], ) for message in messages: try: logger.info("attributes %r", message.attributes) body = message.body logger.info("body %r", body) event = subscription.ListEvent.from_json(body) logger.info("event is %r", event) if event.action == 'subscribe': result = subscription.subscribe(settings.botos, event.address, event.honeypot) elif event.action == 'unsubscribe': result = subscription.unsubscribe(settings.botos, event.address, event.address_id) else: raise ValueError("unknown action: %r" % event.action) except subscription.InvalidEmail: logger.warning("skipping invalid email from %r", body) raven_client.captureException(extra={'body': body}, ) message.delete() except: # noqa: E722 logger.exception("failed to process message %r", body) raven_client.captureException(extra={'body': body}, ) else: message.delete() results.append(result) logger.info("handled %r successfully: %r", event, result) # I'm not sure if this is a localstack bug, but this needs to be a dict. return {'results': results}
def test_ignores_honeypotted_signup(botos): r = subscription.subscribe(botos, '*****@*****.**', 'anything') assert r == (None, None, None) assert len(subscription.get_subscribers(botos)) == 0