<commit_before>import json
import datetime
import time

import pytest
import mock
import botocore.exceptions

from chalice.awsclient import TypedAWSClient


def test_region_name_is_exposed(stubbed_session):
    assert TypedAWSClient(stubbed_session).region_name == 'us-west-2'


def test_deploy_rest_api(stubbed_session):
    stub_client = stubbed_session.stub('apigateway')
    stub_client.create_deployment(
        restApiId='api_id', stageName='stage').returns({})

    stubbed_session.activate_stubs()
    awsclient = TypedAWSClient(stubbed_session)
    awsclient.deploy_rest_api('api_id', 'stage')
    stubbed_session.verify_stubs()


def test_update_function_code_only(stubbed_session):
    lambda_client = stubbed_session.stub('lambda')
    lambda_client.update_function_code(
        FunctionName='name', ZipFile=b'foo').returns({})
    lambda_client.update_function_configuration(
        FunctionName='name', Environment={'Variables': {}}).returns({})
    stubbed_session.activate_stubs()
    awsclient = TypedAWSClient(stubbed_session)
    awsclient.update_function('name', b'foo')
    stubbed_session.verify_stubs()


def test_update_function_code_and_deploy(stubbed_session):
    lambda_client = stubbed_session.stub('lambda')
    lambda_client.update_function_code(
        FunctionName='name', ZipFile=b'foo').returns({})
    lambda_client.update_function_configuration(
        FunctionName='name',
        Environment={'Variables': {"FOO": "BAR"}}).returns({})
    stubbed_session.activate_stubs()
    awsclient = TypedAWSClient(stubbed_session)
    awsclient.update_function(
        'name', b'foo', {"FOO": "BAR"})<commit_msg>Update test name<commit_after>import json
import datetime
import time

import pytest
import mock
import botocore.exceptions

from chalice.awsclient import TypedAWSClient


def test_region_name_is_exposed(stubbed_session):
    assert TypedAWSClient(stubbed_session).region_name == 'us-west-2'


def test_deploy_rest_api(stubbed_session):
    stub_client = stubbed_session.stub('apigateway')
    stub_client.create_deployment(
        restApiId='api_id', stageName='stage').returns({})

    stubbed_session.activate_stubs()
    awsclient = TypedAWSClient(stubbed_session)
    awsclient.deploy_rest_api('api_id', 'stage')
    stubbed_session.verify_stubs()


def test_always_update_function_code(stubbed_session):
    lambda_client = stubbed_session.stub('lambda')
    lambda_client.update_function_code(
        FunctionName='name', ZipFile=b'foo').returns({})
    # Even if there's only a code change, we'll always call
    # update_function_configuration.
    lambda_client.update_function_configuration(
        FunctionName='name', Environment={'Variables': {}}).returns({})
    stubbed_session.activate_stubs()
    awsclient = TypedAWSClient(stubbed_session)
    awsclient.update_function('name', b'foo')
    stubbed_session.verify_stubs()


def test_update_function_code_and_deploy(stubbed_session):
    lambda_client = stubbed_session.stub('lambda')
    lambda_client.update_function_code(
        FunctionName='name', ZipFile=b'foo').returns({})
    lambda_client.update_function_configuration(
        FunctionName='name',
        Environment={'Variables': {"FOO": "BAR"}}).returns({})
    stubbed_session.activate_stubs()
    awsclient = TypedAWSClient(stubbed_session)
    awsclient.update_function(
        'name', b'foo', {"FOO": "BAR"})
{'fraction_non_alphanumeric': 0.11373011196228638, 'fraction_numerical': 0.0005892751915144372, 'mean_word_length': 5.466666666666667, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6796346', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1089, 'n_words': 154}