Move parsing code into helpers module
[cascardo/ipsilon.git] / tests / test1.py
1 #!/usr/bin/python
2 #
3 # Copyright (C) 2014  Simo Sorce <simo@redhat.com>
4 #
5 # see file 'COPYING' for use and warranty information
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21 from helpers import http  # pylint: disable=relative-import
22 import os
23 import pwd
24 import sys
25
26
27 if __name__ == '__main__':
28     basedir = sys.argv[1]
29
30     idpname = 'idp1'
31     spname = 'sp1'
32     user = pwd.getpwuid(os.getuid())[0]
33
34     sess = http.HttpSessions()
35     sess.add_server(idpname, 'http://127.0.0.10:45080', user, 'ipsilon')
36     sess.add_server(spname, 'http://127.0.0.11:45081')
37
38     print "test1: Authenticate to IDP ...",
39     try:
40         sess.auth_to_idp(idpname)
41     except Exception, e:  # pylint: disable=broad-except
42         print >> sys.stderr, " ERROR: %s" % repr(e)
43         sys.exit(1)
44     print " SUCCESS"
45
46     print "test1: Add SP Metadata to IDP ...",
47     try:
48         sess.add_sp_metadata(idpname, spname)
49     except Exception, e:  # pylint: disable=broad-except
50         print >> sys.stderr, " ERROR: %s" % repr(e)
51         sys.exit(1)
52     print " SUCCESS"
53
54     print "test1: Access SP Protected Area ...",
55     try:
56         page = sess.fetch_page(idpname, 'http://127.0.0.11:45081/sp/')
57         page.expected_value('text()', 'WORKS!')
58     except ValueError, e:
59         print >> sys.stderr, " ERROR: %s" % repr(e)
60         sys.exit(1)
61     print " SUCCESS"