John Vandenberg has uploaded a new change for review.

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

Change subject: Add async_request test
......................................................................

Add async_request test

Use Queue.mark_done so that tests can use Queue.join.

Bug: T98439
Change-Id: I8e80d26e8a8a09cddbf26b47c27ffb61a8b0d7e4
---
M pywikibot/__init__.py
M tests/api_tests.py
A tests/edit_tests.py
M tests/site_tests.py
M tox.ini
5 files changed, 76 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/02/215302/1

diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 615589e..ea8304a 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -721,6 +721,7 @@
         if request is None:
             break
         request(*args, **kwargs)
+        page_put_queue.task_done()
 
 
 def async_request(request, *args, **kwargs):
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 46319f1..dde46f5 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -16,6 +16,7 @@
 import pywikibot.family
 import pywikibot.login
 import pywikibot.site
+
 from pywikibot.tools import MediaWikiVersion
 
 from tests.aspects import (
diff --git a/tests/edit_tests.py b/tests/edit_tests.py
new file mode 100644
index 0000000..6778a53
--- /dev/null
+++ b/tests/edit_tests.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8  -*-
+"""Tests for editing pages."""
+#
+# (C) Pywikibot team, 2015
+#
+# Distributed under the terms of the MIT license.
+#
+from __future__ import unicode_literals
+
+__version__ = '$Id$'
+#
+
+import time
+
+import pywikibot
+
+from pywikibot import page_put_queue
+
+from tests.aspects import unittest, TestCase
+
+called_back = False
+
+
+class TestGeneralWrite(TestCase):
+
+    """Run general write tests."""
+
+    family = 'test'
+    code = 'test'
+
+    user = True
+    write = True
+
+    def test_async(self):
+        """Test writing to a page."""
+        global called_back
+        def callback(page, err):
+            global called_back
+            self.assertEqual(page, p)
+            self.assertIsNone(err)
+            called_back = True
+
+        called_back = False
+        ts = str(time.time())
+        p = pywikibot.Page(self.site, 'User:John Vandenberg/async test write')
+        p.text = ts
+        p.save(async=True, callback=callback)
+
+        page_put_queue.join()
+
+        p = pywikibot.Page(self.site, 'User:John Vandenberg/async test write')
+        self.assertEqual(p.text, ts)
+        self.assertTrue(called_back)
+
+if __name__ == '__main__':
+    try:
+        unittest.main()
+    except SystemExit:
+        pass
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 0810f95..953a3d4 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -17,7 +17,9 @@
 import re
 
 import pywikibot
+
 from pywikibot import config
+from pywikibot import async_request, page_put_queue
 from pywikibot.comms import http
 from pywikibot.tools import MediaWikiVersion
 from pywikibot.data import api
@@ -1637,6 +1639,18 @@
         self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists).keys()))
 
 
+
+class TestSiteinfoAsync(DefaultSiteTestCase):
+
+    """Test asyncronous siteinfo fetch."""
+
+    def test_async_request(self):
+        assert('statistics' not in self.site.siteinfo)
+        async_request(self.site.siteinfo.get, 'statistics')
+        page_put_queue.join()
+        self.assertIn('statistics', self.site.siteinfo)
+
+
 class TestSiteLoadRevisions(TestCase):
 
     """Test cases for Site.loadrevision() method."""
diff --git a/tox.ini b/tox.ini
index 67e1655..cb3ca7e 100644
--- a/tox.ini
+++ b/tox.ini
@@ -111,6 +111,7 @@
     tests/cache_tests.py \
     tests/cosmetic_changes_tests.py \
     tests/date_tests.py \
+    tests/edit_tests.py \
     tests/edit_failure_tests.py \
     tests/exceptions_tests.py \
     tests/family_tests.py \

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e80d26e8a8a09cddbf26b47c27ffb61a8b0d7e4
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jay...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to