def test_create_and_list_security_group_rules_with_fails( self, security_group_args=None, security_group_rule_args=None): scenario = security_groups.CreateAndListSecurityGroupRules() security_group_data = security_group_args or {} security_group_rule_data = security_group_rule_args or {} security_group = mock.MagicMock() security_group_rule = {"security_group_rule": {"id": 1, "name": "f1"}} scenario._create_security_group = mock.MagicMock() scenario._create_security_group_rule = mock.MagicMock() scenario._list_security_group_rules = mock.MagicMock() scenario._create_security_group_rule.return_value = security_group_rule scenario._list_security_group_rules.return_value = { "security_group_rules": [{ "id": 1, "name": "f1" }, { "id": 2, "name": "f2" }, { "id": 3, "name": "f3" }] } # Negative case1: security_group isn't created scenario._create_security_group.return_value = None self.assertRaises(rally_exceptions.RallyAssertionError, scenario.run, security_group_data, security_group_rule_data) scenario._create_security_group.assert_called_with( **security_group_data) # Negative case2: security_group_rule isn't created scenario._create_security_group.return_value = security_group scenario._create_security_group_rule.return_value = None self.assertRaises(rally_exceptions.RallyAssertionError, scenario.run, security_group_data, security_group_rule_data) scenario._create_security_group.assert_called_with( **security_group_data) scenario._create_security_group_rule.assert_called_with( security_group["security_group"]["id"], **security_group_rule_data) # Negative case3: security_group_rule isn't listed scenario._create_security_group.return_value = security_group scenario._create_security_group_rule.return_value = mock.MagicMock() self.assertRaises(rally_exceptions.RallyAssertionError, scenario.run, security_group_data, security_group_rule_data) scenario._create_security_group.assert_called_with( **security_group_data) scenario._create_security_group_rule.assert_called_with( security_group["security_group"]["id"], **security_group_rule_data) scenario._list_security_group_rules.assert_called_with()
def test_create_and_list_security_group_rules(self, security_group_args=None, security_group_rule_args=None ): scenario = security_groups.CreateAndListSecurityGroupRules() security_group_data = security_group_args or {} security_group_rule_data = security_group_rule_args or {} security_group = mock.MagicMock() security_group_rule = {"security_group_rule": {"id": 1, "name": "f1"}} scenario._create_security_group = mock.MagicMock() scenario._create_security_group_rule = mock.MagicMock() scenario._list_security_group_rules = mock.MagicMock() # Positive case scenario._create_security_group.return_value = security_group scenario._create_security_group_rule.return_value = security_group_rule scenario._list_security_group_rules.return_value = { "security_group_rules": [{ "id": 1, "name": "f1" }, { "id": 2, "name": "f2" }, { "id": 3, "name": "f3" }] } scenario.run(security_group_args=security_group_data, security_group_rule_args=security_group_rule_data) scenario._create_security_group.assert_called_once_with( **security_group_data) scenario._create_security_group_rule.assert_called_once_with( security_group["security_group"]["id"], **security_group_rule_data) scenario._list_security_group_rules.assert_called_once_with()