def test_submit_unsafe_item(monkeypatch):
    # Set environment variable
    monkeypatch.setenv("STAGE", "dev")
    monkeypatch.setenv("MOTO_ACCOUNT_ID", '891514678401')
    from moto import mock_ses, mock_stepfunctions
    with mock_stepfunctions(), mock_ses():
        # Initialize mock clients
        sf_client = boto3.client('stepfunctions', region_name="eu-central-1")
        sf_client.create_state_machine(
            name='SearchFactChecks_new-dev',
            definition='{}',
            roleArn=
            'arn:aws:iam::891514678401:role/detektivkollektiv-stepfunct-StateMachineLambdaRole'
        )
        ses_client = boto3.client("ses", region_name="eu-central-1")
        ses_client.verify_email_identity(EmailAddress="*****@*****.**")

        with Session() as session:
            session = setup_scenarios.create_questions(session)

            # Submit first item
            response = submit_item(create_event2(), None)

            assert response['statusCode'] == 403
            assert response['headers']['new-item-created'] == "True"

            # Check database entries
            assert session.query(Item).count() == 1
            assert session.query(Submission).count() == 1
            submission = session.query(Submission).first()
            assert submission.status == 'Unsafe'
            assert submission.item.urls[0].url.unsafe is None
            assert submission.item.urls[1].url.unsafe == "GOOGLE:MALWARE"
def test_submit_item(event1, event2, monkeypatch):
    
    # Set environment variable
    monkeypatch.setenv("STAGE", "dev")
    monkeypatch.setenv("MOTO_ACCOUNT_ID", '891514678401')
    from moto import mock_ses, mock_stepfunctions
    with mock_stepfunctions(), mock_ses():
        # Initialize mock clients
        sf_client = boto3.client('stepfunctions', region_name="eu-central-1")
        sf_client.create_state_machine(
            name='SearchFactChecks_new-dev',
            definition='{}',
            roleArn='arn:aws:iam::891514678401:role/detektivkollektiv-stepfunct-StateMachineLambdaRole'
        )
        ses_client = boto3.client("ses", region_name="eu-central-1")
        ses_client.verify_email_identity(EmailAddress="*****@*****.**")

        with Session() as session:

            session = setup_scenarios.create_questions(session)

            # Submit first item
            response = submit_item(event1, None)

            assert response['statusCode'] == 201
            assert response['headers']['new-item-created'] == "True"

            # Check database entries
            assert session.query(Item).count() == 1
            assert session.query(Submission).count() == 1
            assert session.query(Submission.ip_address).first()[0] == '1.2.3.4'

            # Submit second item with same content as first one
            submit_item(event2, None)
            # Check database entries
            assert session.query(Item).count() == 1  # items didn't increase
            assert session.query(Submission).count() == 2  # submissions increased
            first_item_id = session.query(Item.id).first()[0]
            assert session.query(Item.submissions).\
                filter(Item.id == first_item_id).count() == 2  # number of submissions to first item increased
            assert session.query(Submission.ip_address).all()[1][0] == '2.3.4.5' # ip address of second submission assigned to first item
            # Check if confirmation mails have been sent
            send_quota = ses_client.get_send_quota()
            sent_count = int(send_quota["SentLast24Hours"])
            assert sent_count == 2
Exemple #3
0
    def test_stepfunction_1(self, monkeypatch):
        monkeypatch.setenv("DBNAME", "Test")
        os.environ["STAGE"] = "dev"

        session = get_db_session(True, None)

        event = {
            "body": {
                "content":
                "Manche Corona-Tests brauchen keine externe Qualitätskontrolle",
                "type": "claim"
            }
        }
        context = ""
        response = submit_item.submit_item(event, context, True, session)
        assert response['body']['item_id'] is not None
def test_dates(event1):
    from moto import mock_ses, mock_stepfunctions
    with mock_stepfunctions(), mock_ses():
        # Initialize mock clients
        sf_client = boto3.client('stepfunctions', region_name="eu-central-1")
        sf_client.create_state_machine(
            name='SearchFactChecks_new-dev',
            definition='{}',
            roleArn='arn:aws:iam::891514678401:role/detektivkollektiv-stepfunct-StateMachineLambdaRole'
        )
        ses_client = boto3.client("ses", region_name="eu-central-1")
        ses_client.verify_email_identity(EmailAddress="*****@*****.**")

    with Session() as session:
        submissions = session.query(Submission).all()
        response = submit_item(event1, None)
        assert response['statusCode'] == 201
        assert 1 == 1
Exemple #5
0
    def test_stepfunction_1(self):
        os.environ["STAGE"] = "dev"

        event = {
            "body": {
                "content":
                "Manche Corona-Tests brauchen keine externe Qualitätskontrolle",
                "type": "claim"
            },
            "requestContext": {
                "identity": {
                    "sourceIp": '2.3.4.5'
                }
            }
        }
        context = ""
        response = submit_item.submit_item(event, context)
        body = json.loads(response['body'])
        assert body['id'] is not None