Jason Gerard DeRose wrote:
This patch:
==
1.
==
Updates the host and hostgroup XMLRPC tests now that hosts have a
'managedby' attribute and the 'ipaservice' objectclass.
==
2.
==
Changes assert_deepequal() so it normalizes tuples into lists. I did
this because using lists in the Declarative tests makes things much more
readable:
uid=[u'fbar'],
vs.
uid=(u'fbar',),
For readability I replaced the tuples in the existing Declarative tests
with lists, although they will work either way.
==
3.
==
Removes use of 'ignored_values' from the Declarative tests. After
further thought, I decided against using the 'ignore_values' list
because it wasn't intuitive, didn't read well, and led us to testing the
ignored_values more loosely than needed. In its place is the new
tests.util.Fuzzy class for doing loose equality tests. For example, if
previously I would do this:
expected=dict(
result=dict(
uid=[u'fbar'],
),
),
ignore_values=['ipauniqueid', 'uidnumber'],
I would now do this:
expected=dict(
result=dict(
uid=[u'fbar'],
ipauniqueid=[Fuzzy()],
uidnumber=[Fuzzy()],
),
),
By default a `Fuzzy` instance is equal to everything (so it only tests
for existence in an entry). Although it seems pretty wired, these all
evaluate to True:
Fuzzy() == False
7 == Fuzzy() # Order doesn't matter
Fuzzy() == u'Hello False, Lucky 7!'
The first optional argument is a regular expression pattern to match
(which implies the `unicode` type). You could match a phone number like
this:
u'123-456-7890' == Fuzzy('\d{3}-\d{3}-\d{4}') # True
But because it sets an implied type of `unicode`, this evaluates to
False:
'123-456-7890' == Fuzzy('\d{3}-\d{3}-\d{4}') # False
The 'type' kwarg allows you to specify a type constraint, like this:
42 == Fuzzy(type=int) # True
42.0 == Fuzzy(type=int) # False
42.0 == Fuzzy(type=(int, float)) # True
Finally the 'test' kwarg is an optional callable that will be called to
perform the loose equality test, like this:
42 == Fuzzy(test=lambda other: other > 42) # False
43 == Fuzzy(test=lambda other: other > 42) # True
You can also use a type constraint with the 'test' kwarg, like this:
43 == Fuzzy(type=float, test=lambda other: other > 42) # False
42.5 == Fuzzy(type=float, test=lambda other: other > 42) # True
So far `Fuzzy` only needs to be used for 'ipauniqueid', 'uidnumber', and
'gidnumber'. xmlrpc_test.py contains two pre-defined `Fuzzy` instances.
`fuzzy_uuid` matches the 'ipauniqueid' using this burly regular
expression:
fuzzy_uuid = Fuzzy(
'^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
)
`fuzzy_digits` will match 'uidnumber' and 'gidnumber' (which at the
moment are being returned as `str` instances, which I regard as a bug):
fuzzy_digits = Fuzzy('^\d+$', type=str)
==
4.
==
Removes all use of 'ignore_values' by replacing it with Fuzzy instances,
cleans up the declarative tests a bit, and adds slightly more coverage.
ack, pushed to master.
rob
_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel