def test_create_list_and_delete_trigger(bucket, capsys):
    try:
        triggers.create_trigger(
            GCLOUD_PROJECT, bucket.name, 7,
            ['FIRST_NAME', 'EMAIL_ADDRESS', 'PHONE_NUMBER'],
            trigger_id=TEST_TRIGGER_ID,
        )
    except google.api_core.exceptions.InvalidArgument:
        # Trigger already exists, perhaps due to a previous interrupted test.
        triggers.delete_trigger(GCLOUD_PROJECT, TEST_TRIGGER_ID)

        out, _ = capsys.readouterr()
        assert TEST_TRIGGER_ID in out

        # Try again and move on.
        triggers.create_trigger(
            GCLOUD_PROJECT, bucket.name, 7,
            ['FIRST_NAME', 'EMAIL_ADDRESS', 'PHONE_NUMBER'],
            trigger_id=TEST_TRIGGER_ID,
            auto_populate_timespan=True,
        )

    out, _ = capsys.readouterr()
    assert TEST_TRIGGER_ID in out

    triggers.list_triggers(GCLOUD_PROJECT)

    out, _ = capsys.readouterr()
    assert TEST_TRIGGER_ID in out

    triggers.delete_trigger(GCLOUD_PROJECT, TEST_TRIGGER_ID)

    out, _ = capsys.readouterr()
    assert TEST_TRIGGER_ID in out
def test_create_list_and_delete_trigger(bucket, capsys):
    try:
        triggers.create_trigger(
            GCLOUD_PROJECT, bucket.name, 7,
            ['FIRST_NAME', 'EMAIL_ADDRESS', 'PHONE_NUMBER'],
            trigger_id=TEST_TRIGGER_ID,
        )
    except google.api_core.exceptions.InvalidArgument:
        # Trigger already exists, perhaps due to a previous interrupted test.
        triggers.delete_trigger(GCLOUD_PROJECT, TEST_TRIGGER_ID)

        out, _ = capsys.readouterr()
        assert TEST_TRIGGER_ID in out

        # Try again and move on.
        triggers.create_trigger(
            GCLOUD_PROJECT, bucket.name, 7,
            ['FIRST_NAME', 'EMAIL_ADDRESS', 'PHONE_NUMBER'],
            trigger_id=TEST_TRIGGER_ID,
            auto_populate_timespan=True,
        )

    out, _ = capsys.readouterr()
    assert TEST_TRIGGER_ID in out

    triggers.list_triggers(GCLOUD_PROJECT)

    out, _ = capsys.readouterr()
    assert TEST_TRIGGER_ID in out

    triggers.delete_trigger(GCLOUD_PROJECT, TEST_TRIGGER_ID)

    out, _ = capsys.readouterr()
    assert TEST_TRIGGER_ID in out
Exemplo n.º 3
0
def delete_trigger(workspace, trigger_id):
    global trigger_storage
    if not trigger_storage.workspace_exists(workspace=workspace):
        return jsonify({'error':
                        'Workspace {} not found'.format(workspace)}), 404

    res, code = triggers.delete_trigger(trigger_storage, workspace, trigger_id)

    return jsonify(res), code