Skip to content

Commit

Permalink
Implement equality for multipart/form-data
Browse files Browse the repository at this point in the history
This could have a few problems:

1. The ordering of the parts might be different causing this to return
   False when in fact the requests are *semantically* equivalent

2. If there's any dynamic content in a part's content, it will be return
   False as well.
  • Loading branch information
sigmavirus24 committed Jun 16, 2015
1 parent 6155015 commit 2199dea
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions betamax_matchers/multipart.py
Expand Up @@ -26,9 +26,16 @@ def match(self, request, recorded_request):
recorded_decoder = decoder.MultipartDecoder(recorded.body,
recorded_content_type)

# FIXME(sigmavirus24): Equality isn't defined on MultipartDecoders
return request_decoder == recorded_decoder
return decoders_equal(request_decoder, recorded_decoder)


def is_formdata(header):
return header is not None and header == 'multipart/form-data'


def decoders_equal(request, recorded):
if len(request.parts) != len(recorded.parts):
return False

parts = zip(request.parts, recorded.parts)
return all(p1.content == p2.content for p1, p2 in parts)

0 comments on commit 2199dea

Please sign in to comment.