Skip to content
This repository
Browse code

Add tests structure

  • Loading branch information...
commit 34a28f76114faa9ce1b44ce4d6c82704eb6b6b74 1 parent 4fbd087
Guillaume Ayoub authored
62  tests/__init__.py
... ...
@@ -0,0 +1,62 @@
  1
+# -*- coding: utf-8 -*-
  2
+#
  3
+# This file is part of Radicale Server - Calendar Server
  4
+# Copyright © 2012 Guillaume Ayoub
  5
+#
  6
+# This library is free software: you can redistribute it and/or modify
  7
+# it under the terms of the GNU General Public License as published by
  8
+# the Free Software Foundation, either version 3 of the License, or
  9
+# (at your option) any later version.
  10
+#
  11
+# This library is distributed in the hope that it will be useful,
  12
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14
+# GNU General Public License for more details.
  15
+#
  16
+# You should have received a copy of the GNU General Public License
  17
+# along with Radicale.  If not, see <http://www.gnu.org/licenses/>.
  18
+
  19
+"""
  20
+Tests for Radicale.
  21
+
  22
+"""
  23
+
  24
+import os
  25
+import sys
  26
+
  27
+sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
  28
+
  29
+import radicale
  30
+
  31
+
  32
+class BaseTest(object):
  33
+    """Base class for tests."""
  34
+
  35
+    def setup(self):
  36
+        """Setup function for each test."""
  37
+        self.application = radicale.Application()
  38
+
  39
+    def teardown(self):
  40
+        """Teardown function for each test."""
  41
+
  42
+    def request(self, method, path, **args):
  43
+        """Send a request."""
  44
+        self.application._status = None
  45
+        self.application._headers = None
  46
+        self.application._answer = None
  47
+
  48
+        for key in args:
  49
+            args[key.upper()] = args[key]
  50
+        args["REQUEST_METHOD"] = method.upper()
  51
+        args["PATH_INFO"] = path
  52
+        self.application._answer = self.application(args, self.start_response)
  53
+
  54
+        return (
  55
+            int(self.application._status.split()[0]),
  56
+            dict(self.application._headers),
  57
+            self.application._answer[0].decode("utf-8"))
  58
+
  59
+    def start_response(self, status, headers):
  60
+        """Put the response values into the current application."""
  61
+        self.application._status = status
  62
+        self.application._headers = headers
34  tests/test_base.py
... ...
@@ -0,0 +1,34 @@
  1
+# -*- coding: utf-8 -*-
  2
+#
  3
+# This file is part of Radicale Server - Calendar Server
  4
+# Copyright © 2012 Guillaume Ayoub
  5
+#
  6
+# This library is free software: you can redistribute it and/or modify
  7
+# it under the terms of the GNU General Public License as published by
  8
+# the Free Software Foundation, either version 3 of the License, or
  9
+# (at your option) any later version.
  10
+#
  11
+# This library is distributed in the hope that it will be useful,
  12
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14
+# GNU General Public License for more details.
  15
+#
  16
+# You should have received a copy of the GNU General Public License
  17
+# along with Radicale.  If not, see <http://www.gnu.org/licenses/>.
  18
+
  19
+"""
  20
+Radicale tests with simple requests.
  21
+
  22
+"""
  23
+
  24
+from . import BaseTest
  25
+
  26
+
  27
+class TestBaseRequests(BaseTest):
  28
+    """Tests with simple requests."""
  29
+
  30
+    def test_root(self):
  31
+        """Test a GET request at "/"."""
  32
+        status, headers, answer = self.request("GET", "/")
  33
+        assert status == 200
  34
+        assert "Radicale works!" in answer

0 notes on commit 34a28f7

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