Commit 23f98e56 authored by Maribeth Pierce's avatar Maribeth Pierce
Browse files

Seed changes

parent 77c78f3e
Loading
Loading
Loading
Loading
+0 −21
Original line number Diff line number Diff line
"""Shared fixtures for api tests."""
import pytest

from integrade.injector import direct_count_images
from integrade.tests.utils import (
    create_cloud_account,
    get_auth,
)


@pytest.fixture
def cloud_account(drop_account_data, cloudtrails_to_delete):
    """Create a cloud account, return the auth object and account details."""
    assert direct_count_images() == 0
    auth = get_auth()
    create_response = create_cloud_account(
            auth,
            0,
            cloudtrails_to_delete=cloudtrails_to_delete
        )
    return (auth, create_response)
+9 −13
Original line number Diff line number Diff line
@@ -11,25 +11,19 @@
import pytest

from integrade import api, config
from integrade.injector import (
    inject_aws_cloud_account,
)
from integrade.tests import urls
from integrade.tests.utils import (
    create_user_account,
    get_auth,
    needed_aws_profiles_present,
)
from integrade.utils import uuid4


@pytest.skip(reason='refactor with seed data')
@pytest.mark.skip(reason='refactor with seed data')
@pytest.mark.serial_only
@pytest.mark.skipif(not needed_aws_profiles_present(2),
                    reason='needs at least 2 aws profile')
def test_create_multiple_cloud_accounts(
        drop_account_data,
        cloudtrails_to_delete):
def test_create_multiple_cloud_accounts(cloudtrails_to_delete):
    """Ensure cloud accounts can be registered to a user.

    :id: f1db2617-fd15-4270-b9d3-595db001e1e7
@@ -72,12 +66,12 @@ def test_create_multiple_cloud_accounts(
        assert acct in list_response.json()['results']


@pytest.skip(reason='refactor with seed data')
@pytest.mark.skip(reason='refactor with seed data')
@pytest.mark.serial_only
@pytest.mark.skipif(not needed_aws_profiles_present(2),
                    reason='needs at least 2 aws profile')
def test_create_cloud_account_duplicate_names_different_users(
    drop_account_data, cloudtrails_to_delete
    cloudtrails_to_delete
):
    """Ensure cloud accounts can be registered to a user.

@@ -97,13 +91,15 @@ def test_create_cloud_account_duplicate_names_different_users(
        3) The account cannot be deleted and attempts to do so receive a 405
            response.
    """
    user = create_user_account()
    # TODO: refactor inject_aws_cloud_account to use seed data
    user = ''  # create_user_account()
    auth = get_auth(user)
    client = api.Client(authenticate=False, response_handler=api.echo_handler)
    cfg = config.get_config()
    aws_profile = cfg['aws_profiles'][0]
    profile_name = aws_profile['name']
    inject_aws_cloud_account(user['id'], name=profile_name)
    # TODO: refactor inject_aws_cloud_account to use seed data
    profile_name = ''  # aws_profile['name']
    # inject_aws_cloud_account(user['id'], name=profile_name)

    # Now try to reuse the name
    auth = get_auth()
+2 −6
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ from integrade.exceptions import MissingConfigurationError
from integrade.tests import aws_utils, urls
from integrade.tests.aws_utils import aws_image_config_needed
from integrade.tests.constants import AWS_ACCOUNT_TYPE
from integrade.tests.utils import drop_account_data, get_auth
from integrade.tests.utils import get_auth

ImageData = namedtuple(
    'ImageData',
@@ -197,7 +197,7 @@ def get_s3_bucket_name():
    bucket_name = config.get_config()['cloudigrade_s3_bucket']
    if not bucket_name:
        raise MissingConfigurationError(
            'Need to know the name of cloudigrade\'s s3'
            "Need to know the name of cloudigrade's s3"
            ' bucket to mock events!'
        )
    return bucket_name
@@ -469,7 +469,6 @@ def test_find_running_instances(
    if image_name != image_fixture.image_name \
            or image_type != image_fixture.image_type:
        pytest.skip(f'Only testing {IMAGES_TO_TEST}')
    drop_account_data()

    auth = get_auth()
    client = api.Client(authenticate=False, response_handler=api.json_handler)
@@ -547,8 +546,6 @@ def test_on_off_events(
        4) The bad events are ignored.
        5) The power on events events eventually recorded.
    """
    drop_account_data()

    # check and make sure the instance is not running
    client = aws_utils.aws_session(aws_profile['name']).client('ec2')
    reservations = client.describe_instances(Filters=[{
@@ -670,7 +667,6 @@ def test_broken_image(
    source_image = image_fixture.source_image
    source_image_id = source_image['image_id']
    instance_id = image_fixture.instance_id
    drop_account_data()

    auth = get_auth()
    client = api.Client(authenticate=False, response_handler=api.json_handler)
+10 −8
Original line number Diff line number Diff line
@@ -11,14 +11,14 @@
import pytest

from integrade import api
from integrade.injector import (
    inject_aws_cloud_account,
    inject_instance_data,
)
# from integrade.injector import (
#     inject_aws_cloud_account,
#     inject_instance_data,
# )
from integrade.tests import urls, utils


@pytest.skip(reason='TODO refactor')
@pytest.mark.skip(reason='TODO refactor')
def test_past_without_instances():
    """Test accounts with instances only after the filter period.

@@ -35,7 +35,8 @@ def test_past_without_instances():
    """
    user = utils.create_user_account()
    auth = utils.get_auth(user)
    acct = inject_aws_cloud_account(user['id'])
    # TODO: refactor inject_aws_cloud_account to use seed data
    acct = ''  # inject_aws_cloud_account(user['id'])
    client = api.Client(authenticate=False)

    # ask for last 30 days
@@ -52,11 +53,12 @@ def test_past_without_instances():
    assert images == [], repr(images)

    # No tagged images, started 60 days ago and stopped 45 days ago
    image_type = ''
    # image_type = ''
    instance_start = 60
    instance_end = 45
    events = [instance_start, instance_end]
    inject_instance_data(acct['id'], image_type, events)
    print(events)
    # inject_instance_data(acct['id'], image_type, events)

    # test that still have no images in report
    response = client.get(urls.REPORT_IMAGES, params=params, auth=auth)
+8 −3
Original line number Diff line number Diff line
@@ -23,10 +23,15 @@ def test_sysconfig():
    :steps: Do an authenticated GET requests to /api/v1/sysconfig/ and check
        the response.
    :expectedresults: The server returns a 201 response with the expected
        configuration information.
        configuration information. The api.json_handler will raise an error if
        the response_code isn't a successful one - ie 2XX OK, 4XX or 5XX NOK.
    """
    auth = get_auth()
    client = api.Client(response_handler=api.json_handler)
    user = {
        'username': 'user1@example.com',
        'password': 'user1@example.com',
    }
    auth = get_auth(user)
    client = api.Client(response_handler=api.json_handler, token=auth)
    response = client.get(urls.SYSCONFIG, auth=auth)
    assert set(response.keys()) == set((
        'aws_account_id',
Loading