Fix uncompressed size for blob store and add test
This commit is contained in:
parent
685dd1a925
commit
0dffdb87c9
2 changed files with 60 additions and 2 deletions
|
@ -35,13 +35,17 @@ def store_blob_record_and_temp_link(namespace, repo_name, blob_digest, location_
|
|||
try:
|
||||
storage = ImageStorage.get(content_checksum=blob_digest)
|
||||
storage.image_size = byte_count
|
||||
storage.uncompressed_size = uncompressed_byte_count
|
||||
|
||||
if uncompressed_byte_count is not None:
|
||||
storage.uncompressed_size = uncompressed_byte_count
|
||||
|
||||
storage.save()
|
||||
|
||||
ImageStoragePlacement.get(storage=storage, location=location_obj)
|
||||
except ImageStorage.DoesNotExist:
|
||||
storage = ImageStorage.create(content_checksum=blob_digest, uploading=False,
|
||||
image_size=byte_count)
|
||||
image_size=byte_count,
|
||||
uncompressed_size=uncompressed_byte_count)
|
||||
ImageStoragePlacement.create(storage=storage, location=location_obj)
|
||||
except ImageStoragePlacement.DoesNotExist:
|
||||
ImageStoragePlacement.create(storage=storage, location=location_obj)
|
||||
|
|
54
test/test_blobmodel.py
Normal file
54
test/test_blobmodel.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
import unittest
|
||||
import time
|
||||
|
||||
from app import app, storage
|
||||
from initdb import setup_database_for_testing, finished_database_for_testing
|
||||
from data import model, database
|
||||
|
||||
ADMIN_ACCESS_USER = 'devtable'
|
||||
REPO = 'simple'
|
||||
|
||||
class TestBlobModel(unittest.TestCase):
|
||||
def setUp(self):
|
||||
setup_database_for_testing(self)
|
||||
|
||||
self.app = app.test_client()
|
||||
self.ctx = app.test_request_context()
|
||||
self.ctx.__enter__()
|
||||
|
||||
def tearDown(self):
|
||||
finished_database_for_testing(self)
|
||||
self.ctx.__exit__(True, None, None)
|
||||
|
||||
def test_store_blob(self):
|
||||
location = database.ImageStorageLocation.select().get()
|
||||
|
||||
# Create a new blob at a unique digest.
|
||||
digest = 'somecooldigest'
|
||||
blob_storage = model.blob.store_blob_record_and_temp_link(ADMIN_ACCESS_USER, REPO, digest,
|
||||
location, 1024, 0, 5000)
|
||||
|
||||
self.assertEquals(blob_storage.content_checksum, digest)
|
||||
self.assertEquals(blob_storage.image_size, 1024)
|
||||
self.assertEquals(blob_storage.uncompressed_size, 5000)
|
||||
|
||||
# Link to the same digest.
|
||||
blob_storage2 = model.blob.store_blob_record_and_temp_link(ADMIN_ACCESS_USER, REPO, digest,
|
||||
location, 2048, 0, 6000)
|
||||
|
||||
self.assertEquals(blob_storage2.id, blob_storage.id)
|
||||
self.assertEquals(blob_storage2.image_size, 2048)
|
||||
self.assertEquals(blob_storage2.uncompressed_size, 6000)
|
||||
|
||||
# Add a new digest, ensure it has a new record.
|
||||
otherdigest = 'anotherdigest'
|
||||
blob_storage3 = model.blob.store_blob_record_and_temp_link(ADMIN_ACCESS_USER, REPO, otherdigest,
|
||||
location, 1234, 0, 5678)
|
||||
|
||||
self.assertNotEquals(blob_storage3.id, blob_storage.id)
|
||||
self.assertEquals(blob_storage3.image_size, 1234)
|
||||
self.assertEquals(blob_storage3.uncompressed_size, 5678)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in a new issue