Beispiel #1
0
def test_it_prevents_concurrent_running_jobs(mock_running_job):
    mock_running_job.return_value = True
    response = handlers.process_handler(
        {
            "body": "",
            "requestContext": autorization_mock
        }, SimpleNamespace())

    assert 400 == response["statusCode"]
    assert "headers" in response
Beispiel #2
0
def test_it_applies_expiry(mock_utc, mock_config, mock_running_job, job_table,
                           uuid, paginate):
    mock_running_job.return_value = False
    mock_utc.return_value = 12346789
    mock_config.return_value = {
        "AthenaConcurrencyLimit": 15,
        "DeletionTasksMaxNumber": 50,
        "JobDetailsRetentionDays": 30,
        "QueryExecutionWaitSeconds": 5,
        "QueryQueueWaitSeconds": 5,
        "ForgetQueueWaitSeconds": 30
    }
    paginate.return_value = iter([{
        "MatchId": {
            "S": "123"
        },
        "CreatedAt": {
            "N": "123"
        }
    }])
    uuid.uuid4.return_value = 123
    response = handlers.process_handler(
        {
            "body": "",
            "requestContext": autorization_mock
        }, SimpleNamespace())
    mock_utc.assert_called_with(days=30)
    job_table.put_item.assert_called_with(
        Item={
            "Id": "123",
            "Sk": "123",
            "Type": "Job",
            "JobStatus": "QUEUED",
            "GSIBucket": "0",
            "CreatedAt": ANY,
            "Expires": 12346789,
            "DeletionQueueItems": [{
                "MatchId": "123",
                "CreatedAt": 123
            }],
            "DeletionQueueItemsSkipped": False,
            "AthenaConcurrencyLimit": 15,
            "DeletionTasksMaxNumber": 50,
            "QueryExecutionWaitSeconds": 5,
            "QueryQueueWaitSeconds": 5,
            "ForgetQueueWaitSeconds": 30,
            "CreatedBy": {
                "Username": "******",
                "Sub": "cognitoSub"
            }
        })
    assert 202 == response["statusCode"]
def test_it_process_queue(mock_config, mock_running_job, job_table, uuid):
    mock_running_job.return_value = False
    mock_config.return_value = {
        "AthenaConcurrencyLimit": 15,
        "DeletionTasksMaxNumber": 50,
        "QueryExecutionWaitSeconds": 5,
        "QueryQueueWaitSeconds": 5,
        "ForgetQueueWaitSeconds": 30,
    }
    uuid.uuid4.return_value = 123
    response = handlers.process_handler(
        {
            "body": "",
            "requestContext": autorization_mock
        }, SimpleNamespace())
    job_table.put_item.assert_called_with(
        Item={
            "Id": "123",
            "Sk": "123",
            "Type": "Job",
            "JobStatus": "QUEUED",
            "GSIBucket": "0",
            "CreatedAt": ANY,
            "AthenaConcurrencyLimit": 15,
            "DeletionTasksMaxNumber": 50,
            "QueryExecutionWaitSeconds": 5,
            "QueryQueueWaitSeconds": 5,
            "ForgetQueueWaitSeconds": 30,
            "CreatedBy": {
                "Username": "******",
                "Sub": "cognitoSub"
            },
        })
    assert 202 == response["statusCode"]
    assert "headers" in response
    assert {
        "Id": "123",
        "Sk": "123",
        "Type": "Job",
        "JobStatus": "QUEUED",
        "GSIBucket": "0",
        "CreatedAt": ANY,
        "AthenaConcurrencyLimit": 15,
        "DeletionTasksMaxNumber": 50,
        "QueryExecutionWaitSeconds": 5,
        "QueryQueueWaitSeconds": 5,
        "ForgetQueueWaitSeconds": 30,
        "CreatedBy": {
            "Username": "******",
            "Sub": "cognitoSub"
        },
    } == json.loads(response["body"])
Beispiel #4
0
def test_it_partitions_queue(mock_config, mock_running_job, job_table, uuid,
                             paginate):
    mock_running_job.return_value = False
    mock_config.return_value = {}

    deserialised_match = {
        "DataMappers": {
            "L": []
        },
        "MatchId": {
            "S": "123"
        },
        "CreatedAt": {
            "N": "1587992978"
        },
        "CreatedBy": {
            "M": {
                "Username": {
                    "S": "*****@*****.**"
                },
                "Sub": {
                    "S": "123456789-123456789"
                }
            }
        }
    }

    serialised_match = {
        "MatchId": "123",
        "CreatedAt": 1587992978,
        "DataMappers": [],
        "CreatedBy": {
            "Username": "******",
            "Sub": "123456789-123456789"
        }
    }

    paginate.return_value = iter([deserialised_match, deserialised_match])
    uuid.uuid4.return_value = 123
    response = handlers.process_handler(
        {
            "body": "",
            "requestContext": autorization_mock
        }, SimpleNamespace())
    job_table.put_item.assert_called_with(
        Item={
            "Id": "123",
            "Sk": "123",
            "Type": "Job",
            "JobStatus": "QUEUED",
            "GSIBucket": "0",
            "CreatedAt": ANY,
            "DeletionQueueItems": [serialised_match],
            "DeletionQueueItemsSkipped": True,
            "CreatedBy": {
                "Username": "******",
                "Sub": "cognitoSub"
            }
        })
    assert 202 == response["statusCode"]
    assert "headers" in response
    assert {
        "Id": "123",
        "Sk": "123",
        "Type": "Job",
        "JobStatus": "QUEUED",
        "GSIBucket": "0",
        "CreatedAt": ANY,
        "DeletionQueueItems": [serialised_match],
        "DeletionQueueItemsSkipped": True,
        "CreatedBy": {
            "Username": "******",
            "Sub": "cognitoSub"
        }
    } == json.loads(response["body"])