summaryrefslogtreecommitdiff
path: root/troveclient/tests/test_secgroups.py
diff options
context:
space:
mode:
authorMichael Basnight <mbasnight@gmail.com>2013-06-17 23:34:27 -0700
committerMichael Basnight <mbasnight@gmail.com>2013-06-21 20:15:23 +0000
commit9916c8f2733b683d859770d05dacd2c9c82912d7 (patch)
tree084a0d53580cbbd34ed8f28de9302d6c78f7050d /troveclient/tests/test_secgroups.py
parentbc90b3e088d3d4b83b5b3de0f9f83d9b6956947d (diff)
downloadpython-troveclient-0.1.3.tar.gz
Rename from reddwarf to trove.0.1.3
Implements Blueprint reddwarf-trove-rename Change-Id: Ib2d694c7466887ca297bea4250eca17cdc06b7bf
Diffstat (limited to 'troveclient/tests/test_secgroups.py')
-rw-r--r--troveclient/tests/test_secgroups.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/troveclient/tests/test_secgroups.py b/troveclient/tests/test_secgroups.py
new file mode 100644
index 0000000..779d01e
--- /dev/null
+++ b/troveclient/tests/test_secgroups.py
@@ -0,0 +1,102 @@
+from testtools import TestCase
+from mock import Mock
+
+from troveclient import security_groups
+from troveclient import base
+
+"""
+Unit tests for security_groups.py
+"""
+
+
+class SecGroupTest(TestCase):
+
+ def setUp(self):
+ super(SecGroupTest, self).setUp()
+ self.orig__init = security_groups.SecurityGroup.__init__
+ security_groups.SecurityGroup.__init__ = Mock(return_value=None)
+ self.security_group = security_groups.SecurityGroup()
+ self.security_groups = security_groups.SecurityGroups(1)
+
+ def tearDown(self):
+ super(SecGroupTest, self).tearDown()
+ security_groups.SecurityGroup.__init__ = self.orig__init
+
+ def test___repr__(self):
+ self.security_group.name = "security_group-1"
+ self.assertEqual('<SecurityGroup: security_group-1>',
+ self.security_group.__repr__())
+
+ def test_list(self):
+ sec_group_list = ['secgroup1', 'secgroup2']
+ self.security_groups.list = Mock(return_value=sec_group_list)
+ self.assertEqual(sec_group_list, self.security_groups.list())
+
+ def test_get(self):
+ def side_effect_func(path, inst):
+ return path, inst
+
+ self.security_groups._get = Mock(side_effect=side_effect_func)
+ self.security_group.id = 1
+ self.assertEqual(('/security-groups/1', 'security_group'),
+ self.security_groups.get(self.security_group))
+
+
+class SecGroupRuleTest(TestCase):
+
+ def setUp(self):
+ super(SecGroupRuleTest, self).setUp()
+ self.orig__init = security_groups.SecurityGroupRule.__init__
+ security_groups.SecurityGroupRule.__init__ = Mock(return_value=None)
+ security_groups.SecurityGroupRules.__init__ = Mock(return_value=None)
+ self.security_group_rule = security_groups.SecurityGroupRule()
+ self.security_group_rules = security_groups.SecurityGroupRules()
+
+ def tearDown(self):
+ super(SecGroupRuleTest, self).tearDown()
+ security_groups.SecurityGroupRule.__init__ = self.orig__init
+
+ def test___repr__(self):
+ self.security_group_rule.group_id = 1
+ self.security_group_rule.protocol = "tcp"
+ self.security_group_rule.from_port = 80
+ self.security_group_rule.to_port = 80
+ self.security_group_rule.cidr = "0.0.0.0//0"
+ representation = \
+ "<SecurityGroupRule: ( \
+ Security Group id: %d, \
+ Protocol: %s, \
+ From_Port: %d, \
+ To_Port: %d, \
+ CIDR: %s )>" % (1, "tcp", 80, 80, "0.0.0.0//0")
+
+ self.assertEqual(representation,
+ self.security_group_rule.__repr__())
+
+ def test_create(self):
+ def side_effect_func(path, body, inst):
+ return path, body, inst
+
+ self.security_group_rules._create = Mock(side_effect=side_effect_func)
+ p, b, i = self.security_group_rules.create(1, "tcp",
+ 80, 80, "0.0.0.0//0")
+ self.assertEqual("/security-group-rules", p)
+ self.assertEqual("security_group_rule", i)
+ self.assertEqual(1, b["security_group_rule"]["group_id"])
+ self.assertEqual("tcp", b["security_group_rule"]["protocol"])
+ self.assertEqual(80, b["security_group_rule"]["from_port"])
+ self.assertEqual(80, b["security_group_rule"]["to_port"])
+ self.assertEqual("0.0.0.0//0", b["security_group_rule"]["cidr"])
+
+ def test_delete(self):
+ resp = Mock()
+ resp.status = 200
+ body = None
+ self.security_group_rules.api = Mock()
+ self.security_group_rules.api.client = Mock()
+ self.security_group_rules.api.client.delete = \
+ Mock(return_value=(resp, body))
+ self.security_group_rules.delete(self.id)
+ resp.status = 500
+ self.assertRaises(Exception, self.security_group_rules.delete,
+ self.id)