Erosen has submitted this change and it was merged.

Change subject: fixes tests which require logging in
......................................................................


fixes tests which require logging in

Change-Id: I1b8274cb885716f1eabb18f1598349ad5a00bcfe
---
M tests/fixtures.py
M tests/test_controllers/test_metrics.py
M wikimetrics/controllers/authentication.py
3 files changed, 29 insertions(+), 12 deletions(-)

Approvals:
  Erosen: Verified; Looks good to me, approved



diff --git a/tests/fixtures.py b/tests/fixtures.py
index 4a575cf..55f3f7e 100644
--- a/tests/fixtures.py
+++ b/tests/fixtures.py
@@ -20,8 +20,10 @@
     
     def setUp(self):
         
+        
         # create basic test records for non-mediawiki tests
         self.session = db.get_session()
+        self.mwSession = db.get_mw_session('enwiki')
         
         job = Job()
         user = User(username='Dan')
@@ -49,7 +51,6 @@
         self.session.commit()
         
         # create records for enwiki tests
-        self.mwSession = db.get_mw_session('enwiki')
         self.mwSession.add(MediawikiUser(user_id=1, user_name='Dan'))
         self.mwSession.add(MediawikiUser(user_id=2, user_name='Evan'))
         self.mwSession.add(MediawikiUser(user_id=3, user_name='Andrew'))
@@ -110,14 +111,14 @@
     so that any private routes are still served for testing purposes.
     """
     
-    @classmethod
-    def setUpClass(cls):
+    def setUp(self):
         """
         Creates a test flask environment.  Logs in a test user so tests on 
private urls work.
         """
-        cls.app = app.test_client()
-        cls.app.get('/login-for-testing-only')
+        DatabaseTest.setUp(self)
+        self.app = app.test_client()
+        self.app.get('/login-for-testing-only')
     
-    @classmethod
-    def tearDownClass(cls):
-        cls.app.get('/logout')
+    def tearDown(self):
+        DatabaseTest.tearDown(self)
+        self.app.get('/logout')
diff --git a/tests/test_controllers/test_metrics.py 
b/tests/test_controllers/test_metrics.py
index 9642f11..fd2914e 100644
--- a/tests/test_controllers/test_metrics.py
+++ b/tests/test_controllers/test_metrics.py
@@ -12,6 +12,12 @@
             '/metrics should return OK'
         )
         assert_equal(
+            response.data,
+            """[('Metric', <class 'wikimetrics.metrics.metric.Metric'>), 
('NamespaceEdits', <class 
'wikimetrics.metrics.namespace_edits.NamespaceEdits'>), ('RandomMetric', <class 
'wikimetrics.metrics.dummy.RandomMetric'>), ('RevertRate', <class 
'wikimetrics.metrics.revert_rate.RevertRate'>)]""",
+            '/metrics should get this temporary, raw list of available 
metrics, response.data:\n{0}'\
+                .format(response.data)
+        )
+        assert_equal(
             response.data.find('log in with Google'),
             -1,
             '/metrics should get the list of metrics'
diff --git a/wikimetrics/controllers/authentication.py 
b/wikimetrics/controllers/authentication.py
index 2e0311c..d0227c9 100644
--- a/wikimetrics/controllers/authentication.py
+++ b/wikimetrics/controllers/authentication.py
@@ -30,13 +30,21 @@
 if app.config['DEBUG']:
     # safeguard against exposing this route in production
     @app.route('/login-for-testing-only')
+    @is_public
     def login_for_testing_only():
         if app.config['DEBUG']:
-            user = User(
-                id=2,
-                email='[email protected]',
-            )
+            db_session = db.get_session()
+            user = db_session.query(User).get(2)
+            if user is None: 
+                user = User(
+                    id=2,
+                    email='[email protected]',
+                )
+                db_session.add(user)
+                db_session.commit()
+            user.login(db_session) 
             login_user(user)
+            return ''
 
 
 @app.before_request
@@ -48,6 +56,8 @@
     if current_user.is_authenticated():
         return
     
+    # TODO: look into more systematic way of finding whether
+    # request is to status resource
     if (request.endpoint and
         not 'static' in request.endpoint and
         not getattr(app.view_functions[request.endpoint], 'is_public', False)

-- 
To view, visit https://gerrit.wikimedia.org/r/70220
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1b8274cb885716f1eabb18f1598349ad5a00bcfe
Gerrit-PatchSet: 1
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: Erosen <[email protected]>
Gerrit-Reviewer: Erosen <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to