svanoort / pyresttest

Python Rest Testing
Apache License 2.0
1.15k stars 325 forks source link

Comparators: add case-insensitive string comparison #148

Open nitrocode opened 8 years ago

nitrocode commented 8 years ago

Noticed that when checking my header for Application/json it did not work until I checked it for application/json

    - validators:
         - compare: {header: 'Content-Type', comparator: 'str_eq', expected: "Application/json"}
    - validators:
         - compare: {header: 'Content-Type', comparator: 'str_eq', expected: "application/json"}

Is there a configuration parameter that can disable case sensitivity?

svanoort commented 8 years ago

@nitrocode You can use the regex comparator instead of str_eq for this: https://github.com/svanoort/pyresttest/blob/master/advanced_guide.md#comparator-functions

The actual header extractor is case-insensitive, per the RFC for headers -- it's only that the comparator does exact matching here.

Someone can easily create a str_eq_insensitive that compares strings for equality in a case insensitive fashion though (probably under 10 lines of code including test and documentation).

nitrocode commented 8 years ago

@svanoort ok. The regex comparator is worth checking out then. Thank you.