Update REST test to include attributes for SP Portal
[cascardo/ipsilon.git] / tests / helpers / http.py
index bfa3240..69d40a5 100755 (executable)
@@ -1,22 +1,6 @@
 #!/usr/bin/python
 #
-# Copyright (C) 2014  Simo Sorce <simo@redhat.com>
-#
-# see file 'COPYING' for use and warranty information
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
+# Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING
 
 from lxml import html
 import requests
@@ -46,7 +30,7 @@ class PageTree(object):
 
     def first_value(self, rule):
         result = self.tree.xpath(rule)
-        if type(result) is list:
+        if isinstance(result, list):
             if len(result) > 0:
                 result = result[0]
             else:
@@ -55,7 +39,7 @@ class PageTree(object):
 
     def all_values(self, rule):
         result = self.tree.xpath(rule)
-        if type(result) is list:
+        if isinstance(result, list):
             return result
         return [result]
 
@@ -137,7 +121,7 @@ class HttpSessions(object):
         return values
 
     def handle_login_form(self, idp, page):
-        if type(page) != PageTree:
+        if not isinstance(page, PageTree):
             raise TypeError("Expected PageTree object")
 
         srv = self.servers[idp]
@@ -167,7 +151,7 @@ class HttpSessions(object):
                 {'headers': headers, 'data': payload}]
 
     def handle_return_form(self, page):
-        if type(page) != PageTree:
+        if not isinstance(page, PageTree):
             raise TypeError("Expected PageTree object")
 
         try:
@@ -193,7 +177,7 @@ class HttpSessions(object):
                 {'headers': headers, 'data': payload}]
 
     def handle_openid_form(self, page):
-        if type(page) != PageTree:
+        if not isinstance(page, PageTree):
             raise TypeError("Expected PageTree object")
 
         if not page.first_value('//title/text()') == \
@@ -223,7 +207,7 @@ class HttpSessions(object):
                 {'headers': headers, 'data': payload}]
 
     def handle_openid_consent_form(self, page):
-        if type(page) != PageTree:
+        if not isinstance(page, PageTree):
             raise TypeError("Expected PageTree object")
 
         try:
@@ -316,7 +300,7 @@ class HttpSessions(object):
                 raise ValueError("Unhandled status (%d) on url %s" % (
                                  r.status_code, url))
 
-    def auth_to_idp(self, idp, krb=False):
+    def auth_to_idp(self, idp, krb=False, rule=None, expected=None):
 
         srv = self.servers[idp]
         target_url = '%s/%s/' % (srv['baseuri'], idp)
@@ -332,8 +316,12 @@ class HttpSessions(object):
 
         page = self.fetch_page(idp, url, krb=krb)
 
-        page.expected_value('//div[@id="welcome"]/p/text()',
-                            'Welcome %s!' % srv['user'])
+        if rule is None:
+            rule = '//div[@id="welcome"]/p/text()'
+        if expected is None:
+            expected = 'Welcome %s!' % srv['user']
+
+        page.expected_value(rule, expected)
 
     def logout_from_idp(self, idp):
 
@@ -359,7 +347,13 @@ class HttpSessions(object):
         headers = {'referer': url}
         if rest:
             expected_status = 201
-            payload = {'metadata': m.content}
+            payload = {
+                'metadata': m.content,
+                'visible': True,
+                'description': sp,
+                'image': 'Zm9v',
+                'splink': 'http://test.example.com/secret/',
+            }
             headers['content-type'] = 'application/x-www-form-urlencoded'
             url = '%s/%s/rest/providers/saml2/SPS/%s' % (idpuri, idp, sp)
             r = self.post(url, headers=headers, data=urlencode(payload))