Пример #1
0
    def test_missing_storage(self):
        # When a file exists in the DB but is missing from disk, a 404
        # is just confusing. It's an internal error, so 500 instead.
        client = LibrarianClient()

        # Upload a file so we can retrieve it.
        sample_data = b'blah'
        file_alias_id = client.addFile('sample',
                                       len(sample_data),
                                       BytesIO(sample_data),
                                       contentType='text/plain')
        url = client.getURLForAlias(file_alias_id)

        # Change the date_created to a known value that doesn't match
        # the disk timestamp. The timestamp on disk cannot be trusted.
        file_alias = IMasterStore(LibraryFileAlias).get(
            LibraryFileAlias, file_alias_id)

        # Commit so the file is available from the Librarian.
        self.commit()

        # Fetch the file via HTTP.
        response = requests.get(url)
        response.raise_for_status()

        # Delete the on-disk file.
        storage = LibrarianStorage(config.librarian_server.root, None)
        os.remove(storage._fileLocation(file_alias.contentID))

        # The URL now 500s, since the DB says it should exist.
        response = requests.get(url)
        self.assertEqual(500, response.status_code)
        self.assertIn('Server', response.headers)
        self.assertNotIn('Last-Modified', response.headers)
        self.assertNotIn('Cache-Control', response.headers)
Пример #2
0
    def setUp(self):
        self.directory = tempfile.mkdtemp()
        self.storage = LibrarianStorage(self.directory, db.Library())

        # Hook the commit and rollback methods of the store.
        self.store = IStore(LibraryFileContent)
        self.committed = self.rolledback = False
        self.orig_commit = self.store.commit
        self.orig_rollback = self.store.rollback

        def commit():
            self.committed = True
            self.orig_commit()

        self.store.commit = commit

        def rollback():
            self.rolledback = True
            self.orig_rollback()

        self.store.rollback = rollback
Пример #3
0
 def setUp(self):
     switch_dbuser('librarian')
     self.directory = tempfile.mkdtemp()
     self.storage = LibrarianStorage(self.directory, db.Library())