Milimetric has uploaded a new change for review.
https://gerrit.wikimedia.org/r/71943
Change subject: a bit more testing added for job request
......................................................................
a bit more testing added for job request
Change-Id: Icdb08aa3055bc06e992040c431b7fd882f328d57
---
M tests/fixtures.py
M tests/test_controllers/test_cohorts.py
A tests/test_controllers/test_demo.py
M tests/test_controllers/test_metrics.py
A tests/test_utils/test_configuration.py
M wikimetrics/controllers/authentication.py
M wikimetrics/controllers/jobs.py
M wikimetrics/metrics/bytes_added.py
M wikimetrics/models/user.py
A wikimetrics/static/js/jobList.js
M wikimetrics/templates/jobs.html
D wikimetrics/templates/queue.html
12 files changed, 138 insertions(+), 47 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics
refs/changes/43/71943/1
diff --git a/tests/fixtures.py b/tests/fixtures.py
index 682a927..84ca38d 100644
--- a/tests/fixtures.py
+++ b/tests/fixtures.py
@@ -34,10 +34,13 @@
# create basic test records for non-mediawiki tests
self.session = db.get_session()
+ self.mwSession = db.get_mw_session('enwiki')
+ DatabaseTest.tearDown(self)
job = Job()
dan_user = User(username='Dan')
evan_user = User(username='Evan')
+ web_test_user = User(email='[email protected]')
# create a test cohort
dan = WikiUser(mediawiki_username='Dan', mediawiki_userid=1,
project='enwiki')
@@ -54,6 +57,7 @@
job,
dan_user,
evan_user,
+ web_test_user,
dan,
evan,
andrew,
@@ -93,8 +97,18 @@
cohort_id=private_cohort2.id,
role=CohortUserRole.OWNER,
)
+ web_user_owns_private = CohortUser(
+ user_id=web_test_user.id,
+ cohort_id=private_cohort.id,
+ role=CohortUserRole.OWNER,
+ )
+ web_user_owns_private2 = CohortUser(
+ user_id=web_test_user.id,
+ cohort_id=private_cohort2.id,
+ role=CohortUserRole.OWNER,
+ )
dan_views_private2 = CohortUser(
- user_id=evan_user.id,
+ user_id=dan_user.id,
cohort_id=private_cohort2.id,
role=CohortUserRole.VIEWER
)
@@ -102,15 +116,17 @@
dan_owns_test,
evan_owns_private,
evan_owns_private2,
+ web_user_owns_private,
+ web_user_owns_private2,
dan_views_private2
])
self.session.commit()
# add jobs
- job_created = Job(user_id=2, classpath='', status=JobStatus.CREATED,
result_id=None)
- job_started = Job(user_id=2, classpath='', status=JobStatus.STARTED,
result_id=None)
- job_started2 = Job(user_id=2, classpath='', status=JobStatus.STARTED,
result_id=None)
- job_finished = Job(user_id=2, classpath='', status=JobStatus.FINISHED,
result_id=None)
+ job_created = Job(user_id=web_test_user.id, classpath='',
status=JobStatus.CREATED, result_id=None)
+ job_started = Job(user_id=web_test_user.id, classpath='',
status=JobStatus.STARTED, result_id=None)
+ job_started2 = Job(user_id=web_test_user.id, classpath='',
status=JobStatus.STARTED, result_id=None)
+ job_finished = Job(user_id=web_test_user.id, classpath='',
status=JobStatus.FINISHED, result_id=None)
self.session.add_all([
job_created,
job_started,
@@ -118,8 +134,6 @@
job_finished
])
self.session.commit()
-
- self.mwSession = db.get_mw_session('enwiki')
# create records for enwiki tests
self.mwSession.add(MediawikiUser(user_id=1, user_name='Dan'))
@@ -145,7 +159,6 @@
self.mwSession.query(Revision).delete()
self.mwSession.commit()
- self.session = db.get_session()
self.session.query(CohortWikiUser).delete()
self.session.query(CohortUser).delete()
self.session.query(WikiUser).delete()
diff --git a/tests/test_controllers/test_cohorts.py
b/tests/test_controllers/test_cohorts.py
index 51bd0e4..a983f24 100644
--- a/tests/test_controllers/test_cohorts.py
+++ b/tests/test_controllers/test_cohorts.py
@@ -9,7 +9,7 @@
def test_index(self):
response = self.app.get('/cohorts/', follow_redirects=True)
assert_equal(
- response._status_code, 200,
+ response.status_code, 200,
'/cohorts should get the list of cohorts'
)
diff --git a/tests/test_controllers/test_demo.py
b/tests/test_controllers/test_demo.py
new file mode 100644
index 0000000..df8d7e4
--- /dev/null
+++ b/tests/test_controllers/test_demo.py
@@ -0,0 +1,28 @@
+from nose.tools import assert_equal
+from tests.fixtures import WebTest
+import json
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class TestDemoController(WebTest):
+
+ def test_run_task_in_celery(self):
+ response = self.app.get('/demo/metric/random/1')
+ print response.data
+ assert_equal(
+ response.status_code, 200,
+ '/demo/metric/random/<cohort-id>/ exists and is OK to GET'
+ )
+
+ def test_add_demo_cohorts(self):
+ response = self.app.get('/demo/create/cohorts/')
+ assert_equal(
+ response.status_code, 200,
+ '/demo/create/cohorts/ exists and is OK to GET'
+ )
+ assert_equal(
+ response.data, 'OK, wiped out the database and added cohorts only
for [email protected]',
+ '/demo/create/cohorts/ completes successfully'
+ )
diff --git a/tests/test_controllers/test_metrics.py
b/tests/test_controllers/test_metrics.py
index d7ba31c..02d20e3 100644
--- a/tests/test_controllers/test_metrics.py
+++ b/tests/test_controllers/test_metrics.py
@@ -1,5 +1,5 @@
import json
-from nose.tools import assert_equal, assert_true
+from nose.tools import assert_equal, assert_not_equal, assert_true
from tests.fixtures import WebTest
@@ -32,3 +32,21 @@
1,
'test. got: {0}'.format(parsed)
)
+
+ def test_configure_get(self):
+ response = self.app.get('/metrics/configure/BytesAdded')
+ assert_not_equal(
+ response.data.find('name="positive_total"'),
+ -1,
+ 'A form to configure a BytesAdded metric was not rendered'
+ )
+
+ def test_configure_post(self):
+ response = self.app.post('/metrics/configure/BytesAdded', data=dict(
+ start_date='hi'
+ ))
+ assert_not_equal(
+ response.data.find('<li class="text-error">Not a valid date
value</li>'),
+ -1,
+ 'Validation on a BytesAdded configuration is not happening'
+ )
diff --git a/tests/test_utils/test_configuration.py
b/tests/test_utils/test_configuration.py
new file mode 100644
index 0000000..26f977f
--- /dev/null
+++ b/tests/test_utils/test_configuration.py
@@ -0,0 +1,23 @@
+import io
+import os
+import unittest
+from nose.tools import assert_equals
+from wikimetrics.configurables import create_object_from_config_file
+
+
+class ConfigurationTest(unittest.TestCase):
+
+ TEST_CONFIG = 'wikimetrics_test_configuration_file.py'
+
+ def setUp(self):
+ f = io.open(self.TEST_CONFIG, 'w')
+ f.write(u'TEST_SETTING=2')
+ f.close()
+
+ def tearDown(self):
+ os.remove(self.TEST_CONFIG)
+
+ def test_create_object_from_config_file(self):
+ obj = create_object_from_config_file(self.TEST_CONFIG)
+
+ assert_equals(obj.TEST_SETTING, 2, 'The configuration file was not
read properly')
diff --git a/wikimetrics/controllers/authentication.py
b/wikimetrics/controllers/authentication.py
index 797956b..2bf931f 100644
--- a/wikimetrics/controllers/authentication.py
+++ b/wikimetrics/controllers/authentication.py
@@ -26,26 +26,6 @@
return decorator(to_decorate)
-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']:
- 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
def default_to_private():
"""
@@ -177,3 +157,16 @@
Callback for Twitter to send us authentication results.
"""
return 'Not Implemented Yet'
+
+
+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']:
+ db_session = db.get_session()
+ user =
db_session.query(User).filter_by(email='[email protected]').one()
+ user.login(db_session)
+ login_user(user)
+ return ''
diff --git a/wikimetrics/controllers/jobs.py b/wikimetrics/controllers/jobs.py
index a96a962..4becd06 100644
--- a/wikimetrics/controllers/jobs.py
+++ b/wikimetrics/controllers/jobs.py
@@ -12,7 +12,7 @@
Renders a page with a list of jobs started by the currently logged in user.
If the user is an admin, she has the option to see other users' jobs.
"""
- return 'jobs'
+ return render_template('jobs.html')
@app.route('/jobs/create/', methods=['GET', 'POST'])
@@ -23,7 +23,8 @@
if request.method == 'GET':
return render_template('request.html')
else:
- print request.form['responses']
+ # TODO: validate the different metrics in request.form
+ # TODO: create a JobResponse using responses=request.form['responses']
return render_template('jobs.html')
diff --git a/wikimetrics/metrics/bytes_added.py
b/wikimetrics/metrics/bytes_added.py
index f488b0a..f655e3c 100644
--- a/wikimetrics/metrics/bytes_added.py
+++ b/wikimetrics/metrics/bytes_added.py
@@ -10,8 +10,10 @@
def better_bool(value):
if type(value) is bool:
return value
- elif type(value) is list:
+ elif type(value) is list and len(value) > 0:
value = value[0]
+ else:
+ return False
return str(value).strip().lower() in ['yes', 'y', 'true']
diff --git a/wikimetrics/models/user.py b/wikimetrics/models/user.py
index d628e48..d4c470c 100644
--- a/wikimetrics/models/user.py
+++ b/wikimetrics/models/user.py
@@ -9,8 +9,7 @@
class UserRole(object):
ADMIN = 'ADMIN'
- USER_WITH_NDA = 'USER_WITH_NDA'
- USER_WITHOUT_NDA = 'USER_WITHOUT_NDA'
+ USER = 'USER'
GUEST = 'GUEST'
diff --git a/wikimetrics/static/js/jobList.js b/wikimetrics/static/js/jobList.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/wikimetrics/static/js/jobList.js
diff --git a/wikimetrics/templates/jobs.html b/wikimetrics/templates/jobs.html
index e69de29..cec19b1 100644
--- a/wikimetrics/templates/jobs.html
+++ b/wikimetrics/templates/jobs.html
@@ -0,0 +1,26 @@
+{% extends "layout.html" %}
+{% block body %}
+<h2>Job queue</h2>
+<table class="table table-striped">
+ <thead>
+ <tr>
+ <th>Started</th>
+ <th>Name</th>
+ <th>Detail</th>
+ </tr>
+ </thead>
+ <tbody data-bind="foreach: jobs">
+ <tr>
+ <td data-bind="text: started"></td>
+ <td data-bind="text: name"></td>
+ <td>...</td>
+ </tr>
+ </tbody>
+</table>
+
+{% endblock %}
+
+{% block scripts %}
+<script src="//ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js"></script>
+<script src="{{ url_for('static', filename='js/jobList.js') }}"></script>
+{% endblock %}
diff --git a/wikimetrics/templates/queue.html b/wikimetrics/templates/queue.html
deleted file mode 100644
index 35c5aa2..0000000
--- a/wikimetrics/templates/queue.html
+++ /dev/null
@@ -1,12 +0,0 @@
-{% extends "layout.html" %}
-{% block body %}
-<h2>Job queue</h2>
-{% if error %}<p class="text-warning"><strong>Warning:</strong> {{ error
}}</p>{% endif %}
-<table class="table table-striped">
- {% for job in procs %}
- {{ job|safe }}
- {% endfor %}
-</table>
-
-Back to <a href="{{ url_for('all_cohorts') }}">Cohorts</a>.
-{% endblock %}
--
To view, visit https://gerrit.wikimedia.org/r/71943
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icdb08aa3055bc06e992040c431b7fd882f328d57
Gerrit-PatchSet: 1
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: Milimetric <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits