jenkins-bot has submitted this change and it was merged.

Change subject: Add cache test
......................................................................


Add cache test

This test attempts to validate all cache entries, at the end of
the build as a sanity check.

DataSite cache entries were failing to load due to having a
different __init__ signature from APISite.

CacheEntry.params renamed to _params to reflect changes in the
Request object.

Change-Id: I64b685776ad10611c91631e1937613e846972824
---
M .gitignore
M pywikibot/site.py
M scripts/maintenance/cache.py
M tests/__init__.py
A tests/cache_tests.py
5 files changed, 51 insertions(+), 6 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, but someone else must approve
  Nullzero: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/.gitignore b/.gitignore
index 54297a7..16842b7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,7 +8,8 @@
 /*.egg
 /data*
 logs*
-*cache*
+*apicache*
+*pycache*
 .idea
 pywikibot.egg-info/
 pywikibot/families/
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 8cf9f60..3265eb6 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -4855,7 +4855,7 @@
 
     """Wikibase data capable site."""
 
-    def __init__(self, code, fam, user, sysop):
+    def __init__(self, code, fam=None, user=None, sysop=None):
         """Constructor."""
         APISite.__init__(self, code, fam, user, sysop)
         self._item_namespace = None
diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py
index 15dbc88..0d7ed2e 100644
--- a/scripts/maintenance/cache.py
+++ b/scripts/maintenance/cache.py
@@ -158,15 +158,17 @@
             (site, username, login_status, params) = self._parsed_key
         else:
             (site, username, login_status, params) = self.parse_key()
-        if site:
-            self.site = eval(site)
+        if not site:
+            raise ParseError('No Site')
+        self.site = eval(site)
         if login_status:
             self.site._loginstatus = eval('LoginStatus.%s'
                                           % login_status[12:-1])
         if username:
             self.site._username = [username, username]
-        if params:
-            self.params = dict(eval(params))
+        if not params:
+            raise ParseError('No request params')
+        self._params = dict(eval(params))
 
     def _delete(self):
         """ Delete the cache entry. """
diff --git a/tests/__init__.py b/tests/__init__.py
index b903565..0688f98 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -86,6 +86,7 @@
     'script',
     'archivebot',
     'data_ingestion',
+    'cache',
 ]
 
 disabled_test_modules = [
diff --git a/tests/cache_tests.py b/tests/cache_tests.py
new file mode 100644
index 0000000..241f2d7
--- /dev/null
+++ b/tests/cache_tests.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8  -*-
+"""API Request cache tests."""
+#
+# (C) Pywikibot team, 2012-2014
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+#
+
+from pywikibot.site import BaseSite
+import scripts.maintenance.cache as cache
+
+from tests import _cache_dir
+from tests.aspects import unittest, TestCase
+
+
+class RequestCacheTests(TestCase):
+
+    """Validate cache entries."""
+
+    net = False
+
+    def _check_cache_entry(self, entry):
+        self.assertIsInstance(entry.site, BaseSite)
+        self.assertIsInstance(entry.site._loginstatus, int)
+        self.assertIsInstance(entry.site._username, list)
+        print(entry.site._loginstatus, entry.site._username)
+        self.assertTrue(bool(entry.site._loginstatus < 1) !=
+                        bool(entry.site._username[0]))
+        self.assertIsInstance(entry._params, dict)
+        self.assertIsNotNone(entry._params)
+        # TODO: more tests on entry._params, and possibly fixes needed
+        # to make it closely replicate the original object.
+
+    def test_cache(self):
+        cache.process_entries(_cache_dir, self._check_cache_entry)
+
+
+if __name__ == '__main__':
+    unittest.main()

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I64b685776ad10611c91631e1937613e846972824
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Maverick <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Nullzero <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to