Skip to content

Commit a76cd33

Browse files
committed
Update test cases for set_text method
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 92a1faa commit a76cd33

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

tests/test_02_saml.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,22 +230,55 @@ def test_to_string_nspair(self):
230230
assert "saml:AttributeValue" in nsstr
231231
assert "saml:AttributeValue" not in txt
232232

233-
def test_set_text(self):
233+
def test_set_text_empty(self):
234+
av = AttributeValue()
235+
av.set_text(None)
236+
assert av.get_type() == ''
237+
assert av.text == ''
238+
239+
def test_set_text_value(self):
240+
value = 123
241+
av = AttributeValue(value)
242+
assert av.get_type() == 'xs:integer'
243+
assert av.text == str(value)
244+
245+
def test_set_text_update_same_type(self):
234246
av = AttributeValue()
235247
av.set_text(True)
236-
assert av.text == "true"
248+
assert av.get_type() == 'xs:boolean'
249+
assert av.text == 'true'
237250
av.set_text(False)
238-
assert av.text == "false"
239-
# can't change value to another type
240-
raises(AssertionError, "av.set_text(491)")
251+
assert av.get_type() == 'xs:boolean'
252+
assert av.text == 'false'
241253

254+
def test_set_text_cannot_change_value_type(self):
242255
av = AttributeValue()
243-
av.set_text(None)
244-
assert av.text == ""
245-
256+
av.set_text(True)
257+
assert av.get_type() == 'xs:boolean'
258+
assert av.text == 'true'
259+
with raises(ValueError):
260+
av.set_text(123)
261+
assert av.get_type() == 'xs:boolean'
262+
assert av.text == 'true'
263+
264+
def test_set_xs_type_anytype_unchanged_value(self):
265+
av = AttributeValue()
266+
av.set_type('xs:anyType')
267+
for value in [
268+
[1, 2, 3],
269+
{'key': 'value'},
270+
True,
271+
123,
272+
]:
273+
av.set_text(value)
274+
# the value is unchanged
275+
assert av.text == value
276+
277+
def test_set_invalid_type_before_text(self):
246278
av = AttributeValue()
247-
av.set_type('invalid')
248-
raises(ValueError, "av.set_text('free text')")
279+
av.set_type('invalid-type')
280+
with raises(ValueError):
281+
av.set_text('foobar')
249282

250283
def test_make_vals_div(self):
251284
foo = saml2.make_vals(666, AttributeValue, part=True)

0 commit comments

Comments
 (0)