コード例 #1
0
ファイル: tests.py プロジェクト: mredar/md5s3stash
 def test_IOError(self):
     '''Test handling of IOError from urllib.
     Current raise IOError'''
     try:
         (self.temp_file, md5, mime_type) = md5s3stash.checkChunks('./this-path-is-bogus')
     except IOError:
         return True
     self.fail("Didn't raise IOError for file path ./this-path-is-bogus")
コード例 #2
0
ファイル: tests.py プロジェクト: mredar/md5s3stash
 def test_HTTPError(self, mock_urlopen):
     '''Test handling of HTTPError from urllib'''
     with open(self.testfilepath) as fp:
         side_effect=HTTPError('http://bogus-url', 500, 'test HTTPError',
             'headers', fp)
     mock_urlopen.side_effect = side_effect
     with capture(md5s3stash.checkChunks, 'http://bogus-url') as output:
         self.assertFalse(md5s3stash.checkChunks('http://bogus-url'))
コード例 #3
0
 def test_HTTPError(self, mock_urlopen):
     '''Test handling of HTTPError from urllib'''
     with open(self.testfilepath) as fp:
         side_effect = HTTPError('http://bogus-url', 500, 'test HTTPError',
                                 'headers', fp)
     mock_urlopen.side_effect = side_effect
     with capture(md5s3stash.checkChunks, 'http://bogus-url') as output:
         self.assertFalse(md5s3stash.checkChunks('http://bogus-url'))
コード例 #4
0
ファイル: tests.py プロジェクト: mredar/md5s3stash
 def test_local_file_download(self):
 #return file, temp_path, baseFile, hasher.hexdigest(), mime_type
     (self.temp_file, md5, mime_type) = md5s3stash.checkChunks(self.testfilepath)
     self.assertEqual(md5, '71a50dbba44c78128b221b7df7bb51f1')
     self.assertEqual(mime_type, 'image/png')
     #how to check the tmp files?
     self.assertTrue('md5s3' in self.temp_file)
     self.assertTrue(os.path.isfile(self.temp_file))
     self.assertEqual(os.stat(self.temp_file).st_size, 95)
コード例 #5
0
 def test_IOError(self):
     '''Test handling of IOError from urllib.
     Current raise IOError'''
     try:
         (self.temp_file, md5,
          mime_type) = md5s3stash.checkChunks('./this-path-is-bogus')
     except IOError:
         return True
     self.fail("Didn't raise IOError for file path ./this-path-is-bogus")
コード例 #6
0
 def test_local_file_download(self):
     #return file, temp_path, baseFile, hasher.hexdigest(), mime_type
     (self.temp_file, md5,
      mime_type) = md5s3stash.checkChunks(self.testfilepath)
     self.assertEqual(md5, '71a50dbba44c78128b221b7df7bb51f1')
     self.assertEqual(mime_type, 'image/png')
     #how to check the tmp files?
     self.assertTrue('md5s3' in self.temp_file)
     self.assertTrue(os.path.isfile(self.temp_file))
     self.assertEqual(os.stat(self.temp_file).st_size, 95)
コード例 #7
0
ファイル: tests.py プロジェクト: mredar/md5s3stash
 def test_local_file_download_wauth(self, mock_urlopen):
     '''To see that the checkChunks accepts an auth argument'''
     mock_urlopen.return_value = FakeReq('test resp')
     (self.temp_file, md5, mime_type) = md5s3stash.checkChunks(
                                 self.testfilepath,
                                 auth=('username','password'))
     # mock_urlopen.reset_mock()
     file = os.path.join(DIR_FIXTURES, '1x1.png')
     # print "last modified: %s" % time.ctime(os.path.getmtime(file))
     lmod = format_date_time(os.path.getmtime(file))
     mock_urlopen.assert_called_once_with(
                                 file,
                                 auth=('username', 'password'), 
                                 cache={self.testfilepath: {u'If-None-Match': "you're it", u'If-Modified-Since': lmod , u'md5': '85b5a0deaa11f3a5d1762c55701c03da'}})
コード例 #8
0
 def test_local_file_download_wauth(self, mock_urlopen):
     '''To see that the checkChunks accepts an auth argument'''
     mock_urlopen.return_value = FakeReq('test resp')
     (self.temp_file, md5,
      mime_type) = md5s3stash.checkChunks(self.testfilepath,
                                          auth=('username', 'password'))
     # mock_urlopen.reset_mock()
     file = os.path.join(DIR_FIXTURES, '1x1.png')
     # print "last modified: %s" % time.ctime(os.path.getmtime(file))
     lmod = format_date_time(os.path.getmtime(file))
     mock_urlopen.assert_called_once_with(
         file,
         auth=('username', 'password'),
         cache={
             self.testfilepath: {
                 u'If-None-Match': "you're it",
                 u'If-Modified-Since': lmod,
                 u'md5': '85b5a0deaa11f3a5d1762c55701c03da'
             }
         })
コード例 #9
0
ファイル: tests.py プロジェクト: mredar/md5s3stash
 def test_URLError(self):
     '''Test handling of URLError from urllib2'''
     with capture(md5s3stash.checkChunks, 'http://bogus-url') as output:
         self.assertFalse(md5s3stash.checkChunks('http://bogus-url'))
コード例 #10
0
 def test_URLError(self):
     '''Test handling of URLError from urllib2'''
     with capture(md5s3stash.checkChunks, 'http://bogus-url') as output:
         self.assertFalse(md5s3stash.checkChunks('http://bogus-url'))