Exemplo n.º 1
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))
Exemplo n.º 2
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