Beispiel #1
0
 def test_perform_checksum(self):
     self.uploader.upload_checksum = True
     self.request_checksum = request.TusRequest(self.uploader)
     with mock.patch.object(self.request_checksum, 'handle') as mock_:
         self.request_checksum.handle = mock_
         self.request_checksum.perform()
     with open('LICENSE', 'rb') as f:
         license = f.read()
         headers = {
             'upload-offset': 0,
             'Content-Type': 'application/offset+octet-stream'
         }
         headers.update(self.uploader.headers)
         headers["upload-checksum"] = "sha1 " + \
             base64.standard_b64encode(hashlib.sha1(license).digest()).decode("ascii")
         mock_.request.assert_called_with('PATCH',
                                          '/files/15acd89eabdf5738ffc',
                                          license, headers)
Beispiel #2
0
    def test_perform_checksum(self):
        self.uploader.upload_checksum = True
        tus_request = request.TusRequest(self.uploader)

        with open('LICENSE', 'r') as stream, responses.RequestsMock() as resps:
            license_ = stream.read()
            encoded_file = license_.encode('utf-8')
            expected_checksum = "sha1 " + \
                base64.standard_b64encode(hashlib.sha1(
                    encoded_file).digest()).decode("ascii")

            sent_checksum = ''

            def validate_headers(req):
                nonlocal sent_checksum
                sent_checksum = req.headers['upload-checksum']
                return (204, {}, None)

            resps.add_callback(responses.PATCH,
                               self.url,
                               callback=validate_headers)
            tus_request.perform()
            self.assertEqual(sent_checksum, expected_checksum)
Beispiel #3
0
 def setUp(self):
     super(TusRequestTest, self).setUp()
     self.request = request.TusRequest(self.uploader)