Mforns has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/180071

Change subject: Strip project when uploading cohort
......................................................................

Strip project when uploading cohort

When a cohort is uploaded with blank space between the comma
that separates the username and the project, and the project
itself; centralauth service is not capable of unifying i.e.
'enwiki' and ' enwiki' and this causes a validation error.

This fix adresses that problem and adds a test for the
specific case.

Bug: T78584
Change-Id: I301b8c2cafbf4de98b2fd2c2ead9cd74b254f32f
---
M tests/test_controllers/test_cohort_upload.py
M wikimetrics/forms/cohort_upload.py
2 files changed, 12 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics 
refs/changes/71/180071/1

diff --git a/tests/test_controllers/test_cohort_upload.py 
b/tests/test_controllers/test_cohort_upload.py
index f8ac4be..b6694ac 100644
--- a/tests/test_controllers/test_cohort_upload.py
+++ b/tests/test_controllers/test_cohort_upload.py
@@ -119,3 +119,14 @@
         assert_equal(len(parsed), 1)
         assert_equal(parsed[0]['username'], u'Kán'.encode("utf-8"))
         assert_equal(parsed[0]['project'], 'en')
+
+    def test_format_records_with_spaces_in_project(self):
+        parsed = format_records(
+            [
+                ['dan', ' en']
+            ],
+            None
+        )
+        assert_equal(len(parsed), 1)
+        assert_equal(parsed[0]['username'], 'Dan')
+        assert_equal(parsed[0]['project'], 'en')
diff --git a/wikimetrics/forms/cohort_upload.py 
b/wikimetrics/forms/cohort_upload.py
index 1a4e1bb..41ef81a 100644
--- a/wikimetrics/forms/cohort_upload.py
+++ b/wikimetrics/forms/cohort_upload.py
@@ -96,7 +96,7 @@
             # and the username to be the last or maybe change to a tsv format
             if len(r) > 1:
                 username = ",".join([str(p) for p in r[:-1]])
-                project = r[-1] or default_project
+                project = r[-1].strip() or default_project
             else:
                 username = r[0]
                 project = default_project

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I301b8c2cafbf4de98b2fd2c2ead9cd74b254f32f
Gerrit-PatchSet: 1
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: Mforns <[email protected]>

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

Reply via email to