Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Necessary to include placebo statements in application code #333

Closed
alexharv074 opened this issue Dec 7, 2020 · 1 comment
Closed

Necessary to include placebo statements in application code #333

alexharv074 opened this issue Dec 7, 2020 · 1 comment

Comments

@alexharv074
Copy link

This could be me but I ran into an edge case where I seem to be required to have placebo statements in my application code.

I have a project structure like this:

▶ find .          
.
./tests
./tests/test_lambda_function.py
./src
./src/lib
./src/lib/__init__.py
./src/lib/foo.py
./src/lambda_function.py
  • The call to AWS occurs in src/lib/foo.py.

  • I initialise placebo in tests/test_lambda_function.py.

This did not work until I moved these lines into src/lib/foo.py:

boto3.setup_default_session()
session = boto3.DEFAULT_SESSION
pill = placebo.attach(session, data_path="tests/fixtures")

if "BOTO_RECORD" in os.environ:
    pill.record()
elif "BOTO_PLAYBACK" in os.environ:
    pill.playback()

The file foo has content in it like:

import boto3

client = boto3.client("route53")

def get_policy_instance_id(policy_id: str) -> Union[str, None]:
    response = client.list_traffic_policy_instances()
    for policy_instance in response["TrafficPolicyInstances"]:
        if policy_instance["TrafficPolicyId"] == policy_id:
            return policy_instance["Id"]
    return None

def create(hosted_zone_id: str,
           ttl: int,
           domain_name: str,
           traffic_policy_id: str,
           traffic_policy_version: int) -> dict:

    return client.create_traffic_policy_instance(
        HostedZoneId=hosted_zone_id,
        Name=domain_name,
        TTL=ttl,
        TrafficPolicyId=traffic_policy_id,
        TrafficPolicyVersion=traffic_policy_version
    )
...

Is this a known issue, or am I doing something wrong?

@alexharv074
Copy link
Author

My apologies, wrong window. This was intended for the Placebo project, not this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant