Skip to content
This repository
Browse code

Adding some unit tests. More to come

  • Loading branch information...
commit 050f7f1b73c12f1980c32bec192c1d59c4167b19 1 parent b9c3ee4
Brian K. Jones authored February 28, 2012

Showing 1 changed file with 41 additions and 0 deletions. Show diff stats Hide diff stats

  1. 41  test.py
41  test.py
... ...
@@ -0,0 +1,41 @@
  1
+#!/usr/bin/env python
  2
+
  3
+__author__ = 'Brian K. Jones'
  4
+__email__ = 'bkjones@gmail.com'
  5
+
  6
+import unittest2 as unittest
  7
+from mock import Mock, patch, patch_object
  8
+from cmd import Cmd
  9
+from StringIO import StringIO
  10
+from bunnyq import Bunny
  11
+
  12
+class TestBunny(unittest.TestCase):
  13
+    def setUp(self):
  14
+        Bunny.request = Mock()
  15
+        Bunny.do_connect = Mock(return_value=True)
  16
+        self.b = Bunny('foo', 9090, 'guest', 'guest')
  17
+
  18
+    def test_instance(self):
  19
+        host = 'foo.bar'
  20
+        port = 9090
  21
+        user = 'guest'
  22
+        password = 'guest'
  23
+        b = Bunny(host, port, user, password)
  24
+        self.assertIsInstance(b, Bunny)
  25
+        self.assertIsInstance(b, Cmd)
  26
+
  27
+    def test_list_vhost(self):
  28
+        self.b.request.return_value = [{'name': 'v1', 'foo': 'bar'},
  29
+                                     {'name': 'v2', 'baz': 'quux'}]
  30
+        sout = StringIO()
  31
+        expected_out = "v1\nv2\n"
  32
+        with patch('sys.stdout', new=sout) as out:
  33
+            self.b.do_list_vhosts(None)
  34
+            self.assertEqual(expected_out, out.getvalue())
  35
+
  36
+
  37
+
  38
+
  39
+
  40
+
  41
+

0 notes on commit 050f7f1

Please sign in to comment.
Something went wrong with that request. Please try again.