Skip to content

Commit

Permalink
remove emoji and update moto (#296)
Browse files Browse the repository at this point in the history
* remove emoji, update moto and modify tests to use mock_aws
  • Loading branch information
chaudharysaket authored Aug 26, 2024
1 parent d84fb54 commit 83fbaaa
Show file tree
Hide file tree
Showing 10 changed files with 886 additions and 934 deletions.
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ name = "pypi"
boto3 = "*"
click = "*"
colorama = "*"
emoji = "*"
gql = "*"
requests = "*"
tabulate = "*"
Expand All @@ -17,7 +16,8 @@ black = "*"
pytest = "*"
pytest-cov = "*"
requests_toolbelt = "*"
moto = {extras = ["all"], version = "*"}
moto = {extras = ["all"], version = ">=5,<6.0"}
setuptools = ">=65.0,<73.0"

[requires]
python_version = "3.12"
1,740 changes: 852 additions & 888 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ Using these together will auto format your git commits.
## Running Tests

```bash
python setup.py test
pytest tests
```

## Troubleshooting
Expand Down
23 changes: 11 additions & 12 deletions newrelic_lambda_cli/cliutils.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# -*- coding: utf-8 -*-

import click
import emoji

from click.exceptions import Exit


def done(message):
"""Prints a done message to the terminal"""
click.echo(emoji.emojize(":sparkles: %s :sparkles:" % message, language="alias"))
click.echo(f"✔️ {message} ✔️")


def failure(message, exit=False):
"""Prints a failure message to the terminal"""
click.echo(
emoji.emojize(":heavy_multiplication_x: %s" % message, language="alias"),
color="red",
click.secho(
f"✘ {message}",
fg="red",
err=True,
)
if exit:
Expand All @@ -24,15 +23,15 @@ def failure(message, exit=False):

def success(message):
"""Prints a success message to the terminal"""
click.echo(
emoji.emojize(":heavy_check_mark: %s" % message, language="alias"),
color="green",
click.secho(
f"✔️ {message}",
fg="green",
)


def warning(message):
"""Prints a warningmessage to the terminal"""
click.echo(
emoji.emojize(":heavy_exclamation_mark: %s" % message, language="alias"),
color="blue",
"""Prints a warning message to the terminal"""
click.secho(
f"⚠️ {message}",
fg="blue",
)
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
"boto3<5",
"click>=7.1.2",
"colorama",
"emoji>=2,<3",
"gql>=2,<3",
"requests<3",
"tabulate",
],
setup_requires=["pytest-runner"],
tests_require=["moto", "pytest", "requests"],
entry_points={
"console_scripts": ["newrelic-lambda = newrelic_lambda_cli.cli:main"]
},
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/test_layers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from moto import mock_lambda
from moto import mock_aws

from newrelic_lambda_cli.cli import cli, register_groups


@mock_lambda
@mock_aws
def test_layers_install(aws_credentials, cli_runner):
"""
Assert that 'newrelic-lambda layers install' attempts to install the New Relic
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_layers_install(aws_credentials, cli_runner):
assert "Could not find function: foobar" in result2.stderr


@mock_lambda
@mock_aws
def test_layers_uninstall(aws_credentials, cli_runner):
"""
Assert that 'newrelic-lambda layers uninstall' attempts to uninstall the New Relic
Expand Down
9 changes: 3 additions & 6 deletions tests/cli/test_subscriptions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from moto import mock_lambda, mock_logs, mock_cloudformation
from moto import mock_aws

from newrelic_lambda_cli.cli import cli, register_groups


@mock_cloudformation
@mock_lambda
@mock_logs
@mock_aws
def test_subscriptions_install(aws_credentials, cli_runner):
"""
Assert that 'newrelic-lambda subscriptions install' attempts to install the
Expand Down Expand Up @@ -67,8 +65,7 @@ def test_subscriptions_install(aws_credentials, cli_runner):
) in result2.stderr


@mock_lambda
@mock_logs
@mock_aws
def test_subscriptions_uninstall(aws_credentials, cli_runner):
"""
Assert that 'newrelic-lambda subscriptions uninstall' attempts to uninstall the
Expand Down
6 changes: 3 additions & 3 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import boto3
from unittest import mock
from moto import mock_lambda
from moto import mock_aws
from unittest.mock import MagicMock

from newrelic_lambda_cli.functions import get_aliased_functions, list_functions

from .conftest import layer_install


@mock_lambda
@mock_aws
@mock.patch("newrelic_lambda_cli.functions.list_functions", autospec=True)
def test_get_aliased_functions(mock_list_functions, aws_credentials):
"""
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_get_aliased_functions(mock_list_functions, aws_credentials):
]


@mock_lambda
@mock_aws
def test_list_functions(aws_credentials):
session = boto3.Session(region_name="us-east-1")
assert list(list_functions(session)) == []
Expand Down
20 changes: 7 additions & 13 deletions tests/test_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import boto3
import botocore
from moto import (
mock_cloudformation,
mock_iam,
mock_lambda,
mock_sts,
)
from moto import mock_aws
import pytest
from unittest.mock import call, patch, MagicMock, ANY

Expand Down Expand Up @@ -190,7 +185,7 @@ def test_remove_log_ingestion_function_not_present(success_mock):
success_mock.assert_not_called()


@mock_cloudformation
@mock_aws
def test__get_cf_stack_status(aws_credentials):
session = boto3.Session(region_name="us-east-1")
assert _get_cf_stack_status(session, "foo-bar-baz") is None
Expand Down Expand Up @@ -332,21 +327,21 @@ def test__get_stack_output_value():
)


@mock_cloudformation
@mock_aws
def test__create_role(aws_credentials):
session = boto3.Session(region_name="us-east-1")
assert (
_create_role(integration_install(session=session, nr_account_id=12345)) is None
)


@mock_iam
@mock_aws
def test__get_role(aws_credentials):
session = boto3.Session(region_name="us-east-1")
assert _get_role(session, "arn:aws:iam::1234567890:role/foobar") is None


@mock_cloudformation
@mock_aws
def test__import_log_ingestion_function(aws_credentials):
session = boto3.Session(region_name="us-east-1")
_import_log_ingestion_function(
Expand All @@ -361,14 +356,13 @@ def test__import_log_ingestion_function(aws_credentials):
)


@mock_sts
@mock_aws
def test_get_aws_account_id(aws_credentials):
session = boto3.Session(region_name="us-east-1")
assert get_aws_account_id(session) == "123456789012"


@mock_cloudformation
@mock_lambda
@mock_aws
@patch("newrelic_lambda_cli.integrations._get_sar_template_url", autospec=True)
@patch("newrelic_lambda_cli.integrations._create_log_ingestion_function", autospec=True)
def test_update_log_ingestion_function(
Expand Down
8 changes: 4 additions & 4 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import boto3
from click import UsageError
from moto import mock_lambda
from moto import mock_aws
import pytest

from unittest.mock import ANY, call, MagicMock, patch
Expand All @@ -20,7 +20,7 @@
from .conftest import layer_install, layer_uninstall


@mock_lambda
@mock_aws
def test_add_new_relic(aws_credentials, mock_function_config):
session = boto3.Session(region_name="us-east-1")

Expand Down Expand Up @@ -235,7 +235,7 @@ def test_add_new_relic(aws_credentials, mock_function_config):
assert update_kwargs["Layers"][0] != get_arn_prefix("us-east-1")


@mock_lambda
@mock_aws
def test_add_new_relic_dotnet(aws_credentials, mock_function_config):
session = boto3.Session(region_name="us-east-1")

Expand Down Expand Up @@ -298,7 +298,7 @@ def test_add_new_relic_dotnet(aws_credentials, mock_function_config):
)


@mock_lambda
@mock_aws
def test_remove_new_relic(aws_credentials, mock_function_config):
session = boto3.Session(region_name="us-east-1")

Expand Down

0 comments on commit 83fbaaa

Please sign in to comment.