4d0ea8852799578a972eab22198225c3c474e8bd
[mediagoblin.git] / mediagoblin / tests / test_piwigo.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2013 MediaGoblin contributors. See AUTHORS.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 import pytest
18 from .tools import fixture_add_user
19 from mediagoblin.tools.testing import _activate_testing
20
21 _activate_testing()
22
23
24 XML_PREFIX = "<?xml version='1.0' encoding='utf-8'?>\n"
25
26
27 class Test_PWG(object):
28 @pytest.fixture(autouse=True)
29 def setup(self, test_app):
30 self.test_app = test_app
31
32 fixture_add_user()
33
34 self.username = u"chris"
35 self.password = "toast"
36
37 def do_post(self, method, params):
38 params["method"] = method
39 return self.test_app.post("/api/piwigo/ws.php", params)
40
41 def do_get(self, method, params=None):
42 if params is None:
43 params = {}
44 params["method"] = method
45 return self.test_app.get("/api/piwigo/ws.php", params)
46
47 def test_session(self):
48 resp = self.do_post("pwg.session.login",
49 {"username": u"nouser", "password": "wrong"})
50 assert resp.body == XML_PREFIX + '<rsp stat="ok">0</rsp>'
51
52 resp = self.do_post("pwg.session.login",
53 {"username": self.username, "password": "wrong"})
54 assert resp.body == XML_PREFIX + '<rsp stat="ok">0</rsp>'
55
56 resp = self.do_get("pwg.session.getStatus")
57 assert resp.body == XML_PREFIX \
58 + '<rsp stat="ok"><username>guest</username></rsp>'
59
60 resp = self.do_post("pwg.session.login",
61 {"username": self.username, "password": self.password})
62 assert resp.body == XML_PREFIX + '<rsp stat="ok">1</rsp>'
63
64 resp = self.do_get("pwg.session.getStatus")
65 assert resp.body == XML_PREFIX \
66 + '<rsp stat="ok"><username>chris</username></rsp>'
67
68 self.do_get("pwg.session.logout")
69
70 resp = self.do_get("pwg.session.getStatus")
71 assert resp.body == XML_PREFIX \
72 + '<rsp stat="ok"><username>guest</username></rsp>'