| 825 | |
| 826 | class TestClientTest(TestCase): |
| 827 | class DummyFile(object): |
| 828 | def __init__(self, filename): |
| 829 | self.name = filename |
| 830 | def read(self): |
| 831 | return 'TEST_FILE_CONTENT' |
| 832 | |
| 833 | def setUp(self): |
| 834 | self.encoded_file = encode_file('TEST_BOUNDARY', 'TEST_KEY', self.DummyFile('TEST_NAME.BIN')) |
| 835 | |
| 836 | def test_first_line_starts_with_dashes_and_boundary(self): |
| 837 | self.assertEqual('--TEST_BOUNDARY', self.encoded_file[0]) |
| 838 | |
| 839 | def test_adds_content_disposition_form_data_filename(self): |
| 840 | self.assertEqual('Content-Disposition: form-data; name="TEST_KEY"; filename="TEST_NAME.BIN"', self.encoded_file[1]) |
| 841 | |
| 842 | def test_guesses_content_type_on_file_encoding(self): |
| 843 | def assert_content_type_for_file_extension(expected, file_extension): |
| 844 | self.assertEqual('Content-Type: %s' % expected, |
| 845 | encode_file('IGNORE', 'IGNORE', self.DummyFile("FILE.%s" % file_extension))[2]) |
| 846 | |
| 847 | assert_content_type_for_file_extension('application/octet-stream', 'BIN') |
| 848 | assert_content_type_for_file_extension('text/plain', 'TXT') |
| 849 | assert_content_type_for_file_extension('application/zip', 'ZIP') |
| 850 | assert_content_type_for_file_extension('application/octet-stream', 'UNKNOWN') |
| 851 | |
| 852 | def tests_appends_file_content(self): |
| 853 | self.assertEqual('TEST_FILE_CONTENT', self.encoded_file[-1]) |
| 854 | No newline at end of file |