diff --git a/scripts/init_test b/scripts/init_test index b78f557..5953cee 100755 --- a/scripts/init_test +++ b/scripts/init_test @@ -11,7 +11,7 @@ cat << EOF > "$HOME"/.aws/credentials [default] aws_access_key_id = 111111111" aws_secret_access_key = 111111111" -[root] +[master] aws_access_key_id = 111111111" aws_secret_access_key = 111111111" EOF @@ -20,7 +20,7 @@ cat << EOF > "$HOME"/.aws/config [default] region = ap-southeast-2 output = json -[profile root] +[profile master] region = ap-southeast-2 output = json EOF diff --git a/tests/cloudformation/test_changeset_stack.py b/tests/cloudformation/test_changeset_stack.py index 79d2e18..b88da86 100644 --- a/tests/cloudformation/test_changeset_stack.py +++ b/tests/cloudformation/test_changeset_stack.py @@ -100,7 +100,11 @@ def test_execute_changeset( @patch.object(Pyfzf, "execute_fzf") @patch("fzfaws.cloudformation.changeset_stack.Cloudformation") def test_delete_changeset( - self, MockedCloudformation, mocked_execute, mocked_process, mocked_confirm, + self, + MockedCloudformation, + mocked_execute, + mocked_process, + mocked_confirm, ): mocked_confirm.return_value = True cloudformation = MockedCloudformation() @@ -140,7 +144,7 @@ def test_create_changeset( "cloudformation_action": cloudformation.client.create_change_set, } cloudformation.execute_with_capabilities.return_value = {} - changeset_stack(profile="root", region="us-east-1") + changeset_stack(profile="master", region="us-east-1") cloudformation.execute_with_capabilities.assert_called_once_with( ChangeSetName="fooboo", Description="hello", @@ -166,7 +170,7 @@ def test_create_changeset( cloudformation=cloudformation, dryrun=True, ) - MockedCloudformation.assert_called_with("root", "us-east-1") + MockedCloudformation.assert_called_with("master", "us-east-1") changeset_stack( replace=True, wait=True, extra=True, bucket="kazhala-lol/hello.yaml" diff --git a/tests/cloudformation/test_cloudformation.py b/tests/cloudformation/test_cloudformation.py index 02ca41e..fded233 100644 --- a/tests/cloudformation/test_cloudformation.py +++ b/tests/cloudformation/test_cloudformation.py @@ -31,9 +31,9 @@ def test_constructor(self): self.assertEqual(self.cloudformation.stack_name, "") self.assertEqual(self.cloudformation.stack_details, {}) - cloudformation = Cloudformation(profile="root", region="us-east-1") + cloudformation = Cloudformation(profile="master", region="us-east-1") self.assertEqual(cloudformation.region, "us-east-1") - self.assertEqual(cloudformation.profile, "root") + self.assertEqual(cloudformation.profile, "master") self.assertEqual(cloudformation.stack_name, "") self.assertEqual(cloudformation.stack_details, {}) @@ -189,7 +189,9 @@ def test_wait(self, mocked_wait): self.cloudformation.stack_name = "fooboo" self.cloudformation.wait(waiter_name="stack_create_complete", message="hello") mocked_wait.assert_called_once_with( - ANY, StackName="fooboo", WaiterConfig={"Delay": 15, "MaxAttempts": 40}, + ANY, + StackName="fooboo", + WaiterConfig={"Delay": 15, "MaxAttempts": 40}, ) self.capturedOutput.truncate(0) diff --git a/tests/cloudformation/test_create_stack.py b/tests/cloudformation/test_create_stack.py index 3a37085..79d5c17 100644 --- a/tests/cloudformation/test_create_stack.py +++ b/tests/cloudformation/test_create_stack.py @@ -65,11 +65,11 @@ def test_local_creation( mocked_local.reset_mock() create_stack( - profile="root", region="us-east-1", local_path=self.data_path, wait=True + profile="master", region="us-east-1", local_path=self.data_path, wait=True ) mocked_local.assert_not_called() mocked_validate.assert_called_with( - "root", "us-east-1", local_path=self.data_path, no_print=True + "master", "us-east-1", local_path=self.data_path, no_print=True ) mocked_execute.assert_called_with( Parameters=[], @@ -127,7 +127,7 @@ def test_s3_creation( mocked_version.reset_mock() create_stack( - profile="root", + profile="master", region="us-east-1", bucket="kazhala-lol/hello.yaml", version="111111", @@ -135,7 +135,7 @@ def test_s3_creation( ) mocked_version.assert_not_called() mocked_validate.assert_called_with( - "root", + "master", "us-east-1", bucket="kazhala-lol/hello.yaml", version="111111", diff --git a/tests/cloudformation/test_delete_stack.py b/tests/cloudformation/test_delete_stack.py index 50f0acb..87980db 100644 --- a/tests/cloudformation/test_delete_stack.py +++ b/tests/cloudformation/test_delete_stack.py @@ -1,8 +1,9 @@ -import os import io +import os import sys import unittest from unittest.mock import patch + from fzfaws.cloudformation.delete_stack import delete_stack @@ -29,8 +30,8 @@ def test_normal_delete(self, MockedCloudformation, mocked_confirm): cloudformation.client.delete_stack.assert_called_with(StackName="testing1") cloudformation.client.wait.assert_not_called() - delete_stack(wait=True, profile="root", region="us-east-1") - MockedCloudformation.assert_called_with("root", "us-east-1") + delete_stack(wait=True, profile="master", region="us-east-1") + MockedCloudformation.assert_called_with("master", "us-east-1") cloudformation.wait.assert_called_once_with( "stack_delete_complete", "Wating for stack to be deleted ..." ) diff --git a/tests/cloudformation/test_drift_stack.py b/tests/cloudformation/test_drift_stack.py index c3c20ba..7a0df78 100644 --- a/tests/cloudformation/test_drift_stack.py +++ b/tests/cloudformation/test_drift_stack.py @@ -36,8 +36,8 @@ def test_info(self, MockedCloudformation): cloudformation.stack_details = self.cloudformation_details cloudformation.stack_name = "testing1" cloudformation.client.describe_stack_resource_drifts.return_value = {} - drift_stack(profile="root", region="us-east-1", info=True) - MockedCloudformation.assert_called_with("root", "us-east-1") + drift_stack(profile="master", region="us-east-1", info=True) + MockedCloudformation.assert_called_with("master", "us-east-1") cloudformation.set_stack.assert_called_once() cloudformation.client.describe_stack_resource_drifts.assert_called_once_with( StackName="testing1" diff --git a/tests/cloudformation/test_ls_stack.py b/tests/cloudformation/test_ls_stack.py index 150e0b1..d305e7d 100644 --- a/tests/cloudformation/test_ls_stack.py +++ b/tests/cloudformation/test_ls_stack.py @@ -22,7 +22,9 @@ def setUp(self): {"Key": "Application", "Value": "mealternative"}, {"Key": "Name", "Value": "mealternative"}, ], - "DriftInformation": {"StackDriftStatus": "IN_SYNC",}, + "DriftInformation": { + "StackDriftStatus": "IN_SYNC", + }, } self.resource_response = { "StackResourceDetail": { @@ -91,8 +93,8 @@ def test_ls_stack(self, MockedCloudformation): cloudformation = MockedCloudformation() cloudformation.stack_name = "dotbare-cicd" cloudformation.stack_details = self.stack_response - ls_stack(profile="root", region="us-east-1") - MockedCloudformation.assert_called_with("root", "us-east-1") + ls_stack(profile="master", region="us-east-1") + MockedCloudformation.assert_called_with("master", "us-east-1") self.assertRegex(self.capturedOutput.getvalue(), r'"StackName": "dotbare-cicd"') self.assertRegex( self.capturedOutput.getvalue(), diff --git a/tests/cloudformation/test_paramprocessor.py b/tests/cloudformation/test_paramprocessor.py index 9ba4278..dc46a73 100644 --- a/tests/cloudformation/test_paramprocessor.py +++ b/tests/cloudformation/test_paramprocessor.py @@ -45,10 +45,10 @@ def test_constructor(self): self.assertEqual(self.paramprocessor.original_params, {}) self.assertEqual(self.paramprocessor.processed_params, []) - paramprocessor = ParamProcessor(profile="root", region="us-east-1") - self.assertEqual(paramprocessor.ec2.profile, "root") + paramprocessor = ParamProcessor(profile="master", region="us-east-1") + self.assertEqual(paramprocessor.ec2.profile, "master") self.assertEqual(paramprocessor.ec2.region, "us-east-1") - self.assertEqual(paramprocessor.route53.profile, "root") + self.assertEqual(paramprocessor.route53.profile, "master") self.assertEqual(paramprocessor.route53.region, "us-east-1") self.assertEqual(paramprocessor.params, {}) self.assertEqual(paramprocessor.processed_params, []) @@ -92,7 +92,8 @@ def test_process_stack_params1(self, mocked_input, mocked_selection): r"ConstraintDescription: must be the name of an existing EC2 KeyPair", ) self.assertRegex( - self.capturedOutput.getvalue(), r"ParameterValue: 111111", + self.capturedOutput.getvalue(), + r"ParameterValue: 111111", ) mocked_input.assert_called_with( "InstanceType", @@ -130,7 +131,10 @@ def test_process_stack_params2(self, mocked_input, mocked_selection): self.assertEqual( self.paramprocessor.processed_params, [ - {"ParameterKey": "InstanceRole", "ParameterValue": "111111,222222",}, + { + "ParameterKey": "InstanceRole", + "ParameterValue": "111111,222222", + }, {"ParameterKey": "LatestAmiId", "ParameterValue": "111111,222222"}, {"ParameterKey": "SubnetId", "ParameterValue": "111111,222222"}, {"ParameterKey": "SecurityGroups", "ParameterValue": "111111,222222"}, @@ -316,7 +320,12 @@ def test_print_parameter_key(self): @patch.object(Pyfzf, "execute_fzf") @patch.object(Pyfzf, "process_list") def test_get_selected_param_value( - self, mocked_process, mocked_execute, mocked_client, mocked_sg, mocked_zone, + self, + mocked_process, + mocked_execute, + mocked_client, + mocked_sg, + mocked_zone, ): mocked_execute.return_value = "111111" @@ -396,7 +405,9 @@ def test_get_list_param_value( "List", "foo boo" ) mocked_process.assert_called_once_with( - az_response["AvailabilityZones"], "ZoneName", empty_allow=True, + az_response["AvailabilityZones"], + "ZoneName", + empty_allow=True, ) mocked_execute.assert_called_once_with( multi_select=True, empty_allow=True, header="foo boo" diff --git a/tests/cloudformation/test_validate_stack.py b/tests/cloudformation/test_validate_stack.py index 91d5b2f..7807881 100644 --- a/tests/cloudformation/test_validate_stack.py +++ b/tests/cloudformation/test_validate_stack.py @@ -68,9 +68,9 @@ def test_s3_validate(self, MockedCloudformation, MockedS3): "https://s3-ap-southeast-2.amazonaws.com/kazhala-lol/hello.yaml" ) s3.get_object_version.return_value = [{"VersionId": "111111"}] - validate_stack(profile="root", region="ap-southeast-2") - MockedS3.assert_called_with("root", "ap-southeast-2") - MockedCloudformation.assert_called_with("root", "ap-southeast-2") + validate_stack(profile="master", region="ap-southeast-2") + MockedS3.assert_called_with("master", "ap-southeast-2") + MockedCloudformation.assert_called_with("master", "ap-southeast-2") s3.get_object_url.assert_called_once_with("") cloudformation.client.validate_template.assert_called_once_with( TemplateURL="https://s3-ap-southeast-2.amazonaws.com/kazhala-lol/hello.yaml" diff --git a/tests/cloudwatch/test_cloudwatch.py b/tests/cloudwatch/test_cloudwatch.py index adc417b..e53e7c6 100644 --- a/tests/cloudwatch/test_cloudwatch.py +++ b/tests/cloudwatch/test_cloudwatch.py @@ -25,8 +25,8 @@ def test_constructor(self): self.assertEqual(self.cloudwatch.region, "us-east-1") self.assertEqual(self.cloudwatch.arns, [""]) - cloudwatch = Cloudwatch(profile="root", region="us-east-1") - self.assertEqual(cloudwatch.profile, "root") + cloudwatch = Cloudwatch(profile="master", region="us-east-1") + self.assertEqual(cloudwatch.profile, "master") self.assertEqual(cloudwatch.region, "us-east-1") self.assertEqual(cloudwatch.arns, [""]) diff --git a/tests/ec2/test_ec2.py b/tests/ec2/test_ec2.py index fdd607f..bf49e43 100644 --- a/tests/ec2/test_ec2.py +++ b/tests/ec2/test_ec2.py @@ -31,8 +31,8 @@ def test_constructor(self): self.assertEqual(self.ec2.instance_ids, [""]) self.assertEqual(self.ec2.instance_list, [{}]) - ec2 = EC2(profile="root", region="us-east-1") - self.assertEqual(ec2.profile, "root") + ec2 = EC2(profile="master", region="us-east-1") + self.assertEqual(ec2.profile, "master") self.assertEqual(ec2.region, "us-east-1") self.assertEqual(self.ec2.instance_ids, [""]) self.assertEqual(self.ec2.instance_list, [{}]) @@ -211,7 +211,8 @@ def test_waiter_arg2(obj, **kwargs): self.ec2.instance_ids = ["11111111"] self.ec2.wait("instance_status_ok", "hello") self.assertRegex( - self.capturedOutput.getvalue(), r"^| hello.*$", + self.capturedOutput.getvalue(), + r"^| hello.*$", ) @patch.object(Pyfzf, "process_list") @@ -229,7 +230,10 @@ def test_get_security_groups( mocked_fzf_execute.return_value = "sg-006ae18653dc5acd7" self.ec2.get_security_groups() mocked_fzf_list.assert_called_with( - ANY, "GroupId", "GroupName", "Name", + ANY, + "GroupId", + "GroupName", + "Name", ) mocked_fzf_execute.assert_called_with( multi_select=False, empty_allow=True, header=None @@ -241,7 +245,9 @@ def test_get_security_groups( multi_select=True, return_attr="name", header="hello" ) mocked_fzf_list.assert_called_with( - ANY, "GroupName", "Name", + ANY, + "GroupName", + "Name", ) mocked_fzf_execute.assert_called_with( multi_select=True, empty_allow=True, header="hello" @@ -260,7 +266,9 @@ def test_get_instance_id(self, mocked_result, mocked_fzf_execute, mocked_fzf_lis mocked_fzf_execute.return_value = "11111111" self.ec2.get_instance_id() mocked_fzf_list.assert_called_with( - ANY, "InstanceId", "Name", + ANY, + "InstanceId", + "Name", ) mocked_fzf_execute.assert_called_with( multi_select=False, empty_allow=True, header=None @@ -287,7 +295,11 @@ def test_get_subnet_id(self, mocked_result, mocked_fzf_execute, mocked_fzf_list) mocked_fzf_execute.return_value = "11111111" self.ec2.get_subnet_id() mocked_fzf_list.assert_called_with( - ANY, "SubnetId", "AvailabilityZone", "CidrBlock", "Name", + ANY, + "SubnetId", + "AvailabilityZone", + "CidrBlock", + "Name", ) mocked_fzf_execute.assert_called_with( multi_select=False, empty_allow=True, header=None @@ -314,7 +326,9 @@ def test_get_volume_id(self, mocked_result, mocked_fzf_execute, mocked_fzf_list) mocked_fzf_execute.return_value = "11111111" self.ec2.get_volume_id() mocked_fzf_list.assert_called_with( - ANY, "VolumeId", "Name", + ANY, + "VolumeId", + "Name", ) mocked_fzf_execute.assert_called_with( multi_select=False, empty_allow=True, header=None @@ -341,7 +355,11 @@ def test_get_vpc_id(self, mocked_result, mocked_fzf_execute, mocked_fzf_list): mocked_fzf_execute.return_value = "11111111" self.ec2.get_vpc_id() mocked_fzf_list.assert_called_with( - ANY, "VpcId", "IsDefault", "CidrBlock", "Name", + ANY, + "VpcId", + "IsDefault", + "CidrBlock", + "Name", ) mocked_fzf_execute.assert_called_with( empty_allow=True, multi_select=False, header=None diff --git a/tests/ec2/test_ssh.py b/tests/ec2/test_ssh.py index 7b1ba25..407db63 100644 --- a/tests/ec2/test_ssh.py +++ b/tests/ec2/test_ssh.py @@ -75,7 +75,7 @@ def test_tunnel_ssh_instance( # normal mocked_ssh_cmd.return_value = ["sleep", "0"] mocked_instance_ip.return_value = "11111111" - ssh_instance(profile="root", region="us-east-1", bastion=True, tunnel=True) + ssh_instance(profile="master", region="us-east-1", bastion=True, tunnel=True) mocked_set_instance.assert_called_with( multi_select=False, header="select the destination instance" ) diff --git a/tests/ec2/test_start.py b/tests/ec2/test_start.py index 0e9ffda..721759d 100644 --- a/tests/ec2/test_start.py +++ b/tests/ec2/test_start.py @@ -44,7 +44,8 @@ def test_start_instance( mocked_detail.assert_called_once() mocked_wait.assert_not_called() self.assertRegex( - self.capturedOutput.getvalue(), r".*Instance start initiated.*", + self.capturedOutput.getvalue(), + r".*Instance start initiated.*", ) # remock @@ -58,12 +59,13 @@ def test_start_instance( mocked_set_instance.reset_mock() mocked_detail.reset_mock() - start_instance("root", "us-east-1", False, True) + start_instance("master", "us-east-1", False, True) mocked_set_instance.assert_called_once() mocked_detail.assert_called_once() mocked_wait.assert_called_once() self.assertRegex( - self.capturedOutput.getvalue(), r".*Instance start initiated.*", + self.capturedOutput.getvalue(), + r".*Instance start initiated.*", ) self.assertRegex(self.capturedOutput.getvalue(), r".*Instance is ready") @@ -78,10 +80,11 @@ def test_start_instance( mocked_set_instance.reset_mock() mocked_detail.reset_mock() - start_instance("root", "us-east-1", True, False) + start_instance("master", "us-east-1", True, False) mocked_set_instance.assert_called_once() mocked_detail.assert_called_once() self.assertRegex( - self.capturedOutput.getvalue(), r".*Instance start initiated.*", + self.capturedOutput.getvalue(), + r".*Instance start initiated.*", ) self.assertRegex(self.capturedOutput.getvalue(), r".*Instance is running") diff --git a/tests/iam/test_iam.py b/tests/iam/test_iam.py index 860d20e..03d0bb1 100644 --- a/tests/iam/test_iam.py +++ b/tests/iam/test_iam.py @@ -26,8 +26,8 @@ def test_constructor(self): self.assertEqual("default", self.iam.profile) self.assertEqual("us-east-1", self.iam.region) - iam = IAM(profile="root", region="us-east-1") - self.assertEqual("root", iam.profile) + iam = IAM(profile="master", region="us-east-1") + self.assertEqual("master", iam.profile) self.assertEqual("us-east-1", iam.region) self.assertEqual([""], self.iam.arns) diff --git a/tests/kms/test_kms.py b/tests/kms/test_kms.py index 189968e..c0a017c 100644 --- a/tests/kms/test_kms.py +++ b/tests/kms/test_kms.py @@ -26,8 +26,8 @@ def test_constructor(self): self.assertEqual(self.kms.region, "us-east-1") self.assertEqual(self.kms.keyids, [""]) - kms = KMS(profile="root", region="us-east-1") - self.assertEqual(kms.profile, "root") + kms = KMS(profile="master", region="us-east-1") + self.assertEqual(kms.profile, "master") self.assertEqual(kms.region, "us-east-1") self.assertEqual(kms.keyids, [""]) @@ -50,7 +50,10 @@ def test_set_keyids(self, mocked_result, mocked_fzf_list, mocked_fzf_execute): }, ], "Truncated": False, - "ResponseMetadata": {"HTTPStatusCode": 200, "RetryAttempts": 0,}, + "ResponseMetadata": { + "HTTPStatusCode": 200, + "RetryAttempts": 0, + }, } ] diff --git a/tests/lambdaf/test_lambdaf.py b/tests/lambdaf/test_lambdaf.py index 29ec02a..8e38914 100644 --- a/tests/lambdaf/test_lambdaf.py +++ b/tests/lambdaf/test_lambdaf.py @@ -28,8 +28,8 @@ def test_constructor(self): self.assertEqual(self.lambdaf.function_name, "") self.assertEqual(self.lambdaf.function_detail, {}) - lambdaf = Lambdaf(profile="root", region="us-east-1") - self.assertEqual(lambdaf.profile, "root") + lambdaf = Lambdaf(profile="master", region="us-east-1") + self.assertEqual(lambdaf.profile, "master") self.assertEqual(lambdaf.region, "us-east-1") self.assertEqual(lambdaf.function_name, "") self.assertEqual(lambdaf.function_detail, {}) diff --git a/tests/route53/test_route53.py b/tests/route53/test_route53.py index 7426de9..de2acd7 100644 --- a/tests/route53/test_route53.py +++ b/tests/route53/test_route53.py @@ -26,9 +26,9 @@ def test_constructor(self): self.assertEqual(self.route53.profile, "default") self.assertEqual(self.route53.region, "us-east-1") - route53 = Route53(profile="root", region="us-west-1") + route53 = Route53(profile="master", region="us-west-1") self.assertEqual(route53.zone_ids, [""]) - self.assertEqual(route53.profile, "root") + self.assertEqual(route53.profile, "master") self.assertEqual(route53.region, "us-west-1") @patch.object(Pyfzf, "execute_fzf") @@ -37,7 +37,10 @@ def test_constructor(self): def test_set_zone_id(self, mocked_result, mocked_fzf_process, mocked_fzf_execute): mocked_result.return_value = [ { - "ResponseMetadata": {"HTTPStatusCode": 200, "RetryAttempts": 0,}, + "ResponseMetadata": { + "HTTPStatusCode": 200, + "RetryAttempts": 0, + }, "HostedZones": [ { "Id": "/hostedzone/111111", @@ -130,10 +133,15 @@ def test_process_hosted_zone(self): # missing attr test test_list = [ - {"Id": "/hostedzone/111111",}, - {"Id": "/hostedzone/222222",}, + { + "Id": "/hostedzone/111111", + }, + { + "Id": "/hostedzone/222222", + }, ] result = self.route53._process_hosted_zone(test_list) self.assertEqual( - [{"Id": "111111", "Name": None}, {"Id": "222222", "Name": None}], result, + [{"Id": "111111", "Name": None}, {"Id": "222222", "Name": None}], + result, ) diff --git a/tests/s3/test_s3.py b/tests/s3/test_s3.py index ed5d7e4..f0c154a 100644 --- a/tests/s3/test_s3.py +++ b/tests/s3/test_s3.py @@ -33,8 +33,8 @@ def test_constructor(self): self.assertEqual(self.s3.bucket_name, "") self.assertEqual(self.s3.path_list, [""]) - s3 = S3(profile="root", region="us-east-1") - self.assertEqual(s3.profile, "root") + s3 = S3(profile="master", region="us-east-1") + self.assertEqual(s3.profile, "master") self.assertEqual(s3.region, "us-east-1") self.assertEqual(s3.bucket_name, "") self.assertEqual(s3.path_list, [""]) @@ -156,7 +156,8 @@ def test_validate_input_path(self): ) self.assertEqual(result, "accesspoint") self.assertEqual( - match, ("arn:aws:s3:us-west-2:123456789012:accesspoint/test/", "hello"), + match, + ("arn:aws:s3:us-west-2:123456789012:accesspoint/test/", "hello"), ) result, match = self.s3._validate_input_path( diff --git a/tests/sns/test_sns.py b/tests/sns/test_sns.py index 12572d6..d45c77e 100644 --- a/tests/sns/test_sns.py +++ b/tests/sns/test_sns.py @@ -25,8 +25,8 @@ def test_constructor(self): self.assertEqual(self.sns.region, "us-east-1") self.assertEqual(self.sns.arns, [""]) - sns = SNS(profile="root", region="us-east-2") - self.assertEqual(sns.profile, "root") + sns = SNS(profile="master", region="us-east-2") + self.assertEqual(sns.profile, "master") self.assertEqual(sns.region, "us-east-2") self.assertEqual(sns.arns, [""]) diff --git a/tests/utils/test_fileloader.py b/tests/utils/test_fileloader.py index 2750a82..9db2d87 100644 --- a/tests/utils/test_fileloader.py +++ b/tests/utils/test_fileloader.py @@ -1,8 +1,9 @@ -import os import json -import unittest +import os import tempfile +import unittest from unittest.mock import patch + from fzfaws.utils import FileLoader @@ -95,9 +96,13 @@ def test_set_cloudformation_env(self): # custom settings self.fileloader._set_cloudformation_env( - {"profile": "root", "region": "us-east-2", "default_args": {"create": "-l"}} + { + "profile": "master", + "region": "us-east-2", + "default_args": {"create": "-l"}, + } ) - self.assertEqual(os.environ["FZFAWS_CLOUDFORMATION_PROFILE"], "root") + self.assertEqual(os.environ["FZFAWS_CLOUDFORMATION_PROFILE"], "master") self.assertEqual(os.environ["FZFAWS_CLOUDFORMATION_REGION"], "us-east-2") self.assertEqual(os.environ["FZFAWS_CLOUDFORMATION_CREATE"], "-l") @@ -141,16 +146,21 @@ def test_set_s3_env(self): self.fileloader._set_s3_env( { "transfer_config": {"multipart_threshold": 1, "multipart_chunksize": 1}, - "profile": "root", + "profile": "master", "default_args": {"upload": "-R", "ls": "-b"}, } ) self.assertEqual( os.environ["FZFAWS_S3_TRANSFER"], - json.dumps({"multipart_threshold": 1, "multipart_chunksize": 1,}), + json.dumps( + { + "multipart_threshold": 1, + "multipart_chunksize": 1, + } + ), ) self.assertEqual(os.environ["FZFAWS_S3_UPLOAD"], "-R") - self.assertEqual(os.environ["FZFAWS_S3_PROFILE"], "root") + self.assertEqual(os.environ["FZFAWS_S3_PROFILE"], "master") self.assertEqual(os.environ["FZFAWS_S3_LS"], "-b") self.assertEqual(os.getenv("FZFAWS_S3_DOWNLOAD", ""), "") self.assertEqual(os.getenv("FZFAWS_S3_PRESIGN", ""), "") @@ -192,16 +202,17 @@ def test_set_ec2_env(self): "waiter": {"max_attempts": 40}, "default_args": {"ssh": "-A"}, "region": "us-east-1", - "profile": "root", + "profile": "master", } ) self.assertEqual(os.environ["FZFAWS_EC2_KEYPAIRS"], "$HOME/Anywhere/aws") self.assertEqual( - os.environ["FZFAWS_EC2_WAITER"], json.dumps({"max_attempts": 40}), + os.environ["FZFAWS_EC2_WAITER"], + json.dumps({"max_attempts": 40}), ) self.assertEqual(os.environ["FZFAWS_EC2_SSH"], "-A") self.assertEqual(os.environ["FZFAWS_EC2_REGION"], "us-east-1") - self.assertEqual(os.environ["FZFAWS_EC2_PROFILE"], "root") + self.assertEqual(os.environ["FZFAWS_EC2_PROFILE"], "master") def test_set_global_env(self): # normal test @@ -226,17 +237,17 @@ def test_set_global_env(self): # custom settings self.fileloader._set_gloable_env( - {"profile": "root", "region": "us-east-1", "waiter": {"delay": 10}} + {"profile": "master", "region": "us-east-1", "waiter": {"delay": 10}} ) self.assertEqual(os.environ["FZFAWS_GLOBAL_WAITER"], json.dumps({"delay": 10})) self.assertEqual(os.environ["FZFAWS_GLOBAL_REGION"], "us-east-1") - self.assertEqual(os.environ["FZFAWS_GLOBAL_PROFILE"], "root") + self.assertEqual(os.environ["FZFAWS_GLOBAL_PROFILE"], "master") os.environ["FZFAWS_GLOBAL_WAITER"] = "" - self.fileloader._set_gloable_env({"profile": "root", "region": "us-east-1"}) + self.fileloader._set_gloable_env({"profile": "master", "region": "us-east-1"}) self.assertEqual(os.environ["FZFAWS_GLOBAL_WAITER"], "") self.assertEqual(os.environ["FZFAWS_GLOBAL_REGION"], "us-east-1") - self.assertEqual(os.environ["FZFAWS_GLOBAL_PROFILE"], "root") + self.assertEqual(os.environ["FZFAWS_GLOBAL_PROFILE"], "master") def test_set_fzf_env(self): # normal test diff --git a/tests/utils/test_session.py b/tests/utils/test_session.py index fe1e5c1..72d06c1 100644 --- a/tests/utils/test_session.py +++ b/tests/utils/test_session.py @@ -1,10 +1,12 @@ +from pathlib import Path import unittest -from unittest.mock import patch, PropertyMock -from fzfaws.utils import BaseSession, Pyfzf, FileLoader -from boto3.session import Session +from unittest.mock import PropertyMock, patch + import boto3 +from boto3.session import Session from botocore.stub import Stubber -from pathlib import Path + +from fzfaws.utils import BaseSession, FileLoader, Pyfzf class TestSession(unittest.TestCase): @@ -20,9 +22,9 @@ def test_empty_init(self): def test_param_profile_region(self): session = BaseSession( - profile="root", region="ap-southeast-2", service_name="ec2" + profile="master", region="ap-southeast-2", service_name="ec2" ) - self.assertEqual("root", session.profile) + self.assertEqual("master", session.profile) self.assertEqual("ap-southeast-2", session.region) session = BaseSession(profile=None, region=None, service_name="ec2") @@ -41,11 +43,11 @@ def test_param_profile_region(self): @patch.object(Pyfzf, "execute_fzf") @patch.object(Session, "available_profiles", new_callable=PropertyMock) def test_fzf_profile(self, mocked_profile, mocked_fzf_execute, mocked_fzf_append): - mocked_profile.return_value = ["root", "default", "hello"] + mocked_profile.return_value = ["master", "default", "hello"] - mocked_fzf_execute.return_value = "root" + mocked_fzf_execute.return_value = "master" session = BaseSession(profile=True, region=None, service_name="ec2") - self.assertEqual("root", session.profile) + self.assertEqual("master", session.profile) mocked_fzf_append.assert_called_with("hello\n") @patch.object(Pyfzf, "append_fzf")