aboutsummaryrefslogtreecommitdiff
path: root/backend/tests/eol
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2023-01-29 11:30:47 +1100
committerTerry Truong <terry06890@gmail.com>2023-01-29 11:30:47 +1100
commit8781fdb2b8c530a6c1531ae9e82221eb062e34fb (patch)
treeffd824aa9b945d69b47f012617ee13d98764d078 /backend/tests/eol
parentf5e87ae628bab0eef97b3e3e62f6d71cca9c99c0 (diff)
Adjust backend coding style
Add line spacing, section comments, and import consistency
Diffstat (limited to 'backend/tests/eol')
-rw-r--r--backend/tests/eol/test_download_imgs.py8
-rw-r--r--backend/tests/eol/test_gen_images_list_db.py5
-rw-r--r--backend/tests/eol/test_review_imgs.py7
3 files changed, 17 insertions, 3 deletions
diff --git a/backend/tests/eol/test_download_imgs.py b/backend/tests/eol/test_download_imgs.py
index 975d1c7..4872ca3 100644
--- a/backend/tests/eol/test_download_imgs.py
+++ b/backend/tests/eol/test_download_imgs.py
@@ -1,6 +1,7 @@
import unittest
from unittest.mock import Mock, patch
-import tempfile, os
+import tempfile
+import os
from tests.common import readTestFile, createTestDbTable
from tol_data.eol.download_imgs import getEolIdsFromDb, downloadImgs
@@ -19,8 +20,10 @@ class TestGetEolIdsFromDb(unittest.TestCase):
('a second', 2),
}
)
+
# Run
eolIds = getEolIdsFromDb(dbFile)
+
# Check
self.assertEqual(eolIds, {1, 2})
@@ -30,6 +33,7 @@ class TestDownloadImgs(unittest.TestCase):
requestsGetMock.side_effect = lambda url: Mock(content=('img:' + url).encode())
with tempfile.TemporaryDirectory() as tempDir:
eolIds = {1, 2, 4}
+
# Create temp images-list db
imagesListDb = os.path.join(tempDir, 'images_list.db')
createTestDbTable(
@@ -48,10 +52,12 @@ class TestDownloadImgs(unittest.TestCase):
(30, 3, '', 'https://content.eol.org/3.png', 'cc-by', 'owner3'),
}
)
+
# Create temp output dir
with tempfile.TemporaryDirectory() as outDir:
# Run
downloadImgs(eolIds, imagesListDb, outDir)
+
# Check
expectedImgs1 = {
'1 10.jpg': 'img:https://content.eol.org/1.jpg',
diff --git a/backend/tests/eol/test_gen_images_list_db.py b/backend/tests/eol/test_gen_images_list_db.py
index ca9b495..c1c81f3 100644
--- a/backend/tests/eol/test_gen_images_list_db.py
+++ b/backend/tests/eol/test_gen_images_list_db.py
@@ -1,5 +1,6 @@
import unittest
-import tempfile, os
+import tempfile
+import os
from tests.common import createTestFile, readTestDbTable
from tol_data.eol.gen_images_list_db import genData
@@ -17,9 +18,11 @@ class TestGenData(unittest.TestCase):
createTestFile(os.path.join(tempDir, 'imgs-2.csv'), (
'3,30,https://example.com/3/,https://content.eol.org/3.png,public,owner3\n'
))
+
# Run
dbFile = os.path.join(tempDir, 'imagesList.db')
genData(imageListsGlob, dbFile)
+
# Check
self.assertEqual(
readTestDbTable(
diff --git a/backend/tests/eol/test_review_imgs.py b/backend/tests/eol/test_review_imgs.py
index 49c09bb..21d4756 100644
--- a/backend/tests/eol/test_review_imgs.py
+++ b/backend/tests/eol/test_review_imgs.py
@@ -1,5 +1,7 @@
import unittest
-import tempfile, os, shutil
+import tempfile
+import os
+import shutil
from tests.common import createTestDbTable
from tol_data.eol.review_imgs import reviewImgs
@@ -19,6 +21,7 @@ class TestReviewImgs(unittest.TestCase):
shutil.copy(AVOID_IMG, os.path.join(imgDir, '2 22.jpg'))
shutil.copy(AVOID_IMG, os.path.join(imgDir, '3 30.png'))
shutil.copy(AVOID_IMG, os.path.join(imgDir, '3 31.jpg'))
+
# Create temp extra-info db
extraInfoDb = os.path.join(tempDir, 'data.db')
createTestDbTable(
@@ -39,8 +42,10 @@ class TestReviewImgs(unittest.TestCase):
('two','II',1,'eol'),
}
)
+
# Run
outDir = os.path.join(tempDir, 'imgs')
reviewImgs(imgDir, outDir, extraInfoDb)
+
# Check
self.assertEqual(set(os.listdir(outDir)), {'1 10.jpg', '2 20.jpeg'})