Add Tests for testing the statuspage, extend the PostgreSQL test to return a wider result.

This commit is contained in:
Feike Steenbergen
2015-05-21 13:56:08 +02:00
parent c05453cc98
commit 7afba469b4
2 changed files with 55 additions and 2 deletions
+2 -2
View File
@@ -37,9 +37,9 @@ class MockCursor:
elif sql.startswith('SELECT pg_last_xlog_replay_location()'):
self.results = [(0,)]
elif sql.startswith('SELECT pg_is_in_recovery()'):
self.results = [(False, )]
self.results = [(False, None, None, None, None, None, None, None, None, None)]
else:
self.results = []
self.results = [(None, None, None, None, None, None, None, None, None, None)]
def fetchone(self):
return self.results[0]
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from helpers.statuspage import StatusPage
from test_postgresql import MockConnect
from StringIO import StringIO as IO
class TestStatusPage(unittest.TestCase):
def __init__(self, method_name='runTest'):
self.setUp = self.set_up
self.tearDown = self.tear_down
super(TestStatusPage, self).__init__(method_name)
def set_up(self):
pass
def tear_down(self):
pass
def test_statuspage_main(self):
pass
def test_statuspage_initialize(self):
pass
def test_do_GET(self):
self.http_server = MockServer(('0.0.0.0', 8888), StatusPage, '/pg_master')
self.http_server = MockServer(('0.0.0.0', 8888), StatusPage, '/pg_slave')
self.http_server = MockServer(('0.0.0.0', 8888), StatusPage, '/pg_status')
self.http_server = MockServer(('0.0.0.0', 8888), StatusPage, '/not_found')
class MockRequest(object):
def __init__(self, path):
self.path = path
def makefile(self, *args, **kwargs):
return IO(b"GET " + self.path)
class MockServer(object):
def __init__(self, ip_port, Handler, path):
self.postgresql = MockConnect()
Handler(MockRequest(path), ip_port, self)
if __name__ == '__main__':
unittest.main()