From 34a28f76114faa9ce1b44ce4d6c82704eb6b6b74 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Sat, 15 Sep 2012 10:00:13 +0200 Subject: [PATCH] Add tests structure --- tests/__init__.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++ tests/test_base.py | 34 +++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_base.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..88f62cd4 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# +# This file is part of Radicale Server - Calendar Server +# Copyright © 2012 Guillaume Ayoub +# +# This library is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Radicale. If not, see . + +""" +Tests for Radicale. + +""" + +import os +import sys + +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) + +import radicale + + +class BaseTest(object): + """Base class for tests.""" + + def setup(self): + """Setup function for each test.""" + self.application = radicale.Application() + + def teardown(self): + """Teardown function for each test.""" + + def request(self, method, path, **args): + """Send a request.""" + self.application._status = None + self.application._headers = None + self.application._answer = None + + for key in args: + args[key.upper()] = args[key] + args["REQUEST_METHOD"] = method.upper() + args["PATH_INFO"] = path + self.application._answer = self.application(args, self.start_response) + + return ( + int(self.application._status.split()[0]), + dict(self.application._headers), + self.application._answer[0].decode("utf-8")) + + def start_response(self, status, headers): + """Put the response values into the current application.""" + self.application._status = status + self.application._headers = headers diff --git a/tests/test_base.py b/tests/test_base.py new file mode 100644 index 00000000..10adbd58 --- /dev/null +++ b/tests/test_base.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# +# This file is part of Radicale Server - Calendar Server +# Copyright © 2012 Guillaume Ayoub +# +# This library is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Radicale. If not, see . + +""" +Radicale tests with simple requests. + +""" + +from . import BaseTest + + +class TestBaseRequests(BaseTest): + """Tests with simple requests.""" + + def test_root(self): + """Test a GET request at "/".""" + status, headers, answer = self.request("GET", "/") + assert status == 200 + assert "Radicale works!" in answer