Add deprecation warning with pointers to WMF's pages on the topic (#365)
[ores.git] / tests / test_api.py
blob8f5a58b0aa1430aa2664eb5f94a09d54d258b25a
1 from ores import api
4 class FakeSession:
6 def __init__(self, error_out=False):
7 self.error_out = error_out
9 def get(self, url, params, headers, verify=False, stream=False):
10 if self.error_out:
11 return FakeResponse(
12 {"error": {"code": "an error", "message": "a message"}})
13 else:
14 return FakeResponse({
15 "context": {
16 "scores": {
17 str(rev_id): {model: {"score": "my score"}
18 for model in params['models'].split("|")}
19 for rev_id in params['revids'].split("|")
25 class FakeResponse:
27 def __init__(self, doc):
28 self.doc = doc
30 def json(self):
31 return self.doc
34 def test_fake_session():
35 session = FakeSession(error_out=True)
36 response = session.get(None, None, None)
37 doc = response.json()
38 assert 'error' in doc
41 def test_session():
42 session1 = api.Session("myhost", session=FakeSession())
43 scores = list(session1.score("context", ["foo", "bar"], range(0, 100)))
44 assert len(scores) == 100
45 assert scores[0] == {"foo": {"score": "my score"},
46 "bar": {"score": "my score"}}
49 def test_base_error():
50 session2 = api.Session("myhost", session=FakeSession(error_out=True))
51 scores = list(session2.score("context", ["foo", "bar"], range(0, 100)))
52 assert len(scores) == 100
53 assert scores[0]['foo']['error'] == \
54 {'code': 'an error', 'message': 'a message'}