test_piwigo.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. import pytest
  17. from .tools import fixture_add_user
  18. XML_PREFIX = "<?xml version='1.0' encoding='utf-8'?>\n"
  19. class Test_PWG(object):
  20. @pytest.fixture(autouse=True)
  21. def setup(self, test_app):
  22. self.test_app = test_app
  23. fixture_add_user()
  24. self.username = u"chris"
  25. self.password = "toast"
  26. def do_post(self, method, params):
  27. params["method"] = method
  28. return self.test_app.post("/api/piwigo/ws.php", params)
  29. def do_get(self, method, params=None):
  30. if params is None:
  31. params = {}
  32. params["method"] = method
  33. return self.test_app.get("/api/piwigo/ws.php", params)
  34. def test_session(self):
  35. resp = self.do_post("pwg.session.login",
  36. {"username": u"nouser", "password": "wrong"})
  37. assert resp.body == (XML_PREFIX + '<rsp stat="fail"><err code="999" msg="Invalid username/password"/></rsp>').encode('ascii')
  38. resp = self.do_post("pwg.session.login",
  39. {"username": self.username, "password": "wrong"})
  40. assert resp.body == (XML_PREFIX + '<rsp stat="fail"><err code="999" msg="Invalid username/password"/></rsp>').encode('ascii')
  41. resp = self.do_get("pwg.session.getStatus")
  42. assert resp.body == (XML_PREFIX + '<rsp stat="ok"><username>guest</username></rsp>').encode('ascii')
  43. resp = self.do_post("pwg.session.login",
  44. {"username": self.username, "password": self.password})
  45. assert resp.body == (XML_PREFIX + '<rsp stat="ok">1</rsp>').encode('ascii')
  46. resp = self.do_get("pwg.session.getStatus")
  47. assert resp.body == (XML_PREFIX + '<rsp stat="ok"><username>chris</username></rsp>').encode('ascii')
  48. self.do_get("pwg.session.logout")
  49. resp = self.do_get("pwg.session.getStatus")
  50. assert resp.body == (XML_PREFIX + '<rsp stat="ok"><username>guest</username></rsp>').encode('ascii')