summaryrefslogtreecommitdiff
path: root/tests/test_05_md.py
blob: f0a8ef0357f6c05e571a5d9317947d001d62f138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009 UmeƄ University.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for saml2.md"""

__author__ = 'roland.hedberg@umu.se (Roland Hedberg)'

import unittest
try:
  from xml.etree import ElementTree
except ImportError:
  from elementtree import ElementTree

import saml2
import xmldsig as ds

from saml2 import saml
from saml2 import samlp
from saml2 import md 
from saml2.extension import idpdisc
from saml2.extension import shibmd

from saml2 import extension_element_to_element
import md_data, ds_data

class TestEndpointType:

  def setup_class(self):
    self.endpoint = md.EndpointType_()

  def testAccessors(self):
    """Test for EndpointType accessors"""
    self.endpoint.binding = saml2.BINDING_HTTP_POST
    self.endpoint.location = "http://www.example.com/endpoint"
    self.endpoint.response_location = "http://www.example.com/response"
    print self.endpoint.__class__.c_attributes.items()
    new_endpoint = md.endpoint_type__from_string(self.endpoint.to_string())
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"

  def testUsingTestData(self):
    """Test for endpoint_type_from_string() using test data."""
    new_endpoint = md.endpoint_type__from_string(md_data.TEST_ENDPOINT)
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"
    

class TestIndexedEndpointType:

  def setup_class(self):
    self.i_e = md.IndexedEndpointType_()

  def testAccessors(self):
    """Test for IndexedEndpointType accessors"""
    self.i_e.binding = saml2.BINDING_HTTP_POST
    self.i_e.location = "http://www.example.com/endpoint"
    self.i_e.response_location = "http://www.example.com/response"
    self.i_e.index = "1"
    self.i_e.is_default = "false"
    new_i_e = md.indexed_endpoint_type__from_string(self.i_e.to_string())
    assert new_i_e.binding == saml2.BINDING_HTTP_POST
    assert new_i_e.location == "http://www.example.com/endpoint"
    assert new_i_e.response_location == "http://www.example.com/response"
    assert new_i_e.index == "1"
    assert new_i_e.is_default == "false"

  def testUsingTestData(self):
    """Test for indexed_endpoint_type_from_string() using test data."""
    new_i_e = md.indexed_endpoint_type__from_string(md_data.TEST_INDEXED_ENDPOINT)
    assert new_i_e.binding == saml2.BINDING_HTTP_POST
    assert new_i_e.location == "http://www.example.com/endpoint"
    assert new_i_e.response_location == "http://www.example.com/response"
    assert new_i_e.index == "1"
    assert new_i_e.is_default == "false"


class TestExtensions:

  def setup_class(self):
    self.extensions = md.Extensions()

  def testAccessors(self):
    """Test for Extensions accessors"""
    self.extensions.extension_elements.append(
      saml2.extension_element_from_string(
      """<?xml version='1.0' encoding='UTF-8'?>
      <hoge>fuga</hoge>
      """))
    new_extensions = md.extensions_from_string(self.extensions.to_string())
    assert new_extensions.extension_elements[0].tag == "hoge"
    assert new_extensions.extension_elements[0].text.strip() == "fuga"


class TestOrganizationName:

  def setup_class(self):
    self.organization_name = md.OrganizationName()

  def testAccessors(self):
    """Test for OrganizationName accessors"""
    self.organization_name.lang = "en"
    self.organization_name.text = "SIOS Technology, Inc."
    new_organization_name = md.organization_name_from_string(
      self.organization_name.to_string())
    assert new_organization_name.lang == "en"
    assert new_organization_name.text.strip() == "SIOS Technology, Inc."

  def testUsingTestData(self):
    """Test for organization_name_from_string() using test data."""
    new_organization_name = md.organization_name_from_string(
      md_data.TEST_ORGANIZATION_NAME)
    print new_organization_name.keyswv()
    assert new_organization_name.lang == "se"
    assert new_organization_name.text.strip() == "Catalogix"


class TestOrganizationDisplayName:

  def setup_class(self):
    self.od_name = md.OrganizationDisplayName()

  def testAccessors(self):
    """Test for OrganizationDisplayName accessors"""
    self.od_name.lang = "en"
    self.od_name.text = "SIOS"
    new_od_name = md.organization_display_name_from_string(
      self.od_name.to_string())
    assert new_od_name.lang == "en"
    assert new_od_name.text.strip() == "SIOS"

  def testUsingTestData(self):
    """Test for organization_display_name_from_string() using test data."""
    new_od_name = md.organization_display_name_from_string(
      md_data.TEST_ORGANIZATION_DISPLAY_NAME)
    assert new_od_name.lang == "se"
    assert new_od_name.text.strip() == "Catalogix"


class TestOrganizationURL:

  def setup_class(self):
    self.organization_url = md.OrganizationURL()

  def testAccessors(self):
    """Test for OrganizationURL accessors"""
    self.organization_url.lang = "ja"
    self.organization_url.text = "http://www.example.com/"
    print self.organization_url.to_string()
    new_organization_url = md.organization_url_from_string(
      self.organization_url.to_string())
    assert new_organization_url.lang == "ja"
    assert new_organization_url.text.strip() == "http://www.example.com/"

  def testUsingTestData(self):
    """Test for organization_url_from_string() using test data."""
    new_organization_url = md.organization_url_from_string(
      md_data.TEST_ORGANIZATION_URL)
    assert new_organization_url.lang == "no"
    assert new_organization_url.text.strip() == "http://www.example.com/"


class TestOrganization:

  def setup_class(self):
    self.organization = md.Organization()

  def testAccessors(self):
    """Test for Organization accessors"""
    self.organization.extensions = md.Extensions()
    self.organization.organization_name.append(
      md.organization_name_from_string(md_data.TEST_ORGANIZATION_NAME))
    self.organization.organization_display_name.append(
      md.organization_display_name_from_string(
      md_data.TEST_ORGANIZATION_DISPLAY_NAME))
    self.organization.organization_url.append(
      md.organization_url_from_string(md_data.TEST_ORGANIZATION_URL))
    new_organization = md.organization_from_string(self.organization.to_string())
    assert isinstance(new_organization.extensions, md.Extensions)
    assert isinstance(new_organization.organization_name[0],
                            md.OrganizationName)
    assert isinstance(new_organization.organization_display_name[0],
                            md.OrganizationDisplayName)
    assert isinstance(new_organization.organization_url[0],
                            md.OrganizationURL)
    assert new_organization.organization_name[0].text.strip() == "Catalogix"
    assert new_organization.organization_name[0].lang == "se"
    assert new_organization.organization_display_name[0].text.strip() == "Catalogix"
    assert new_organization.organization_display_name[0].lang == "se"
    assert new_organization.organization_url[0].text.strip() == "http://www.example.com/"
    assert new_organization.organization_url[0].lang == "no"
    

  def testUsingTestData(self):
    """Test for organization_from_string() using test data."""
    new_organization = md.organization_from_string(
      md_data.TEST_ORGANIZATION)
    assert isinstance(new_organization.extensions, md.Extensions)
    assert isinstance(new_organization.organization_name[0],
                            md.OrganizationName)
    assert isinstance(new_organization.organization_display_name[0],
                            md.OrganizationDisplayName)
    assert isinstance(new_organization.organization_url[0],
                            md.OrganizationURL)
    assert new_organization.organization_name[0].text.strip() == "Catalogix AB"
    assert new_organization.organization_name[0].lang == "se"
    assert new_organization.organization_display_name[0].text.strip() == "Catalogix AS"
    assert new_organization.organization_display_name[0].lang == "no"
    assert new_organization.organization_url[0].text.strip() == "http://www.example.com/"
    assert new_organization.organization_url[0].lang == "en"


class TestContactPerson:

  def setup_class(self):
    self.contact_person = md.ContactPerson()

  def testAccessors(self):
    """Test for ContactPerson accessors"""
    self.contact_person.contact_type = "technical"
    self.contact_person.extensions = md.Extensions()
    self.contact_person.company = md.Company(text="SIOS Technology, Inc.")
    self.contact_person.given_name = md.GivenName(text="Takashi")
    self.contact_person.sur_name = md.SurName(text="Matsuo")
    self.contact_person.email_address.append(
      md.EmailAddress(text="tmatsuo@example.com"))
    self.contact_person.email_address.append(
      md.EmailAddress(text="tmatsuo@shehas.net"))
    self.contact_person.telephone_number.append(
      md.TelephoneNumber(text="00-0000-0000"))
    new_contact_person = md.contact_person_from_string(
      self.contact_person.to_string())
    assert new_contact_person.contact_type == "technical"
    assert isinstance(new_contact_person.extensions, md.Extensions)
    assert new_contact_person.company.text.strip() == "SIOS Technology, Inc."
    assert new_contact_person.given_name.text.strip() == "Takashi"
    assert new_contact_person.sur_name.text.strip() == "Matsuo"
    assert new_contact_person.email_address[0].text.strip() == "tmatsuo@example.com"
    assert new_contact_person.email_address[1].text.strip() == "tmatsuo@shehas.net"
    assert new_contact_person.telephone_number[0].text.strip() == "00-0000-0000"

  def testUsingTestData(self):
    """Test for contact_person_from_string() using test data."""
    new_contact_person = md.contact_person_from_string(
      md_data.TEST_CONTACT_PERSON)
    assert new_contact_person.contact_type == "technical"
    assert isinstance(new_contact_person.extensions, md.Extensions)
    assert new_contact_person.company.text.strip() == "SIOS Technology, Inc."
    assert new_contact_person.given_name.text.strip() == "Takashi"
    assert new_contact_person.sur_name.text.strip() == "Matsuo"
    assert new_contact_person.email_address[0].text.strip() == "tmatsuo@example.com"
    assert new_contact_person.email_address[1].text.strip() == "tmatsuo@shehas.net"
    assert new_contact_person.telephone_number[0].text.strip() == "00-0000-0000"

class TestAdditionalMetadataLocation:

  def setup_class(self):
    self.additional_metadata_location = md.AdditionalMetadataLocation()

  def testAccessors(self):
    """Test for AdditionalMetadataLocation accessors"""
    self.additional_metadata_location.namespace = (
      "http://www.example.com/namespace")
    self.additional_metadata_location.text = (
      "http://www.example.com/AdditionalMetadataLocation")
    new_additional_metadata_location = md.additional_metadata_location_from_string(
      self.additional_metadata_location.to_string())
    assert new_additional_metadata_location.namespace == "http://www.example.com/namespace"
    assert new_additional_metadata_location.text.strip() == "http://www.example.com/AdditionalMetadataLocation"

  def testUsingTestData(self):
    """Test for additional_metadata_location_from_string() using test data."""
    new_additional_metadata_location = md.additional_metadata_location_from_string(
      md_data.TEST_ADDITIONAL_METADATA_LOCATION)
    assert new_additional_metadata_location.namespace == "http://www.example.com/namespace"
    assert new_additional_metadata_location.text.strip() == "http://www.example.com/AdditionalMetadataLocation"

# class TestKeySize:
# 
#   def setup_class(self):
#     self.key_size = md.KeySize()
# 
#   def testAccessors(self):
#     """Test for KeySize accessors"""
#     self.key_size.text = "128"
#     new_key_size = md.key_size_from_string(self.key_size.to_string())
#     assert new_key_size.text.strip() == "128"
# 
#   def testUsingTestData(self):
#     """Test for key_size_from_string() using test data."""
#     new_key_size = md.key_size_from_string(md_data.TEST_KEY_SIZE)
#     assert new_key_size.text.strip() == "128"
    

# class TestOAEPparams:
# 
#   def setup_class(self):
#     self.oaep_params = md.OAEPparams()
# 
#   def testAccessors(self):
#     """Test for OAEPparams accessors"""
#     self.oaep_params.text = "9lWu3Q=="
#     new_oaep_params = md.oae_pparams_from_string(self.oaep_params.to_string())
#     assert new_oaep_params.text.strip() == "9lWu3Q=="
# 
#   def testUsingTestData(self):
#     """Test for oae_pparams_from_string() using test data."""
#     new_oaep_params = md.oae_pparams_from_string(md_data.TEST_OAEP_PARAMS)
#     assert new_oaep_params.text.strip() == "9lWu3Q=="


class TestEncryptionMethod:

  def setup_class(self):
    self.encryption_method = md.EncryptionMethod()

  def testAccessors(self):
    """Test for EncryptionMethod accessors"""
    self.encryption_method.algorithm = (
      "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p")
    new_encryption_method = md.encryption_method_from_string(
      self.encryption_method.to_string())
    assert new_encryption_method.algorithm == "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"

  def testUsingTestData(self):
    """Test for encryption_method_from_string() using test data."""
    new_encryption_method = md.encryption_method_from_string(
      md_data.TEST_ENCRYPTION_METHOD)
    assert new_encryption_method.algorithm == "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"
    assert new_encryption_method.oae_pparams.text.strip() == "9lWu3Q=="


class TestKeyDescriptor:

  def setup_class(self):
    self.key_descriptor = md.KeyDescriptor()

  def testAccessors(self):
    """Test for KeyDescriptor accessors"""

    self.key_descriptor.use = "signing"
    self.key_descriptor.key_info = ds.key_info_from_string(
      ds_data.TEST_KEY_INFO)
    self.key_descriptor.encryption_method.append(md.encryption_method_from_string(
      md_data.TEST_ENCRYPTION_METHOD))
    new_key_descriptor = md.key_descriptor_from_string(
      self.key_descriptor.to_string())
    assert new_key_descriptor.use == "signing"
    assert isinstance(new_key_descriptor.key_info, ds.KeyInfo)
    assert isinstance(new_key_descriptor.encryption_method[0], 
                            md.EncryptionMethod)

  def testUsingTestData(self):
    """Test for key_descriptor_from_string() using test data."""
    new_key_descriptor = md.key_descriptor_from_string(
      md_data.TEST_KEY_DESCRIPTOR)
    assert new_key_descriptor.use == "signing"
    assert isinstance(new_key_descriptor.key_info, ds.KeyInfo)
    assert isinstance(new_key_descriptor.encryption_method[0],
                            md.EncryptionMethod)


class TestRoleDescriptor:
  def setup_class(self):
    self.role_descriptor = md.RoleDescriptor()

  def testAccessors(self):
    """Test for RoleDescriptor accessors"""
    self.role_descriptor.id = "ID"
    self.role_descriptor.valid_until = "2008-09-14T01:05:02Z"
    self.role_descriptor.cache_duration = "10:00:00:00"
    self.role_descriptor.protocol_support_enumeration = samlp.NAMESPACE
    self.role_descriptor.error_url = "http://www.example.com/errorURL"
    self.role_descriptor.signature = ds.Signature()
    self.role_descriptor.extensions = md.Extensions()
    self.role_descriptor.key_descriptor.append(md.key_descriptor_from_string(
      md_data.TEST_KEY_DESCRIPTOR))
    self.role_descriptor.organization = md.Organization()
    self.role_descriptor.contact_person.append(md.ContactPerson())

    new_role_descriptor = md.role_descriptor_from_string(
      self.role_descriptor.to_string())
    assert new_role_descriptor.id == "ID"
    assert new_role_descriptor.valid_until == "2008-09-14T01:05:02Z"
    assert new_role_descriptor.cache_duration == "10:00:00:00"
    assert new_role_descriptor.protocol_support_enumeration == samlp.NAMESPACE
    assert new_role_descriptor.error_url == "http://www.example.com/errorURL"
    assert isinstance(new_role_descriptor.signature, ds.Signature)
    assert isinstance(new_role_descriptor.extensions, md.Extensions)
    assert isinstance(new_role_descriptor.key_descriptor[0],
                            md.KeyDescriptor)
    assert isinstance(new_role_descriptor.organization, md.Organization)
    assert isinstance(new_role_descriptor.contact_person[0],
                            md.ContactPerson)

  def testUsingTestData(self):
    """Test for role_descriptor_from_string() using test data."""
    new_role_descriptor = md.role_descriptor_from_string(
      md_data.TEST_ROLE_DESCRIPTOR)
    assert new_role_descriptor.id == "ID"
    assert new_role_descriptor.valid_until == "2008-09-14T01:05:02Z"
    assert new_role_descriptor.cache_duration == "10:00:00:00"
    assert new_role_descriptor.protocol_support_enumeration == samlp.NAMESPACE
    assert new_role_descriptor.error_url == "http://www.example.com/errorURL"
    assert isinstance(new_role_descriptor.signature, ds.Signature)
    assert isinstance(new_role_descriptor.extensions, md.Extensions)
    assert isinstance(new_role_descriptor.key_descriptor[0],
                            md.KeyDescriptor)
    assert isinstance(new_role_descriptor.organization, md.Organization)
    assert isinstance(new_role_descriptor.contact_person[0],
                            md.ContactPerson)

# class TestSSODescriptor:
#   def setup_class(self):
#     self.sso_descriptor = md.SSODescriptorType_()
# 
#   def testAccessors(self):
#     """Test for SSODescriptorType accessors"""
#     self.sso_descriptor.id = "ID"
#     self.sso_descriptor.valid_until = "2008-09-14T01:05:02Z"
#     self.sso_descriptor.cache_duration = "10:00:00:00"
#     self.sso_descriptor.protocol_support_enumeration = samlp.NAMESPACE
#     self.sso_descriptor.error_url = "http://www.example.com/errorURL"
#     self.sso_descriptor.signature = ds.Signature()
#     self.sso_descriptor.extensions = md.Extensions()
#     self.sso_descriptor.key_descriptor.append(md.key_descriptor_from_string(
#       md_data.TEST_KEY_DESCRIPTOR))
#     self.sso_descriptor.organization = md.Organization()
#     self.sso_descriptor.contact_person.append(md.ContactPerson())
#     self.sso_descriptor.artifact_resolution_service.append(
#       md.ArtifactResolutionService())
#     self.sso_descriptor.single_logout_service.append(
#       md.SingleLogoutService())
#     self.sso_descriptor.manage_name_id_service.append(
#       md.ManageNameIDService())
#     self.sso_descriptor.name_id_format.append(
#       md.NameIDFormat())
# 
#     new_sso_descriptor = md.sso_descriptor_type__from_string(
#       self.sso_descriptor.to_string())
#     assert new_sso_descriptor.id == "ID"
#     assert new_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
#     assert new_sso_descriptor.cache_duration == "10:00:00:00"
#     assert new_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
#     assert new_sso_descriptor.error_url == "http://www.example.com/errorURL"
#     assert isinstance(new_sso_descriptor.signature, ds.Signature)
#     assert isinstance(new_sso_descriptor.extensions, md.Extensions)
#     assert isinstance(new_sso_descriptor.key_descriptor[0],
#                             md.KeyDescriptor)
#     assert isinstance(new_sso_descriptor.organization, md.Organization)
#     assert isinstance(new_sso_descriptor.contact_person[0],
#                             md.ContactPerson)
#     assert isinstance(new_sso_descriptor.artifact_resolution_service[0],
#                             md.ArtifactResolutionService)
#     assert isinstance(new_sso_descriptor.single_logout_service[0],
#                             md.SingleLogoutService)
#     assert isinstance(new_sso_descriptor.manage_name_id_service[0],
#                             md.ManageNameIDService)
#     assert isinstance(new_sso_descriptor.name_id_format[0],
#                             md.NameIDFormat)
# 

class TestArtifactResolutionService:

  def setup_class(self):
    self.i_e = md.ArtifactResolutionService()

  def testAccessors(self):
    """Test for ArtifactResolutionService accessors"""
    self.i_e.binding = saml2.BINDING_HTTP_POST
    self.i_e.location = "http://www.example.com/endpoint"
    self.i_e.response_location = "http://www.example.com/response"
    self.i_e.index = "1"
    self.i_e.is_default = "false"
    new_i_e = md.artifact_resolution_service_from_string(self.i_e.to_string())
    assert new_i_e.binding == saml2.BINDING_HTTP_POST
    assert new_i_e.location == "http://www.example.com/endpoint"
    assert new_i_e.response_location == "http://www.example.com/response"
    assert new_i_e.index == "1"
    assert new_i_e.is_default == "false"

  def testUsingTestData(self):
    """Test for artifact_resolution_service_from_string() using test data."""
    new_i_e = md.artifact_resolution_service_from_string(
      md_data.TEST_ARTIFACT_RESOLUTION_SERVICE)
    assert new_i_e.binding == saml2.BINDING_HTTP_POST
    assert new_i_e.location == "http://www.example.com/endpoint"
    assert new_i_e.response_location == "http://www.example.com/response"
    assert new_i_e.index == "1"
    assert new_i_e.is_default == "false"


class TestSingleLogout:

  def setup_class(self):
    self.endpoint = md.SingleLogoutService()

  def testAccessors(self):
    """Test for SingleLogoutService accessors"""
    self.endpoint.binding = saml2.BINDING_HTTP_POST
    self.endpoint.location = "http://www.example.com/endpoint"
    self.endpoint.response_location = "http://www.example.com/response"
    new_endpoint = md.single_logout_service_from_string(self.endpoint.to_string())
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"

  def testUsingTestData(self):
    """Test for single_logout_service_from_string() using test data."""
    new_endpoint = md.single_logout_service_from_string(
      md_data.TEST_SINGLE_LOGOUT_SERVICE)
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"
    

class TestManageNameIDService:

  def setup_class(self):
    self.endpoint = md.ManageNameIDService()

  def testAccessors(self):
    """Test for ManageNameIDService accessors"""
    self.endpoint.binding = saml2.BINDING_HTTP_POST
    self.endpoint.location = "http://www.example.com/endpoint"
    self.endpoint.response_location = "http://www.example.com/response"
    new_endpoint = md.manage_name_id_service_from_string(self.endpoint.to_string())
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"

  def testUsingTestData(self):
    """Test for manage_name_id_service_from_string() using test data."""
    new_endpoint = md.manage_name_id_service_from_string(
      md_data.TEST_MANAGE_NAMEID_SERVICE)
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"
    

class TestNameIDFormat:

  def setup_class(self):
    self.name_id_format = md.NameIDFormat()

  def testAccessors(self):
    """Test for NameIDFormat accessors"""
    self.name_id_format.text = saml.NAMEID_FORMAT_EMAILADDRESS
    new_name_id_format = md.name_id_format_from_string(
      self.name_id_format.to_string())
    assert new_name_id_format.text.strip() == saml.NAMEID_FORMAT_EMAILADDRESS

  def testUsingTestData(self):
    """Test for name_id_format_from_string() using test data."""
    new_name_id_format = md.name_id_format_from_string(
      md_data.TEST_NAME_ID_FORMAT)
    assert new_name_id_format.text.strip() == saml.NAMEID_FORMAT_EMAILADDRESS
  

class TestSingleSignOnService:

  def setup_class(self):
    self.endpoint = md.SingleSignOnService()

  def testAccessors(self):
    """Test for SingelSignOnService accessors"""
    self.endpoint.binding = saml2.BINDING_HTTP_POST
    self.endpoint.location = "http://www.example.com/endpoint"
    self.endpoint.response_location = "http://www.example.com/response"
    new_endpoint = md.single_sign_on_service_from_string(self.endpoint.to_string())
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"

  def testUsingTestData(self):
    """Test for SingelSignOn_service_from_string() using test data."""
    new_endpoint = md.single_sign_on_service_from_string(
      md_data.TEST_SINGLE_SIGN_ON_SERVICE)
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"

class TestNameIDMappingService:

  def setup_class(self):
    self.endpoint = md.NameIDMappingService()

  def testAccessors(self):
    """Test for NameIDMappingService accessors"""
    self.endpoint.binding = saml2.BINDING_HTTP_POST
    self.endpoint.location = "http://www.example.com/endpoint"
    self.endpoint.response_location = "http://www.example.com/response"
    new_endpoint = md.name_id_mapping_service_from_string(self.endpoint.to_string())
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"

  def testUsingTestData(self):
    """Test for name_id_mapping_service_from_string() using test data."""
    new_endpoint = md.name_id_mapping_service_from_string(
      md_data.TEST_NAME_ID_MAPPING_SERVICE)
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"

class TestAssertionIDRequestService:

  def setup_class(self):
    self.endpoint = md.AssertionIDRequestService()

  def testAccessors(self):
    """Test for AssertionIDRequestService accessors"""
    self.endpoint.binding = saml2.BINDING_HTTP_POST
    self.endpoint.location = "http://www.example.com/endpoint"
    self.endpoint.response_location = "http://www.example.com/response"
    new_endpoint = md.assertion_id_request_service_from_string(
      self.endpoint.to_string())
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"

  def testUsingTestData(self):
    """Test for assertion_id_request_service_from_string() using test data."""
    new_endpoint = md.assertion_id_request_service_from_string(
      md_data.TEST_ASSERTION_ID_REQUEST_SERVICE)
    assert new_endpoint.binding == saml2.BINDING_HTTP_POST
    assert new_endpoint.location == "http://www.example.com/endpoint"
    assert new_endpoint.response_location == "http://www.example.com/response"

class TestAttributeProfile:

  def setup_class(self):
    self.attribute_profile = md.AttributeProfile()

  def testAccessors(self):
    """Test for AttributeProfile accessors"""
    self.attribute_profile.text = saml.PROFILE_ATTRIBUTE_BASIC
    new_attribute_profile = md.attribute_profile_from_string(
      self.attribute_profile.to_string())
    assert new_attribute_profile.text.strip() == saml.PROFILE_ATTRIBUTE_BASIC

  def testUsingTestData(self):
    """Test for name_id_format_from_string() using test data."""
    new_attribute_profile = md.attribute_profile_from_string(
      md_data.TEST_ATTRIBUTE_PROFILE)
    assert new_attribute_profile.text.strip() == saml.PROFILE_ATTRIBUTE_BASIC
  

class TestIDPSSODescriptor:
  def setup_class(self):
    self.idp_sso_descriptor = md.IDPSSODescriptor()

  def testAccessors(self):
    """Test for IDPSSODescriptor accessors"""
    self.idp_sso_descriptor.id = "ID"
    self.idp_sso_descriptor.valid_until = "2008-09-14T01:05:02Z"
    self.idp_sso_descriptor.cache_duration = "10:00:00:00"
    self.idp_sso_descriptor.protocol_support_enumeration = \
                                                         samlp.NAMESPACE
    self.idp_sso_descriptor.error_url = "http://www.example.com/errorURL"
    self.idp_sso_descriptor.signature = ds.Signature()
    self.idp_sso_descriptor.extensions = md.Extensions()
    self.idp_sso_descriptor.key_descriptor.append(md.key_descriptor_from_string(
      md_data.TEST_KEY_DESCRIPTOR))
    self.idp_sso_descriptor.organization = md.Organization()
    self.idp_sso_descriptor.contact_person.append(md.ContactPerson())
    self.idp_sso_descriptor.artifact_resolution_service.append(
      md.ArtifactResolutionService())
    self.idp_sso_descriptor.single_logout_service.append(
      md.SingleLogoutService())
    self.idp_sso_descriptor.manage_name_id_service.append(
      md.ManageNameIDService())
    self.idp_sso_descriptor.name_id_format.append(
      md.NameIDFormat())
    self.idp_sso_descriptor.want_authn_requests_signed = 'true'
    self.idp_sso_descriptor.single_sign_on_service.append(
      md.SingleSignOnService())
    self.idp_sso_descriptor.name_id_mapping_service.append(
      md.NameIDMappingService())
    self.idp_sso_descriptor.assertion_id_request_service.append(
      md.AssertionIDRequestService())
    self.idp_sso_descriptor.attribute_profile.append(
      md.AttributeProfile())
    self.idp_sso_descriptor.attribute.append(saml.Attribute())

    new_idp_sso_descriptor = md.idpsso_descriptor_from_string(
      self.idp_sso_descriptor.to_string())
    assert new_idp_sso_descriptor.id == "ID"
    assert new_idp_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
    assert new_idp_sso_descriptor.cache_duration == "10:00:00:00"
    assert new_idp_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
    assert new_idp_sso_descriptor.error_url == "http://www.example.com/errorURL"
    assert isinstance(new_idp_sso_descriptor.signature, ds.Signature)
    assert isinstance(new_idp_sso_descriptor.extensions, md.Extensions)
    assert isinstance(new_idp_sso_descriptor.key_descriptor[0],
                            md.KeyDescriptor)
    assert isinstance(new_idp_sso_descriptor.organization,
                            md.Organization)
    assert isinstance(new_idp_sso_descriptor.contact_person[0],
                            md.ContactPerson)
    assert isinstance(
      new_idp_sso_descriptor.artifact_resolution_service[0],
      md.ArtifactResolutionService)
    assert isinstance(new_idp_sso_descriptor.single_logout_service[0],
                            md.SingleLogoutService)
    assert isinstance(new_idp_sso_descriptor.manage_name_id_service[0],
                            md.ManageNameIDService)
    assert isinstance(new_idp_sso_descriptor.name_id_format[0],
                            md.NameIDFormat)
    assert new_idp_sso_descriptor.want_authn_requests_signed == "true"
    assert isinstance(new_idp_sso_descriptor.single_sign_on_service[0],
                            md.SingleSignOnService)
    assert isinstance(new_idp_sso_descriptor.name_id_mapping_service[0],
                            md.NameIDMappingService)
    assert isinstance(
      new_idp_sso_descriptor.assertion_id_request_service[0],
      md.AssertionIDRequestService)
    assert isinstance(new_idp_sso_descriptor.attribute_profile[0],
                            md.AttributeProfile)
    assert isinstance(new_idp_sso_descriptor.attribute[0],
                            saml.Attribute)

  def testUsingTestData(self):
    """Test for idpsso_descriptor_from_string() using test data."""
    new_idp_sso_descriptor = md.idpsso_descriptor_from_string(
      md_data.TEST_IDP_SSO_DESCRIPTOR)
    assert new_idp_sso_descriptor.id == "ID"
    assert new_idp_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
    assert new_idp_sso_descriptor.cache_duration == "10:00:00:00"
    assert new_idp_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
    assert new_idp_sso_descriptor.error_url == "http://www.example.com/errorURL"
    assert isinstance(new_idp_sso_descriptor.signature, ds.Signature)
    assert isinstance(new_idp_sso_descriptor.extensions, md.Extensions)
    assert isinstance(new_idp_sso_descriptor.key_descriptor[0],
                            md.KeyDescriptor)
    assert isinstance(new_idp_sso_descriptor.organization,
                            md.Organization)
    assert isinstance(new_idp_sso_descriptor.contact_person[0],
                            md.ContactPerson)
    assert isinstance(
      new_idp_sso_descriptor.artifact_resolution_service[0],
      md.ArtifactResolutionService)
    assert isinstance(new_idp_sso_descriptor.single_logout_service[0],
                            md.SingleLogoutService)
    assert isinstance(new_idp_sso_descriptor.manage_name_id_service[0],
                            md.ManageNameIDService)
    assert isinstance(new_idp_sso_descriptor.name_id_format[0],
                            md.NameIDFormat)
    assert new_idp_sso_descriptor.want_authn_requests_signed == "true"
    assert isinstance(new_idp_sso_descriptor.single_sign_on_service[0],
                            md.SingleSignOnService)
    assert isinstance(new_idp_sso_descriptor.name_id_mapping_service[0],
                            md.NameIDMappingService)
    assert isinstance(
      new_idp_sso_descriptor.assertion_id_request_service[0],
      md.AssertionIDRequestService)
    assert isinstance(new_idp_sso_descriptor.attribute_profile[0],
                            md.AttributeProfile)
    assert isinstance(new_idp_sso_descriptor.attribute[0],
                            saml.Attribute)

  def testUsingScope(self):
      descriptor = md.IDPSSODescriptor()
      scope = shibmd.Scope()
      scope.text = "example.org"
      scope.regexp = "false"
      descriptor.extensions = md.Extensions()
      ext = saml2.element_to_extension_element(scope)
      descriptor.extensions.extension_elements.append(ext)
      exts = descriptor.extensions
      assert len(exts.extension_elements) == 1
      elem = exts.extension_elements[0]
      inst = saml2.extension_element_to_element(elem,
                                                shibmd.ELEMENT_FROM_STRING,
                                                namespace=shibmd.NAMESPACE)
      assert isinstance(inst, shibmd.Scope)
      assert inst.text == "example.org"
      assert inst.regexp == "false"
      
class TestAssertionConsumerService:

  def setup_class(self):
    self.i_e = md.AssertionConsumerService()

  def testAccessors(self):
    """Test for AssertionConsumerService accessors"""
    self.i_e.binding = saml2.BINDING_HTTP_POST
    self.i_e.location = "http://www.example.com/endpoint"
    self.i_e.response_location = "http://www.example.com/response"
    self.i_e.index = "1"
    self.i_e.is_default = "false"
    new_i_e = md.assertion_consumer_service_from_string(self.i_e.to_string())
    assert new_i_e.binding == saml2.BINDING_HTTP_POST
    assert new_i_e.location == "http://www.example.com/endpoint"
    assert new_i_e.response_location == "http://www.example.com/response"
    assert new_i_e.index == "1"
    assert new_i_e.is_default == "false"

  def testUsingTestData(self):
    """Test for assertion_consumer_service_from_string() using test data."""
    new_i_e = md.assertion_consumer_service_from_string(
      md_data.TEST_ASSERTION_CONSUMER_SERVICE)
    assert new_i_e.binding == saml2.BINDING_HTTP_POST
    assert new_i_e.location == "http://www.example.com/endpoint"
    assert new_i_e.response_location == "http://www.example.com/response"
    assert new_i_e.index == "1"
    assert new_i_e.is_default == "false"


class TestRequestedAttribute:

  def setup_class(self):
    self.requested_attribute = md.RequestedAttribute()

  def testAccessors(self):
    """Test for RequestedAttribute accessors"""
    assert isinstance(self.requested_attribute, saml.AttributeType_)
    assert isinstance(self.requested_attribute, md.RequestedAttribute)
    assert self.requested_attribute.is_required is None
    self.requested_attribute.is_required = "true"
    new_requested_attribute = md.requested_attribute_from_string(
      self.requested_attribute.to_string())
    assert new_requested_attribute.is_required == "true"
    assert isinstance(new_requested_attribute, saml.AttributeType_)
    assert isinstance(new_requested_attribute, md.RequestedAttribute)

  def testUsingTestData(self):
    """Test for requested_attribute_from_string() using test data."""
    new_requested_attribute = md.requested_attribute_from_string(
      md_data.TEST_REQUESTED_ATTRIBUTE)
    assert new_requested_attribute.is_required == "true"
    assert isinstance(new_requested_attribute, saml.AttributeType_)
    assert isinstance(new_requested_attribute, md.RequestedAttribute)


class TestServiceName:

  def setup_class(self):
    self.service_name = md.ServiceName()

  def testAccessors(self):
    """Test for ServiceName accessors"""
    self.service_name.lang = "en"
    self.service_name.text = "SIOS mail"
    new_service_name = md.service_name_from_string(self.service_name.to_string())
    assert new_service_name.lang == "en"
    assert new_service_name.text.strip() == "SIOS mail"

  def testUsingTestData(self):
    """Test for organization_name_from_string() using test data."""
    new_service_name = md.service_name_from_string(md_data.TEST_SERVICE_NAME)
    assert new_service_name.lang == "en"
    assert new_service_name.text.strip() == "Catalogix Whois"


class TestServiceDescription:

  def setup_class(self):
    self.service_description = md.ServiceDescription()

  def testAccessors(self):
    """Test for ServiceDescription accessors"""
    self.service_description.lang = "en"
    self.service_description.text = "SIOS mail service"
    new_service_description = md.service_description_from_string(
      self.service_description.to_string())
    assert new_service_description.lang == "en"
    assert new_service_description.text.strip() == "SIOS mail service"

  def testUsingTestData(self):
    """Test for organization_name_from_string() using test data."""
    new_service_description = md.service_description_from_string(
      md_data.TEST_SERVICE_DESCRIPTION)
    assert new_service_description.lang == "en"
    assert new_service_description.text.strip() == "Catalogix Whois Service"


class TestAttributeConsumingService:

  def setup_class(self):
    self.attribute_consuming_service = md.AttributeConsumingService()

  def testAccessors(self):
    """Test for AttributeConsumingService accessors"""
    self.attribute_consuming_service.service_name.append(md.ServiceName())
    self.attribute_consuming_service.service_description.append(
      md.ServiceDescription())
    self.attribute_consuming_service.requested_attribute.append(
      md.RequestedAttribute())
    self.attribute_consuming_service.index = "1"
    self.attribute_consuming_service.is_default = "true"

    new_attribute_consuming_service = md.attribute_consuming_service_from_string(
      self.attribute_consuming_service.to_string())
    assert new_attribute_consuming_service.index == "1"
    assert new_attribute_consuming_service.is_default == "true"
    assert isinstance(new_attribute_consuming_service.service_name[0],
                 md.ServiceName)
    assert isinstance(
      new_attribute_consuming_service.service_description[0],
      md.ServiceDescription)
    assert isinstance(
      new_attribute_consuming_service.requested_attribute[0],
      md.RequestedAttribute)

  def testUsingTestData(self):
    """Test for attribute_consuming_service_from_string() using test data."""
    new_attribute_consuming_service = md.attribute_consuming_service_from_string(
      md_data.TEST_ATTRIBUTE_CONSUMING_SERVICE)
    assert new_attribute_consuming_service.index == "1"
    assert new_attribute_consuming_service.is_default == "true"
    assert isinstance(new_attribute_consuming_service.service_name[0],
                 md.ServiceName)
    assert isinstance(
      new_attribute_consuming_service.service_description[0],
      md.ServiceDescription)
    assert isinstance(
      new_attribute_consuming_service.requested_attribute[0],
      md.RequestedAttribute)


class TestSPSSODescriptor:
  def setup_class(self):
    self.sp_sso_descriptor = md.SPSSODescriptor()

  def testAccessors(self):
    """Test for SPSSODescriptor accessors"""
    self.sp_sso_descriptor.id = "ID"
    self.sp_sso_descriptor.valid_until = "2008-09-14T01:05:02Z"
    self.sp_sso_descriptor.cache_duration = "10:00:00:00"
    self.sp_sso_descriptor.protocol_support_enumeration = \
                                                         samlp.NAMESPACE
    self.sp_sso_descriptor.error_url = "http://www.example.com/errorURL"
    self.sp_sso_descriptor.signature = ds.Signature()
    self.sp_sso_descriptor.extensions = md.Extensions()
    self.sp_sso_descriptor.key_descriptor.append(md.key_descriptor_from_string(
      md_data.TEST_KEY_DESCRIPTOR))
    self.sp_sso_descriptor.organization = md.Organization()
    self.sp_sso_descriptor.contact_person.append(md.ContactPerson())
    self.sp_sso_descriptor.artifact_resolution_service.append(
      md.ArtifactResolutionService())
    self.sp_sso_descriptor.single_logout_service.append(
      md.SingleLogoutService())
    self.sp_sso_descriptor.manage_name_id_service.append(
      md.ManageNameIDService())
    self.sp_sso_descriptor.name_id_format.append(
      md.NameIDFormat())
    self.sp_sso_descriptor.authn_requests_signed = "true"
    self.sp_sso_descriptor.want_assertions_signed = "true"
    self.sp_sso_descriptor.assertion_consumer_service.append(
      md.AssertionConsumerService())
    self.sp_sso_descriptor.attribute_consuming_service.append(
      md.AttributeConsumingService())

    print self.sp_sso_descriptor
    new_sp_sso_descriptor = md.spsso_descriptor_from_string(
      self.sp_sso_descriptor.to_string())
    print new_sp_sso_descriptor
    assert new_sp_sso_descriptor.id == "ID"
    assert new_sp_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
    assert new_sp_sso_descriptor.cache_duration == "10:00:00:00"
    assert new_sp_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
    assert new_sp_sso_descriptor.error_url == "http://www.example.com/errorURL"
    assert isinstance(new_sp_sso_descriptor.signature, ds.Signature)
    assert isinstance(new_sp_sso_descriptor.extensions, md.Extensions)
    assert isinstance(new_sp_sso_descriptor.key_descriptor[0],
                            md.KeyDescriptor)
    assert isinstance(new_sp_sso_descriptor.organization,
                            md.Organization)
    assert isinstance(new_sp_sso_descriptor.contact_person[0],
                            md.ContactPerson)
    assert isinstance(
      new_sp_sso_descriptor.artifact_resolution_service[0],
      md.ArtifactResolutionService)
    assert isinstance(new_sp_sso_descriptor.single_logout_service[0],
                            md.SingleLogoutService)
    assert isinstance(new_sp_sso_descriptor.manage_name_id_service[0],
                            md.ManageNameIDService)
    assert isinstance(new_sp_sso_descriptor.name_id_format[0],
                            md.NameIDFormat)
    assert new_sp_sso_descriptor.authn_requests_signed == "true"
    assert new_sp_sso_descriptor.want_assertions_signed == "true"
    assert isinstance(
      new_sp_sso_descriptor.assertion_consumer_service[0],
      md.AssertionConsumerService)
    assert isinstance(
      new_sp_sso_descriptor.attribute_consuming_service[0],
      md.AttributeConsumingService)

  def testUsingTestData(self):
    """Test for spsso_descriptor_from_string() using test data."""
    new_sp_sso_descriptor = md.spsso_descriptor_from_string(
      md_data.TEST_SP_SSO_DESCRIPTOR)
    assert new_sp_sso_descriptor.id == "ID"
    assert new_sp_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
    assert new_sp_sso_descriptor.cache_duration == "10:00:00:00"
    assert new_sp_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
    assert new_sp_sso_descriptor.error_url == "http://www.example.com/errorURL"
    assert isinstance(new_sp_sso_descriptor.signature, ds.Signature)
    assert isinstance(new_sp_sso_descriptor.extensions, md.Extensions)
    print new_sp_sso_descriptor.extensions.__dict__
    assert len(new_sp_sso_descriptor.extensions.extension_elements) == 2
    for eelem in new_sp_sso_descriptor.extensions.extension_elements:
        print "EE",eelem.__dict__
        dp = extension_element_to_element(eelem, idpdisc.ELEMENT_FROM_STRING,
                                            idpdisc.NAMESPACE)
        print "DP",dp.c_tag, dp.c_namespace,dp.__dict__
        assert isinstance(dp, idpdisc.DiscoveryResponse)
    assert isinstance(new_sp_sso_descriptor.key_descriptor[0],
                            md.KeyDescriptor)
    assert isinstance(new_sp_sso_descriptor.organization,
                            md.Organization)
    assert isinstance(new_sp_sso_descriptor.contact_person[0],
                            md.ContactPerson)
    assert isinstance(
      new_sp_sso_descriptor.artifact_resolution_service[0],
      md.ArtifactResolutionService)
    assert isinstance(new_sp_sso_descriptor.single_logout_service[0],
                            md.SingleLogoutService)
    assert isinstance(new_sp_sso_descriptor.manage_name_id_service[0],
                            md.ManageNameIDService)
    assert isinstance(new_sp_sso_descriptor.name_id_format[0],
                            md.NameIDFormat)
    assert new_sp_sso_descriptor.authn_requests_signed == "true"
    assert new_sp_sso_descriptor.want_assertions_signed == "true"
    assert isinstance(
      new_sp_sso_descriptor.assertion_consumer_service[0],
      md.AssertionConsumerService)
    assert isinstance(
      new_sp_sso_descriptor.attribute_consuming_service[0],
      md.AttributeConsumingService)


class TestEntityDescriptor:
  def setup_class(self):
    self.entity_descriptor = md.EntityDescriptor()

  def testAccessors(self):
    """Test for RoleDescriptor accessors"""
    self.entity_descriptor.id = "ID"
    self.entity_descriptor.entity_id = "entityID"
    self.entity_descriptor.valid_until = "2008-09-14T01:05:02Z"
    self.entity_descriptor.cache_duration = "10:00:00:00"

    self.entity_descriptor.signature = ds.Signature()
    self.entity_descriptor.extensions = md.Extensions()
    self.entity_descriptor.role_descriptor.append(md.RoleDescriptor())
    self.entity_descriptor.idpsso_descriptor.append(md.IDPSSODescriptor())
    self.entity_descriptor.spsso_descriptor.append(md.SPSSODescriptor())
    self.entity_descriptor.organization = md.Organization()
    self.entity_descriptor.contact_person.append(md.ContactPerson())
    self.entity_descriptor.additional_metadata_location.append(
      md.AdditionalMetadataLocation())

    new_entity_descriptor = md.entity_descriptor_from_string(
      self.entity_descriptor.to_string())
    assert new_entity_descriptor.id == "ID"
    assert new_entity_descriptor.entity_id == "entityID"
    assert new_entity_descriptor.valid_until == "2008-09-14T01:05:02Z"
    assert new_entity_descriptor.cache_duration == "10:00:00:00"
    assert isinstance(new_entity_descriptor.signature, ds.Signature)
    assert isinstance(new_entity_descriptor.extensions, md.Extensions)
    assert isinstance(new_entity_descriptor.role_descriptor[0],
                            md.RoleDescriptor)
    assert isinstance(new_entity_descriptor.idpsso_descriptor[0],
                            md.IDPSSODescriptor)
    assert isinstance(new_entity_descriptor.spsso_descriptor[0],
                            md.SPSSODescriptor)
    assert isinstance(new_entity_descriptor.organization,
                            md.Organization)
    assert isinstance(new_entity_descriptor.contact_person[0],
                            md.ContactPerson)
    assert isinstance(
      new_entity_descriptor.additional_metadata_location[0],
      md.AdditionalMetadataLocation)

  def testUsingTestData(self):
    """Test for entity_descriptor_from_string() using test data."""
    new_entity_descriptor = md.entity_descriptor_from_string(
      md_data.TEST_ENTITY_DESCRIPTOR)
    assert new_entity_descriptor.id == "ID"
    assert new_entity_descriptor.entity_id == "entityID"
    assert new_entity_descriptor.valid_until == "2008-09-14T01:05:02Z"
    assert new_entity_descriptor.cache_duration == "10:00:00:00"
    assert isinstance(new_entity_descriptor.signature, ds.Signature)
    assert isinstance(new_entity_descriptor.extensions, md.Extensions)
    assert isinstance(new_entity_descriptor.role_descriptor[0],
                            md.RoleDescriptor)
    assert isinstance(new_entity_descriptor.idpsso_descriptor[0],
                            md.IDPSSODescriptor)
    assert isinstance(new_entity_descriptor.spsso_descriptor[0],
                            md.SPSSODescriptor)
    assert isinstance(new_entity_descriptor.organization,
                            md.Organization)
    assert isinstance(new_entity_descriptor.contact_person[0],
                            md.ContactPerson)
    assert isinstance(new_entity_descriptor.additional_metadata_location[0],
                            md.AdditionalMetadataLocation)


class TestEntitiesDescriptor:
  def setup_class(self):
    self.entities_descriptor = md.EntitiesDescriptor()

  def testAccessors(self):
    """Test for EntitiesDescriptor accessors"""
    self.entities_descriptor.id = "ID"
    self.entities_descriptor.name = "name"
    self.entities_descriptor.valid_until = "2008-09-14T01:05:02Z"
    self.entities_descriptor.cache_duration = "10:00:00:00"

    self.entities_descriptor.signature = ds.Signature()
    self.entities_descriptor.extensions = md.Extensions()
    self.entities_descriptor.entity_descriptor.append(md.EntityDescriptor())
    self.entities_descriptor.entities_descriptor.append(
      md.EntitiesDescriptor())

    new_entities_descriptor = md.entities_descriptor_from_string(
      self.entities_descriptor.to_string())
    assert new_entities_descriptor.id == "ID"
    assert new_entities_descriptor.name == "name"
    assert new_entities_descriptor.valid_until == "2008-09-14T01:05:02Z"
    assert new_entities_descriptor.cache_duration == "10:00:00:00"
    assert isinstance(new_entities_descriptor.signature, ds.Signature)
    assert isinstance(new_entities_descriptor.extensions, md.Extensions)
    assert isinstance(new_entities_descriptor.entity_descriptor[0],
                            md.EntityDescriptor)
    assert isinstance(new_entities_descriptor.entities_descriptor[0],
                            md.EntitiesDescriptor)

  def testUsingTestData(self):
    """Test for entities_descriptor_from_string() using test data."""
    new_entities_descriptor = md.entities_descriptor_from_string(
      md_data.TEST_ENTITIES_DESCRIPTOR)
    assert new_entities_descriptor.id == "ID"
    assert new_entities_descriptor.name == "name"
    assert new_entities_descriptor.valid_until == "2008-09-14T01:05:02Z"
    assert new_entities_descriptor.cache_duration == "10:00:00:00"
    assert isinstance(new_entities_descriptor.signature, ds.Signature)
    assert isinstance(new_entities_descriptor.extensions, md.Extensions)
    assert isinstance(new_entities_descriptor.entity_descriptor[0],
                            md.EntityDescriptor)
    assert isinstance(new_entities_descriptor.entities_descriptor[0],
                            md.EntitiesDescriptor)