Exemple #1
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
Exemple #2
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
Exemple #3
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
Exemple #4
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