1. Pior Bastida
  2. awstools

Commits

Pior Bastida  committed e948d19

Improve test_awstools

  • Participants
  • Parent commits a0c4801
  • Branches default

Comments (0)

Files changed (2)

File awstools/tests/unittests/test_awstools.py

View file
 # you should have received as part of this distribution.
 # Author: Pior Bastida <pbastida@socialludia.com>
 
+from UserList import UserList
 import unittest
 
 import mock
         self.stack_status = status
 
 
-class StackList(list):
-    def __init__(self, l=[], next_token=None):
-        self.extend(l)
+class StackList(UserList):
+    def __init__(self, data, next_token=None):
+        super(StackList, self).__init__(data)
         self.next_token = next_token
 
-teststacks1 = StackList([
-                        Stack('test1'),
-                        Stack('test2'),
-                        Stack('test3'),
-                        ],
-                        next_token='tok')
-
-teststacks2 = StackList([
-                        Stack('ns1'),
-                        Stack('ns2'),
-                        Stack('deleted', status='DELETE_COMPLETE')
-                        ])
-
-stack_list = sorted(['test1', 'test2', 'test3', 'ns1', 'ns2'])
-
 
 class TestAwstools(unittest.TestCase):
 
-    @mock.patch('boto.connect_cloudformation')
+    def setUp(self):
+        self.teststacks1 = StackList(
+            [Stack('test1'),  Stack('test2'), Stack('test3')],
+            next_token='tok')
+
+        self.teststacks2 = StackList(
+            [Stack('ns1'), Stack('ns2'),
+             Stack('deleted', status='DELETE_COMPLETE')])
+
+        self.stack_list = sorted(['test1', 'test2', 'test3',
+                                  'ns1', 'ns2', 'deleted'])
+
+        self.result = None
+
+    def check_slist(self, listok):
+        self.assertEqual([s.stack_name for s in self.result], sorted(listok))
+
+    @mock.patch('awstools.utils.cloudformation.boto.connect_cloudformation')
     def test_find_stacks_valid(self, mock_conn_cfn):
-        from awstools import utils
+        from awstools.utils import cloudformation
 
-        mock_cfn = mock.MagicMock()
-        mock_cfn.list_stacks.side_effect = [
-            teststacks1,
-            teststacks2,
-        ]
-        mock_conn_cfn.return_value = mock_cfn
+        l_s = mock_conn_cfn.return_value.list_stacks
+        l_s.side_effect = [self.teststacks1, self.teststacks2]
 
-        res = utils.cloudformation.find_stacks()
+        self.result = cloudformation.find_stacks()
 
-        self.assertEqual(mock_cfn.list_stacks.mock_calls,
-                         [mock.call(next_token=None),
-                          mock.call(next_token='tok')]
-                         )
+        l_s.assert_has_calls([mock.call(next_token=None),
+                              mock.call(next_token='tok')])
 
-        self.assertEqual(
-            [s.stack_name for s in res],
-            stack_list
-        )
+        self.check_slist(['test1', 'test2', 'test3', 'ns1', 'ns2'])
+
+    @mock.patch('awstools.utils.cloudformation.boto.connect_cloudformation')
+    def test_find_stacks_valid_all(self, mock_conn_cfn):
+        from awstools.utils import cloudformation
+
+        l_s = mock_conn_cfn.return_value.list_stacks
+        l_s.side_effect = [self.teststacks1, self.teststacks2]
+
+        self.result = cloudformation.find_stacks(findall=True)
+
+        l_s.assert_has_calls([mock.call(next_token=None),
+                              mock.call(next_token='tok')])
+
+        self.check_slist(['test1', 'test2', 'test3', 'ns1', 'ns2', 'deleted'])
+
+    @mock.patch('awstools.utils.cloudformation.boto.connect_cloudformation')
+    def test_find_stacks_pattern(self, mock_conn_cfn):
+        from awstools.utils import cloudformation
+
+        l_s = mock_conn_cfn.return_value.list_stacks
+        l_s.side_effect = [self.teststacks1, self.teststacks2]
+
+        self.result = cloudformation.find_stacks(pattern='ns')
+
+        l_s.assert_has_calls([mock.call(next_token=None),
+                              mock.call(next_token='tok')])
+
+        self.check_slist(['ns1', 'ns2'])

File setup.py

View file
 from setuptools import setup, find_packages
 import codecs
 
-version = '0.3.5.dev0'
+version = '0.3.5.dev2'
 
 
 def read(filename):