コード例 #1
0
    def test_getNewDimensions_short(self, mockLoad, mockData):
        testResizer = CoverResizer('testImageBytes')
        testResizer.oWidth = 500
        testResizer.oHeight = 350

        testResizer.getNewDimensions()

        assert testResizer.rHeight == 210
        assert testResizer.rWidth == 300
コード例 #2
0
    def test_getNewDimensions_square(self, mockLoad, mockData):
        testResizer = CoverResizer('testImageBytes')
        testResizer.oWidth = 550
        testResizer.oHeight = 600

        testResizer.getNewDimensions()

        assert testResizer.rHeight == 275
        assert testResizer.rWidth == 300
コード例 #3
0
    def test_getNewDimensions_long(self, mockLoad, mockData):
        testResizer = CoverResizer('testImageBytes')
        testResizer.oWidth = 450
        testResizer.oHeight = 900

        testResizer.getNewDimensions()

        assert testResizer.rHeight == 400
        assert testResizer.rWidth == 200
コード例 #4
0
 def test_loadOriginal(self, mocker, mockData):
     mockImage = mocker.patch.object(Image, 'open')
     mockBytes = mocker.patch('lib.resizer.BytesIO', return_value='testB')
     mockImage.return_value = 'pillow_image'
     testResizer = CoverResizer('testImageBytes')
     assert testResizer.original == 'pillow_image'
     mockBytes.assert_called_once_with('testImageBytes')
     mockImage.assert_called_once_with('testB')
     mockData.assert_called_once()
コード例 #5
0
 def test_resizeCover(self, mocker, mockLoad, mockData):
     testImg = mocker.MagicMock()
     testImg.resize.return_value = 'resizedImage'
     mockLoad.return_value = testImg
     testResizer = CoverResizer('testImageBytes')
     testResizer.rWidth = 300
     testResizer.rHeight = 400
     testResizer.resizeCover()
     assert testResizer.standard == 'resizedImage'
     testImg.resize.assert_called_once_with((300, 400))
コード例 #6
0
 def test_loadImageData(self, mocker, mockLoad):
     mockImg = mocker.MagicMock()
     mockImg.width = 300
     mockImg.height = 400
     mockImg.format = 'test'
     mockLoad.return_value = mockImg
     testResizer = CoverResizer('testImageBytes')
     assert testResizer.oWidth == 300
     assert testResizer.oHeight == 400
     assert testResizer.format == 'test'
コード例 #7
0
    def test_getCoverInBytes(self, mocker, mockLoad, mockData):
        mockIO = mocker.patch('lib.resizer.BytesIO')
        mockBytes = mocker.MagicMock()
        mockIO.return_value = mockBytes
        mockBytes.getvalue.return_value = 'standardBytes'
        testResizer = CoverResizer('testImageBytes')

        testResizer.standard = mocker.MagicMock()
        testResizer.format = 'test'

        testOut = testResizer.getCoverInBytes()

        assert testOut == 'standardBytes'
        testResizer.standard.save.assert_called_once_with(mockBytes,
                                                          format='test')
コード例 #8
0
    def storeCover(self):
        authObj = None
        if 'hathitrust' in self.remoteURL:
            authObj = CoverParse.createAuth()
        try:
            imgResp = requests.get(self.remoteURL, auth=authObj, timeout=5)
        except ReadTimeout:
            raise URLFetchError('URL request timed out', 504, self.remoteURL)
        if imgResp.status_code != 200:
            raise URLFetchError('Unable to read image at url',
                                imgResp.status_code, self.remoteURL)

        coverKey = self.createKey()
        mimeType = self.getMimeType(coverKey)
        s3 = s3Client(coverKey)
        existingFile = s3.checkForFile()
        if existingFile is None:
            resizer = CoverResizer(imgResp.content)
            resizer.getNewDimensions()
            resizer.resizeCover()
            standardCoverBytes = resizer.getCoverInBytes()
            self.s3CoverURL = s3.storeNewFile(standardCoverBytes, mimeType)
        else:
            self.s3CoverURL = existingFile
コード例 #9
0
 def test_init_resizer(self, mockLoad, mockData):
     testResizer = CoverResizer('testImageBytes')
     assert isinstance(testResizer, CoverResizer)
     mockLoad.assert_called_once_with('testImageBytes')
     mockData.assert_called_once()