Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #8 from ashcrow/fixup-tests
Browse files Browse the repository at this point in the history
test: Clean up tests.
  • Loading branch information
themurph committed Jan 22, 2016
2 parents b006654 + fba9f55 commit 058589b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 27 deletions.
4 changes: 2 additions & 2 deletions test/test_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Test cases for the commissaire.authentication.httpauth module.
Test cases for the commissaire.authentication module.
"""

import falcon
Expand All @@ -28,7 +28,7 @@ class Test_Authenticator(TestCase):
Tests for the Authenticator class.
"""

def setUp(self):
def before(self):
"""
Sets up a fresh instance of the class before each run.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def test_authenticate_with_invalid_user(self):
"""
Verify authenticate denies with a proper JSON file, Authorization header, and no matching user.
"""
self.http_basic_auth_by_file = httpauth.HTTPBasicAuthByFile('./conf/users.json')
self.http_basic_auth_by_file = httpauth.HTTPBasicAuthByFile(
'./conf/users.json')
req = falcon.Request(
create_environ(headers={'Authorization': 'basic Yjpi'}))
resp = falcon.Response()
Expand All @@ -121,6 +122,7 @@ def test_authenticate_with_invalid_user(self):
self.http_basic_auth_by_file.authenticate,
req, resp)


class TestHTTPBasicAuthByEtcd(TestCase):
"""
Tests for the HTTPBasicAuthByEtcd class.
Expand Down
11 changes: 4 additions & 7 deletions test/test_handlers_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
import falcon

from . import TestCase
from falcon.testing.helpers import create_environ
from mock import MagicMock
from commissaire.handlers import clusters
from commissaire.script import create_app
from commissaire.middleware import JSONify


Expand Down Expand Up @@ -85,7 +83,7 @@ def before(self):

def test_clusters_listing(self):
"""
Verify listing clusters.
Verify listing Clusters.
"""
child = MagicMock(value=self.acluster)
self.return_value._children = [child]
Expand All @@ -99,11 +97,10 @@ def test_clusters_listing(self):
[json.loads(self.acluster)],
json.loads(body[0]))

def test_clusters_listing_with_no_hosts(self):
def test_clusters_listing_with_no_clusters(self):
"""
Verify listing clusters.
Verify listing Clusters when no clusters exist.
"""
child = MagicMock(value=self.acluster)
self.return_value._children = []
self.return_value.leaves = self.return_value._children

Expand All @@ -115,7 +112,7 @@ def test_clusters_listing_with_no_hosts(self):

def test_clusters_listing_with_no_etcd_result(self):
"""
Verify listing clusters handles no etcd result properly.
Verify listing Clusters handles no etcd result properly.
"""
self.datasource.get.side_effect = etcd.EtcdKeyNotFound

Expand Down
17 changes: 7 additions & 10 deletions test/test_handlers_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Test cases for the commissaire.authentication.httpauth module.
Test cases for the commissaire.handlers.hosts module.
"""

import json
Expand All @@ -22,10 +22,8 @@
import falcon

from . import TestCase
from falcon.testing.helpers import create_environ
from mock import MagicMock
from commissaire.handlers import hosts
from commissaire.script import create_app
from commissaire.middleware import JSONify


Expand All @@ -36,7 +34,7 @@ class Test_Hosts(TestCase):

def test_hosts_creation(self):
"""
Verify hosts model
Verify Hosts model.
"""
# Make sure hosts is required
self.assertRaises(
Expand Down Expand Up @@ -95,7 +93,7 @@ def before(self):

def test_hosts_listing(self):
"""
Verify listing hosts.
Verify listing Hosts.
"""
child = MagicMock(value=self.etcd_host)
self.return_value._children = [child]
Expand All @@ -111,9 +109,8 @@ def test_hosts_listing(self):

def test_hosts_listing_with_no_hosts(self):
"""
Verify listing hosts.
Verify listing Hosts when no hosts exists.
"""
child = MagicMock(value=self.ahost)
self.return_value._children = []
self.return_value.leaves = self.return_value._children

Expand Down Expand Up @@ -195,7 +192,7 @@ def before(self):

def test_host_retrieve(self):
"""
Verify retrieving a host.
Verify retrieving a Host.
"""
# Verify if the host exists the data is returned
self.return_value.value = self.etcd_host
Expand All @@ -219,7 +216,7 @@ def test_host_retrieve(self):

def test_host_delete(self):
"""
Verify deleting a host.
Verify deleting a Host.
"""
# Verify deleting of an existing host works
body = self.simulate_request('/api/v0/host/10.2.0.2', method='DELETE')
Expand All @@ -238,7 +235,7 @@ def test_host_delete(self):

def test_host_create(self):
"""
Verify creation of a host.
Verify creation of a Host.
"""
self.datasource.get.side_effect = etcd.EtcdKeyNotFound
self.return_value.value = self.etcd_host
Expand Down
5 changes: 2 additions & 3 deletions test/test_handlers_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Test cases for the commissaire.handlers.clusters module.
Test cases for the commissaire.handlers.status module.
"""

import json
Expand Down Expand Up @@ -66,7 +66,7 @@ def before(self):

def test_status_retrieve(self):
"""
Verify retrieving status.
Verify retrieving Status.
"""
child = MagicMock(value='')
self.return_value._children = [child]
Expand All @@ -81,7 +81,6 @@ def test_status_retrieve(self):
# datasource's get should have been called once
self.assertEquals(1, self.datasource.get.call_count)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
print json.loads(body[0])
self.assertEqual(
json.loads(self.astatus),
json.loads(body[0]))
4 changes: 2 additions & 2 deletions test/test_jobs_investigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Test cases for the commissaire.authentication.httpauth module.
Test cases for the commissaire.jobs.investigator module.
"""

import etcd
Expand All @@ -37,7 +37,7 @@ class Test_JobsInvestigator(TestCase):

def test_investigator(self):
"""
Verify investigator ....
Verify the investigator.
"""
with mock.patch('commissaire.transport.ansibleapi.Transport') as _tp:
_tp().get_info.return_value = (
Expand Down
4 changes: 2 additions & 2 deletions test/test_transport_ansibleapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Test_LogForward(TestCase):
Tests for the LogForward class.
"""

def setUp(self):
def before(self):
"""
Sets up a fresh instance of the class before each run.
"""
Expand Down Expand Up @@ -87,7 +87,7 @@ class Test_Transport(TestCase):

def test_get_info(self):
"""
Verify get_info works as expected.
Verify Transport().get_info works as expected.
"""
with patch('commissaire.transport.ansibleapi.TaskQueueManager') as _tqm:
_tqm().run.return_value = 0
Expand Down

0 comments on commit 058589b

Please sign in to comment.