summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/example_complete_item.json388
-rw-r--r--tests/test_json.py27
2 files changed, 415 insertions, 0 deletions
diff --git a/tests/example_complete_item.json b/tests/example_complete_item.json
new file mode 100644
index 0000000..48e9b31
--- /dev/null
+++ b/tests/example_complete_item.json
@@ -0,0 +1,388 @@
+{
+ "claims" : {
+ "P6" : [
+ {
+ "rank" : "preferred",
+ "type" : "statement",
+ "id" : "Q60$5cc8fc79-4807-9800-dbea-fe9c20ab273b",
+ "qualifiers" : {
+ "P580" : [
+ {
+ "hash" : "c53f3ca845b789e543ed45e3e1ecd1dd950e30dc",
+ "snaktype" : "value",
+ "datavalue" : {
+ "type" : "time",
+ "value" : {
+ "calendarmodel" : "http://www.wikidata.org/entity/Q1985727",
+ "timezone" : 0,
+ "after" : 0,
+ "before" : 0,
+ "time" : "+00000002014-01-01T00:00:00Z",
+ "precision" : 11
+ }
+ },
+ "property" : "P580",
+ "datatype" : "time"
+ }
+ ]
+ },
+ "qualifiers-order" : [
+ "P580"
+ ],
+ "mainsnak" : {
+ "datatype" : "wikibase-item",
+ "property" : "P6",
+ "snaktype" : "value",
+ "datavalue" : {
+ "type" : "wikibase-entityid",
+ "value" : {
+ "entity-type" : "item",
+ "numeric-id" : 4911497
+ }
+ }
+ }
+ },
+ {
+ "mainsnak" : {
+ "property" : "P6",
+ "datatype" : "wikibase-item",
+ "snaktype" : "value",
+ "datavalue" : {
+ "value" : {
+ "entity-type" : "item",
+ "numeric-id" : 607
+ },
+ "type" : "wikibase-entityid"
+ }
+ },
+ "qualifiers-order" : [
+ "P580",
+ "P582"
+ ],
+ "id" : "q60$cad4e313-4b5e-e089-08b9-3b1c7998e762",
+ "qualifiers" : {
+ "P580" : [
+ {
+ "hash" : "47c515b79f80e24e03375b327f2ac85184765d5b",
+ "snaktype" : "value",
+ "datavalue" : {
+ "type" : "time",
+ "value" : {
+ "before" : 0,
+ "time" : "+00000002002-01-01T00:00:00Z",
+ "precision" : 11,
+ "calendarmodel" : "http://www.wikidata.org/entity/Q1985727",
+ "timezone" : 0,
+ "after" : 0
+ }
+ },
+ "property" : "P580",
+ "datatype" : "time"
+ }
+ ],
+ "P582" : [
+ {
+ "datavalue" : {
+ "value" : {
+ "calendarmodel" : "http://www.wikidata.org/entity/Q1985727",
+ "timezone" : 0,
+ "after" : 0,
+ "before" : 0,
+ "time" : "+00000002013-12-31T00:00:00Z",
+ "precision" : 11
+ },
+ "type" : "time"
+ },
+ "snaktype" : "value",
+ "hash" : "1f463f78538c49ef6adf3a9b18e211af7195240a",
+ "datatype" : "time",
+ "property" : "P582"
+ }
+ ]
+ },
+ "P856" : [
+ {
+ "mainsnak" : {
+ "snaktype" : "value",
+ "datavalue" : {
+ "type" : "string",
+ "value" : "http://nyc.gov/"
+ },
+ "datatype" : "url",
+ "property" : "P856"
+ },
+ "rank" : "normal",
+ "type" : "statement",
+ "id" : "Q60$4e3e7a42-4ec4-b7c3-7570-b103eb2bc1ac"
+ }
+ ]
+ }
+ ],
+ "P625" : [
+ {
+ "mainsnak" : {
+ "datatype" : "globe-coordinate",
+ "property" : "P625",
+ "datavalue" : {
+ "value" : {
+ "globe" : "http://www.wikidata.org/entity/Q2",
+ "latitude" : 40.67,
+ "precision" : 0.00027777777777778,
+ "longitude" : -73.94,
+ "altitude" : null
+ },
+ "type" : "globecoordinate"
+ },
+ "snaktype" : "value"
+ },
+ "references" : [
+ {
+ "snaks" : {
+ "P143" : [
+ {
+ "property" : "P143",
+ "datatype" : "wikibase-item",
+ "datavalue" : {
+ "type" : "wikibase-entityid",
+ "value" : {
+ "entity-type" : "item",
+ "numeric-id" : 328
+ }
+ },
+ "snaktype" : "value"
+ }
+ ]
+ },
+ "snaks-order" : [
+ "P143"
+ ],
+ "hash" : "7eb64cf9621d34c54fd4bd040ed4b61a88c4a1a0"
+ }
+ ],
+ "type" : "statement",
+ "rank" : "normal",
+ "id" : "q60$f00c56de-4bac-e259-b146-254897432868"
+ }
+ ],
+ "P1151" : [
+ {
+ "mainsnak" : {
+ "datavalue" : {
+ "value" : {
+ "numeric-id" : 6342720,
+ "entity-type" : "item"
+ },
+ "type" : "wikibase-entityid"
+ },
+ "snaktype" : "value",
+ "property" : "P1151",
+ "datatype" : "wikibase-item"
+ },
+ "rank" : "normal",
+ "type" : "statement",
+ "id" : "Q60$6f832804-4c3f-6185-38bd-ca00b8517765"
+ }
+ ],
+ "P150" : [
+ {
+ "rank" : "normal",
+ "type" : "statement",
+ "id" : "Q60$bdddaa06-4e4b-f369-8954-2bb010aaa057",
+ "mainsnak" : {
+ "property" : "P150",
+ "datatype" : "wikibase-item",
+ "snaktype" : "value",
+ "datavalue" : {
+ "value" : {
+ "entity-type" : "item",
+ "numeric-id" : 11299
+ },
+ "type" : "wikibase-entityid"
+ }
+ }
+ },
+ {
+ "type" : "statement",
+ "rank" : "normal",
+ "id" : "Q60$0e484d5b-41a5-1594-7ae1-c3768c6206f6",
+ "mainsnak" : {
+ "datavalue" : {
+ "value" : {
+ "numeric-id" : 18419,
+ "entity-type" : "item"
+ },
+ "type" : "wikibase-entityid"
+ },
+ "snaktype" : "value",
+ "datatype" : "wikibase-item",
+ "property" : "P150"
+ }
+ },
+ {
+ "id" : "Q60$e5000a60-42fc-2aba-f16d-bade1d2e8a58",
+ "type" : "statement",
+ "rank" : "normal",
+ "mainsnak" : {
+ "datatype" : "wikibase-item",
+ "property" : "P150",
+ "snaktype" : "value",
+ "datavalue" : {
+ "value" : {
+ "entity-type" : "item",
+ "numeric-id" : 18424
+ },
+ "type" : "wikibase-entityid"
+ }
+ }
+ },
+ {
+ "mainsnak" : {
+ "datavalue" : {
+ "value" : {
+ "entity-type" : "item",
+ "numeric-id" : 18426
+ },
+ "type" : "wikibase-entityid"
+ },
+ "snaktype" : "value",
+ "datatype" : "wikibase-item",
+ "property" : "P150"
+ },
+ "type" : "statement",
+ "rank" : "normal",
+ "id" : "Q60$4d90d6f4-4ab8-26bd-f2a5-4ac2a6eb48cd"
+ },
+ {
+ "rank" : "normal",
+ "type" : "statement",
+ "id" : "Q60$ede49e3c-44f6-75a3-eb74-6a89886e30c9",
+ "mainsnak" : {
+ "property" : "P150",
+ "datatype" : "wikibase-item",
+ "snaktype" : "value",
+ "datavalue" : {
+ "value" : {
+ "numeric-id" : 18432,
+ "entity-type" : "item"
+ },
+ "type" : "wikibase-entityid"
+ }
+ }
+ }
+ ]
+ },
+ "title" : "Q60",
+ "descriptions" : {
+ "ro" : {
+ "value" : "oraşul cel mai mare din SUA",
+ "language" : "ro"
+ },
+ "it" : {
+ "value" : "città degli Stati Uniti d'America",
+ "language" : "it"
+ },
+ "pl" : {
+ "language" : "pl",
+ "value" : "miasto w Stanach Zjednoczonych"
+ },
+ "en" : {
+ "language" : "en",
+ "value" : "largest city in New York and the United States of America"
+ }
+ },
+ "sitelinks" : {
+ "zhwikivoyage" : {
+ "badges" : [],
+ "title" : "紐約",
+ "site" : "zhwikivoyage"
+ },
+ "dewikinews" : {
+ "title" : "Kategorie:New York",
+ "site" : "dewikinews",
+ "badges" : []
+ },
+ "enwiki" : {
+ "site" : "enwiki",
+ "title" : "New York City",
+ "badges" : []
+ },
+ "dewiki" : {
+ "badges" : [
+ "Q17437798"
+ ],
+ "site" : "dewiki",
+ "title" : "New York City"
+ },
+ "zuwiki" : {
+ "title" : "New York (idolobha)",
+ "site" : "zuwiki",
+ "badges" : []
+ },
+ "elwiki" : {
+ "site" : "elwiki",
+ "title" : "Νέα Υόρκη",
+ "badges" : []
+ },
+ "afwiki" : {
+ "title" : "New York Stad",
+ "site" : "afwiki",
+ "badges" : []
+ }
+ },
+ "lastrevid" : 199780882,
+ "type" : "item",
+ "id" : "Q60",
+ "pageid" : 186,
+ "labels" : {
+ "ps" : {
+ "language" : "ps",
+ "value" : "نيويارک"
+ },
+ "fr" : {
+ "language" : "fr",
+ "value" : "New York City"
+ },
+ "my" : {
+ "language" : "my",
+ "value" : "နယူးယောက်မြို့"
+ },
+ "ar" : {
+ "language" : "ar",
+ "value" : "مدينة نيو يورك"
+ },
+ "en" : {
+ "language" : "en",
+ "value" : "New York City"
+ }
+ },
+ "aliases" : {
+ "zh-mo" : [
+ {
+ "language" : "zh-mo",
+ "value" : "紐約市"
+ }
+ ],
+ "en" : [
+ {
+ "language" : "en",
+ "value" : "NYC"
+ },
+ {
+ "language" : "en",
+ "value" : "New York"
+ }
+ ],
+ "fr" : [
+ {
+ "value" : "New York City",
+ "language" : "fr"
+ },
+ {
+ "value" : "NYC",
+ "language" : "fr"
+ }
+ ]
+ },
+ "modified" : "2015-02-27T14:37:20Z",
+ "ns" : 0
+}
diff --git a/tests/test_json.py b/tests/test_json.py
new file mode 100644
index 0000000..19dfc18
--- /dev/null
+++ b/tests/test_json.py
@@ -0,0 +1,27 @@
+"""
+This file contains tests that parse and dump JSON serialized entities.
+
+It requires the 'nose' python package. To run it, just enter this directory and
+do:
+
+ $ nosetests
+
+If there are errors it can be helpful to debug with:
+
+ $ nosetests --pdb
+"""
+
+from nose.tools import *
+from nose.plugins.skip import SkipTest
+import unittest
+import random
+import json
+
+from bbb import *
+
+class TestJSON(unittest.TestCase):
+
+ def test_wikidata_org_item(self):
+ with open('tests/example_item_nyc.json', 'r') as f:
+ d = json.loads(''.join(f.readlines()))
+ wi = WikibaseItem.from_dict(d)