summaryrefslogtreecommitdiffstats
path: root/tests/test_local_server.py
blob: 5bd8760f9c15cfdf8a26740ea19733641bebdea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
This file contains tests that connect to a local wikibase install (eg, in a
vagrant env).

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 warnings

from bbb import *

TEST_SERVER_URL = "http://wikidata.wiki.local.wmftest.net:8080/w/api.php"
TEST_SERVER_USER = "TestBaseBot"
TEST_SERVER_PASSWD = "TestBaseBot123" # I know, right?

class TestLocalServer(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.srv = WikibaseServer(
            api_url=TEST_SERVER_URL,
            lang="en",
            auth=None)
        try:
            cls.srv.check()
        except WikibaseException:
            raise SkipTest("Couldn't connect to local dev wikibase server")

        cls.srv.login(TEST_SERVER_USER, TEST_SERVER_PASSWD,
                        force_http=True)

        cls.srv.check()

    def setUp(self):
        #self.srv.logout()
        #self.srv.login(TEST_SERVER_USER, TEST_SERVER_PASSWD, force_http=True)
        pass    # TODO:

    def test_logout_login(self):
        self.srv.logout()
        self.srv.check()
        self.srv.login(TEST_SERVER_USER, TEST_SERVER_PASSWD, force_http=True)
        self.srv.check()

    def test_force_http(self):
        tsrv = WikibaseServer("http://example.com/w/api.php")
        with assert_raises(WikibaseException):
            tsrv.login("fake", "fake")

    def test_low_level(self):
        self.srv._get("wbgetclaims", dict(entity="Q3"))

    def test_api_warnings(self):
        with warnings.catch_warnings(record=True) as warns:
            self.srv._get("wbparsevalue",
                dict(datatype="time", values="now",
                    dummy_non_existant_param="THIS"))

            assert_equals(len(warns), 1)
            print(warns[0])
            print(str(warns[0].message))
            assert "Unrecognized parameter" in str(warns[0].message)

    def test_bad_pass(self):
        self.srv.logout()
        with assert_raises(WikibaseAccountError):
            self.srv.login(TEST_SERVER_USER, TEST_SERVER_PASSWD+"BADBAD", force_http=True)

    def test_get_item(self):
        item = self.srv.get_item("Coffee")
        item = self.srv.get_item("Q2")
        item = self.srv.get_item(2)

    def test_get_property(self):
        raise SkipTest("UNIMPLEMENTED")
        item = self.srv.get_property("Mass")
        item = self.srv.get_property(pid="P2")
        item = self.srv.get_property(pid=2)

    def test_find_items(self):
        raise SkipTest("UNIMPLEMENTED")
        l = self.srv.find_items("love", limit=5)
        l = self.srv.find_items("robot", limit=5)
        l = self.srv.find_items("Imposible_String_" + random.randint(10e19, 10e20), limit=5)
        assert len(l) == 0

    def test_create_item(self):
        raise SkipTest("UNIMPLEMENTED")
        item = WikibaseItem("QWERTY Layout")
        self.srv.create(thing)
        item.add(WikibaseStatement(
            "Inventor", "Christopher Latham Sholes", datatype="item",
            qualifiers={'year_of_invention': 1860},
            refs=['http://www.smithsonianmag.com/arts-culture/fact-of-fiction-the-legend-of-the-qwerty-keyboard-49863249/']))
        self.srv.save(item)