sogo/Tests/Integration/test-ui-posts.py
Jean Raby aeef968c4e * Tests/Integration/config.py.in: New config parameter: webCalendarURL
* Tests/Integration/webdavlib.py(HTTPPOST,HTTPGET):
  Allow cookies in post and get requests.
  * Tests/Integration/test-ui-posts.py: New test class
  Currently contains only one test case which exercises addWebCalendar

  * SoObjects/Appointments/GNUmakefile:
  use -Wl,--no-as-needed when linking. Fixes #1863

Monotone-Parent: 080d411d52272c158ce60ea0bab6ba8eb9d9aa2a
Monotone-Revision: 8ce46d6fa7b1d1a9d12069cee3ba796d99d668d2

Monotone-Author: jraby@inverse.ca
Monotone-Date: 2012-07-18T20:22:54
2012-07-18 20:22:54 +00:00

76 lines
2.1 KiB
Python

#!/usr/bin/python
from config import hostname, port, username, password, \
webCalendarURL
import simplejson
import sogoLogin
import sogotests
import unittest
import utilities
import webdavlib
import httplib
class UIPostsTests(unittest.TestCase):
def setUp(self):
self.client = webdavlib.WebDAVClient(hostname, port)
self.gcClient = webdavlib.WebDAVClient(hostname, port)
self.cookie = sogoLogin.getAuthCookie(hostname, port, username, password)
def _urlPostData(self, client, url, data, exp_status=200):
post = webdavlib.HTTPPOST(url, data)
post.content_type = "application/x-www-form-urlencoded"
post.cookie = self.cookie
client.execute(post)
if (exp_status is not None):
self.assertEquals(post.response["status"], exp_status)
return post.response
def _urlGet(self, client, url, exp_status=200):
get = webdavlib.HTTPGET(url)
get.cookie = self.cookie
client.execute(get)
if (exp_status is not None):
self.assertEquals(get.response["status"], exp_status)
return get.response
def testAddWebCalendar(self):
""" Add Web Calendar """
ret=True
data = "url=%s" % webCalendarURL
calendarBaseURL="/SOGo/so/%s/Calendar" % username
addWebCalendarURL = "%s/addWebCalendar" % calendarBaseURL
response = self._urlPostData(self.client, addWebCalendarURL, data)
respJSON = simplejson.loads(response['body'])
folderID = respJSON['folderID']
#sogo1:Calendar/C07-5006F300-1-370E2480
(_, calID) = folderID.split('/', 1)
self.assertNotEqual(calID, None)
# reload the cal
calURL = "%s/%s" % (calendarBaseURL, calID)
try:
response = self._urlGet(self.client, "%s/reload" % calURL, exp_status=None)
except httplib.BadStatusLine:
# that's bad, the server probably reset the connection. fake a 502
response['status'] = 502
# cleanup our trash
self._urlPostData(self.gcClient, "%s/delete" % calURL, "", exp_status=None)
# delayed assert to allow cal deletion on failure
self.assertEqual(response['status'], 200)
if __name__ == "__main__":
sogotests.runTests()