]> git.aero2k.de Git - sirius.git/commitdiff
Move testing base into a separate testing directory.
authorTom Hunger <tehunger@gmail.com>
Mon, 26 Jan 2015 15:31:15 +0000 (15:31 +0000)
committerTom Hunger <tehunger@gmail.com>
Mon, 26 Jan 2015 15:31:15 +0000 (15:31 +0000)
sirius/testing/__init__.py [new file with mode: 0644]
sirius/testing/base.py [new file with mode: 0644]
sirius/web/test_claiming.py

diff --git a/sirius/testing/__init__.py b/sirius/testing/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sirius/testing/base.py b/sirius/testing/base.py
new file mode 100644 (file)
index 0000000..46fa64e
--- /dev/null
@@ -0,0 +1,39 @@
+from flask.ext import testing
+from flask.ext import login
+
+from sirius.models import user
+from sirius.models import hardware
+from sirius.models.db import db
+from sirius.web import webapp
+
+
+class Base(testing.TestCase):
+    """Common base class for tests that require database interactions.
+    """
+
+    def create_app(self):
+        app = webapp.create_app('test')
+        return app
+
+    def setUp(self):
+        testing.TestCase.setUp(self)
+        db.create_all()
+        self.testuser = user.User(username="testuser")
+        db.session.add(self.testuser)
+        db.session.commit()
+
+    def tearDown(self):
+        db.session.remove()
+        db.drop_all()
+
+    def autologin(self):
+        # Most disgusting hack but I see no other way to log in users:
+        # Flask session doesn't pick up the cookies if I call just
+        # login_user. The login_user call needs to be embedded in a
+        # request.
+        @self.app.route('/autologin')
+        def autologin():
+            login.login_user(self.testuser)
+            return ''
+
+        self.client.get('/autologin')
index 790ffc0913513fc181e0b6f3ad15b4bf65c78152..5d3bae29e4ee90d6929e6b147bbacede8bfe5b89 100644 (file)
@@ -1,44 +1,13 @@
 import flask
-from flask.ext import testing
 from flask.ext import login
 
 from sirius.models import user
 from sirius.models import hardware
 from sirius.models.db import db
 from sirius.web import webapp
+from sirius.testing import base
 
-
-class Base(testing.TestCase):
-
-    def create_app(self):
-        app = webapp.create_app('test')
-        return app
-
-    def setUp(self):
-        testing.TestCase.setUp(self)
-        db.create_all()
-        self.testuser = user.User(username="testuser")
-        db.session.add(self.testuser)
-        db.session.commit()
-
-    def tearDown(self):
-        db.session.remove()
-        db.drop_all()
-
-    def autologin(self):
-        # Most disgusting hack but I see no other way to log in users:
-        # Flask session doesn't pick up the cookies if I call just
-        # login_user. The login_user call needs to be embedded in a
-        # request.
-        @self.app.route('/autologin')
-        def autologin():
-            login.login_user(self.testuser)
-            return ''
-
-        self.client.get('/autologin')
-
-
-class TestClaiming(Base):
+class TestClaiming(base.Base):
 
     def test_claim_first(self):
         self.testuser.claim_printer('n5ry-p6x6-kth7-7hc4', 'my test printer')
@@ -72,7 +41,7 @@ class TestClaiming(Base):
         self.assertEqual(printer.owner, self.testuser2)
 
 
-class TestClaimingWeb(Base):
+class TestClaimingWeb(base.Base):
 
     def get_claim_url(self):
         return flask.url_for(