Use urljoin to create proper feed media URLs
[larjonas-mediagoblin.git] / mediagoblin / tests / test_piwigo.py
blob33aea5801bee42b55a9024ce31d6e9456952c431
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2013 MediaGoblin contributors. See AUTHORS.
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.
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.
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/>.
17 import pytest
18 from .tools import fixture_add_user
21 XML_PREFIX = "<?xml version='1.0' encoding='utf-8'?>\n"
24 class Test_PWG(object):
25 @pytest.fixture(autouse=True)
26 def setup(self, test_app):
27 self.test_app = test_app
29 fixture_add_user()
31 self.username = u"chris"
32 self.password = "toast"
34 def do_post(self, method, params):
35 params["method"] = method
36 return self.test_app.post("/api/piwigo/ws.php", params)
38 def do_get(self, method, params=None):
39 if params is None:
40 params = {}
41 params["method"] = method
42 return self.test_app.get("/api/piwigo/ws.php", params)
44 def test_session(self):
45 resp = self.do_post("pwg.session.login",
46 {"username": u"nouser", "password": "wrong"})
47 assert resp.body == (XML_PREFIX + '<rsp stat="fail"><err code="999" msg="Invalid username/password"/></rsp>').encode('ascii')
49 resp = self.do_post("pwg.session.login",
50 {"username": self.username, "password": "wrong"})
51 assert resp.body == (XML_PREFIX + '<rsp stat="fail"><err code="999" msg="Invalid username/password"/></rsp>').encode('ascii')
53 resp = self.do_get("pwg.session.getStatus")
54 assert resp.body == (XML_PREFIX + '<rsp stat="ok"><username>guest</username></rsp>').encode('ascii')
56 resp = self.do_post("pwg.session.login",
57 {"username": self.username, "password": self.password})
58 assert resp.body == (XML_PREFIX + '<rsp stat="ok">1</rsp>').encode('ascii')
60 resp = self.do_get("pwg.session.getStatus")
61 assert resp.body == (XML_PREFIX + '<rsp stat="ok"><username>chris</username></rsp>').encode('ascii')
63 self.do_get("pwg.session.logout")
65 resp = self.do_get("pwg.session.getStatus")
66 assert resp.body == (XML_PREFIX + '<rsp stat="ok"><username>guest</username></rsp>').encode('ascii')