Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
test: update test profile from root to master
Browse files Browse the repository at this point in the history
  • Loading branch information
kazhala committed Sep 12, 2020
1 parent 6d8b3ca commit 816fca4
Show file tree
Hide file tree
Showing 21 changed files with 154 additions and 88 deletions.
4 changes: 2 additions & 2 deletions scripts/init_test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 7 additions & 3 deletions tests/cloudformation/test_changeset_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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",
Expand All @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions tests/cloudformation/test_cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, {})

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/cloudformation/test_create_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[],
Expand Down Expand Up @@ -127,15 +127,15 @@ 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",
wait=True,
)
mocked_version.assert_not_called()
mocked_validate.assert_called_with(
"root",
"master",
"us-east-1",
bucket="kazhala-lol/hello.yaml",
version="111111",
Expand Down
7 changes: 4 additions & 3 deletions tests/cloudformation/test_delete_stack.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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 ..."
)
Expand Down
4 changes: 2 additions & 2 deletions tests/cloudformation/test_drift_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions tests/cloudformation/test_ls_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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(),
Expand Down
25 changes: 18 additions & 7 deletions tests/cloudformation/test_paramprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -396,7 +405,9 @@ def test_get_list_param_value(
"List<AWS::EC2::AvailabilityZone::Name>", "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"
Expand Down
6 changes: 3 additions & 3 deletions tests/cloudformation/test_validate_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/cloudwatch/test_cloudwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, [""])

Expand Down
36 changes: 27 additions & 9 deletions tests/ec2/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, [{}])
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ec2/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
13 changes: 8 additions & 5 deletions tests/ec2/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand All @@ -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")
4 changes: 2 additions & 2 deletions tests/iam/test_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 816fca4

Please sign in to comment.