Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/49469
Change subject: Add requirements.txt, improve test coverage.
......................................................................
Add requirements.txt, improve test coverage.
Change-Id: I1c9d5ff9c7eca222913fed8d34b6ea1cdfded66a
---
M server/eventlogging/schema.py
A server/requirements.txt
M server/setup.py
M server/tests/fixtures.py
M server/tests/test_parser.py
M server/tests/test_schema.py
6 files changed, 29 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/EventLogging
refs/changes/69/49469/1
diff --git a/server/eventlogging/schema.py b/server/eventlogging/schema.py
index b7d12d2..13fc663 100644
--- a/server/eventlogging/schema.py
+++ b/server/eventlogging/schema.py
@@ -86,10 +86,8 @@
try:
content = urlopen(url).read().decode('utf-8')
schema = json.loads(content)
- except EnvironmentError as ex:
- raise jsonschema.SchemaError('Failed to retrieve schema: %s' % ex)
- except ValueError:
- raise jsonschema.SchemaError('Could not decode JSON Schema at ' + url)
+ except (ValueError, EnvironmentError) as ex:
+ raise jsonschema.SchemaError('Schema fetch failure: %s' % ex)
jsonschema.Draft3Validator.check_schema(schema)
return schema
@@ -104,6 +102,6 @@
# If `schema`, `revision` or `event` keys are missing, a
# KeyError exception will be raised. We re-raise it as a
# :exc:`ValidationError` to provide a simpler API for callers.
- raise jsonschema.ValidationError('Missing key: %s' % ex.message)
+ raise jsonschema.ValidationError('Missing key: %s' % ex)
schema = get_schema(scid, encapsulate=True)
jsonschema.validate(capsule, schema)
diff --git a/server/requirements.txt b/server/requirements.txt
new file mode 100644
index 0000000..3dc0456
--- /dev/null
+++ b/server/requirements.txt
@@ -0,0 +1,4 @@
+jsonschema>=0.7
+pygments>=1.5
+pyzmq>=2.1
+sqlalchemy>=0.7
diff --git a/server/setup.py b/server/setup.py
index 358991c..c8e118b 100644
--- a/server/setup.py
+++ b/server/setup.py
@@ -55,8 +55,8 @@
zip_safe=False,
test_suite='tests',
install_requires=(
- "pygments>=1.5",
"jsonschema>=0.7",
+ "pygments>=1.5",
"pyzmq>=2.1",
"sqlalchemy>=0.7",
),
diff --git a/server/tests/fixtures.py b/server/tests/fixtures.py
index 0f75c56..d89e2d8 100644
--- a/server/tests/fixtures.py
+++ b/server/tests/fixtures.py
@@ -176,6 +176,7 @@
super(HttpSchemaTestMixin, self).setUp()
self.orig_urlopen = eventlogging.schema.urlopen
eventlogging.schema.urlopen = self.urlopen_stub
+ eventlogging.schema.schema_cache.clear()
def tearDown(self):
"""Restore original `urlopen`."""
diff --git a/server/tests/test_parser.py b/server/tests/test_parser.py
index 2a7b9f6..5a5db38 100644
--- a/server/tests/test_parser.py
+++ b/server/tests/test_parser.py
@@ -6,11 +6,20 @@
This module contains tests for :class:`eventlogging.LogParser`.
"""
+import calendar
+import datetime
import unittest
import eventlogging
+class NcsaTimestampTestCase(unittest.TestCase):
+ def test_ncsa_timestamp_handling(self):
+ epoch_ts = calendar.timegm(datetime.datetime.utcnow().utctimetuple())
+ ncsa_ts = eventlogging.ncsa_utcnow()
+ self.assertAlmostEqual(eventlogging.ncsa_to_epoch(ncsa_ts),
+ epoch_ts, delta=100)
+
class LogParserTestCase(unittest.TestCase):
"""Test case for LogParser."""
diff --git a/server/tests/test_schema.py b/server/tests/test_schema.py
index aee533b..08d60e1 100644
--- a/server/tests/test_schema.py
+++ b/server/tests/test_schema.py
@@ -42,6 +42,12 @@
with self.assertRaises(eventlogging.SchemaError):
eventlogging.schema.http_get_schema(TEST_SCHEMA_SCID)
+ def test_caching(self):
+ """Valid HTTP responses containing JSON Schema are cached."""
+ self.http_resp = b'{"properties":{"value":{"type":"number"}}}'
+ eventlogging.get_schema(TEST_SCHEMA_SCID)
+ self.assertIn(TEST_SCHEMA_SCID, eventlogging.schema.schema_cache)
+
class SchemaTestCase(SchemaTestMixin, unittest.TestCase):
"""Tests for :module:`eventlogging.schema`."""
@@ -50,6 +56,11 @@
"""Valid events validate."""
self.assertIsValid(self.event)
+ def test_incomplete_scid(self):
+ """Missing SCID in capsule object triggers validation failure."""
+ self.event.pop('schema')
+ self.assertIsInvalid(self.event)
+
def test_missing_property(self):
"""Missing property in capsule object triggers validation failure."""
self.event.pop('timestamp')
--
To view, visit https://gerrit.wikimedia.org/r/49469
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c9d5ff9c7eca222913fed8d34b6ea1cdfded66a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/EventLogging
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits