[PATCH 3 of 4] [test] add test for BFSS to S3 migration

Arthur Lutz arthur.lutz at logilab.fr
Fri Sep 20 14:42:27 CEST 2019


# HG changeset patch
# User Arthur Lutz <arthur.lutz at logilab.fr>
# Date 1568983020 -7200
#      Fri Sep 20 14:37:00 2019 +0200
# Node ID bacb587fcac6fef524fff9026113f8407fa0e580
# Parent  84fa380517600af03d38e07a5230296bc8edbf68
# EXP-Topic custom-s3-endpoint
[test] add test for BFSS to S3 migration

diff -r 84fa38051760 -r bacb587fcac6 test/data/hooks.py
--- a/test/data/hooks.py	Thu Sep 19 18:10:51 2019 +0200
+++ b/test/data/hooks.py	Fri Sep 20 14:37:00 2019 +0200
@@ -1,5 +1,7 @@
+import tempfile
 
 from cubicweb.server.hook import Hook
+from cubicweb.server.sources import storages
 from cubicweb_s3storage.storages import S3Storage
 
 
@@ -10,3 +12,8 @@
   def __call__(self):
       storage = S3Storage('test-bucket')
       self.repo.system_source.set_storage('Image', 'data', storage)
+      #with tempfile.TemporaryDirectory() as tmpdirname:
+      storages.set_attribute_storage(
+            self.repo, 'Image', 'thumbnail_on_bfss',
+            storages.BytesFileSystemStorage(tempfile.mkdtemp()))
+      # TODO - find a way to cleanup tmpdir
diff -r 84fa38051760 -r bacb587fcac6 test/data/schema.py
--- a/test/data/schema.py	Thu Sep 19 18:10:51 2019 +0200
+++ b/test/data/schema.py	Fri Sep 20 14:37:00 2019 +0200
@@ -5,3 +5,4 @@
     title = String()
     data = Bytes(required=True)
     thumbnail = Bytes()
+    thumbnail_on_bfss = Bytes()
diff -r 84fa38051760 -r bacb587fcac6 test/test_s3storage.py
--- a/test/test_s3storage.py	Thu Sep 19 18:10:51 2019 +0200
+++ b/test/test_s3storage.py	Fri Sep 20 14:37:00 2019 +0200
@@ -101,7 +101,8 @@
 
     def test_entity_migration(self):
         with self.admin_access.client_cnx() as cnx:
-            create_image(cnx, thumbnail=Binary(b'some content'))
+            create_image(cnx, thumbnail=Binary(b'some content'),
+                         thumbnail_on_bfss=Binary(b'some content on bfss'))
             cnx.commit()
 
         # Re-use storage instance of "data" attribute as it already has s3
@@ -110,21 +111,29 @@
         with self.mh() as (cnx, mh):
             storages.set_attribute_storage(
                 self.repo, 'Image', 'thumbnail', s3_storage)
-
             mh.cmd_storage_changed('Image', 'thumbnail')
             cnx.commit()
+            storages.set_attribute_storage(
+                self.repo, 'Image', 'thumbnail_on_bfss', s3_storage)
+            mh.cmd_storage_changed('Image', 'thumbnail_on_bfss')
+            cnx.commit()
 
         with self.admin_access.client_cnx() as cnx:
-            key = cnx.execute('Any STKEY(D) WHERE X is Image, '
-                              'X thumbnail D').rows[0][0]
-            key = key.getvalue().decode()
-            # check it looks like an UUID generated by uuid.uuid1()
-            # sorry, I'm lazy, this regex is a bit too permissive...
-            self.assertTrue(re.match(r'\w{8}-\w{4}-\w{4}-\w{4}-\w{12}', key))
+            for attr in ('thumbnail', 'thumbnail_on_bfss'):
+                key = cnx.execute('Any STKEY(D) WHERE X is Image, '
+                                  'X thumbnail D').rows[0][0]
+                key = key.getvalue().decode()
+                # check it looks like an UUID generated by uuid.uuid1()
+                # sorry, I'm lazy, this regex is a bit too permissive...
+                uid_regexp = r'\w{8}-\w{4}-\w{4}-\w{4}-\w{12}'
+                self.assertTrue(re.match(uid_regexp, key))
 
             value = cnx.execute('Any D WHERE X is Image, '
                                 'X thumbnail D').rows[0][0]
             self.assertEqual(b'some content', value.getvalue())
+            value = cnx.execute('Any D WHERE X is Image, '
+                                'X thumbnail_on_bfss D').rows[0][0]
+            self.assertEqual(b'some content on bfss', value.getvalue())
 
 
 if __name__ == '__main__':



More information about the cubicweb-devel mailing list