pretenders/pretenders — pull request #45 by ulcooney (2012-10-18 15:46:01+00:00)
Title: Header matching

Hi Carles

As discussed on my previous pull request for Etag matching, I've had a go at implementing a more generic header matching feature. It was a bit more involved than I'd expected and I'm not sure if I've ventured too far from your mental model. Anyway, the tests still pass.

The main change is that the matching process now involves a simple "confidence rating" rather than a boolean result. This was the best way I could think of to get the most appropriate response where there are multiple presets for a given url eg If you have the following presets defined:

mock.when(GET '/test/headers)
mock.when(GET '/test/headers/', headers={'Etag': 'AAAA'})

A *GET* to */test/headers* with no additional headers selects the first preset.
A *GET* to */test/headers* with {'Etag': 'AAAA'} in the headers selects the second.

Let me know what you think.