| 56 | |
| 57 | |
| 58 | def test_ie_novary(self): |
| 59 | """ |
| 60 | test ``fix_IE_for_vary`` response to user_agent, content-type |
| 61 | Ref #16632 |
| 62 | """ |
| 63 | |
| 64 | # functions to generate responses |
| 65 | def response_with_excluded_mime(): |
| 66 | r = HttpResponse(content_type="text/unsafe") |
| 67 | r['Vary'] = 'Cookie' |
| 68 | return r |
| 69 | |
| 70 | def response_with_no_content(): |
| 71 | # 'Content-Type' always defaulted, so delete it |
| 72 | r = response_with_excluded_mime() |
| 73 | del r['Content-Type'] |
| 74 | return r |
| 75 | |
| 76 | # request with & without IE user agent |
| 77 | rf = RequestFactory() |
| 78 | request = rf.get('/') |
| 79 | ie_request = rf.get('/', HTTP_USER_AGENT='MSIE') |
| 80 | |
| 81 | # test four cases: normal/ie * excluded_mime/no_content |
| 82 | # not IE, excluded_mime_type |
| 83 | response = response_with_excluded_mime() |
| 84 | utils.fix_IE_for_vary(request, response) |
| 85 | self.assertTrue('Vary' in response) |
| 86 | |
| 87 | # IE, excluded_mime_type |
| 88 | response = response_with_excluded_mime() |
| 89 | utils.fix_IE_for_vary(ie_request, response) |
| 90 | self.assertFalse('Vary' in response) |
| 91 | |
| 92 | # not IE, no_content |
| 93 | response = response_with_no_content() |
| 94 | utils.fix_IE_for_vary(request, response) |
| 95 | self.assertTrue('Vary' in response) |
| 96 | |
| 97 | # IE, no_content |
| 98 | response = response_with_no_content() |
| 99 | utils.fix_IE_for_vary(ie_request, response) |
| 100 | self.assertFalse('Vary' in response) |
| 101 | |