Pior Bastida avatar Pior Bastida committed b2ad85d

added partial unittest for awstools.find_stacks

Comments (0)

Files changed (1)

awstools/tests/unittests/test_awstools.py

+# -*- coding: utf-8 -*-
+# Copyright (C) 2012 Ludia Inc.
+# This software is licensed as described in the file LICENSE, which
+# you should have received as part of this distribution.
+# Author: Pior Bastida <pbastida@socialludia.com>
+
+import unittest
+
+import mock
+# import boto
+
+import awstools
+
+
+class Stack(object):
+    def __init__(self,
+                 name="test",
+                 status="CREATE_COMPLETE",
+                 ):
+        self.stack_name = name
+        self.stack_status = status
+
+
+class StackList(list):
+    def __init__(self, l=[], next_token=None):
+        self.extend(l)
+        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 test_find_stacks_valid(self, mock_conn_cfn):
+        mock_cfn = mock.MagicMock()
+        mock_cfn.list_stacks.side_effect = [
+            teststacks1,
+            teststacks2,
+            ]
+        mock_conn_cfn.return_value = mock_cfn
+
+        res = awstools.find_stacks()
+
+        self.assertEqual(mock_cfn.list_stacks.mock_calls,
+                         [mock.call(next_token=None),
+                          mock.call(next_token='tok')]
+                        )
+
+        self.assertEqual(
+            [s.stack_name for s in res],
+            stack_list
+            )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.