From 7afba469b437980f16fac73d943a2c315dabc05e Mon Sep 17 00:00:00 2001 From: Feike Steenbergen Date: Thu, 21 May 2015 13:56:08 +0200 Subject: [PATCH] Add Tests for testing the statuspage, extend the PostgreSQL test to return a wider result. --- tests/test_postgresql.py | 4 +-- tests/test_statuspage.py | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/test_statuspage.py diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 7fa5dcf7..1ee6d890 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -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] diff --git a/tests/test_statuspage.py b/tests/test_statuspage.py new file mode 100644 index 00000000..7039ccc6 --- /dev/null +++ b/tests/test_statuspage.py @@ -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()