diff options
Diffstat (limited to 'backend/tests')
21 files changed, 132 insertions, 21 deletions
diff --git a/backend/tests/common.py b/backend/tests/common.py index cb455e4..abfa471 100644 --- a/backend/tests/common.py +++ b/backend/tests/common.py @@ -3,7 +3,9 @@ Utilities for testing """ from typing import Any -import bz2, gzip, sqlite3 +import bz2 +import gzip +import sqlite3 def createTestFile(filename: str, content: str) -> None: """ Creates a file with the given name and contents """ diff --git a/backend/tests/dbpedia/test_gen_desc_data.py b/backend/tests/dbpedia/test_gen_desc_data.py index 7d35677..ae56c5e 100644 --- a/backend/tests/dbpedia/test_gen_desc_data.py +++ b/backend/tests/dbpedia/test_gen_desc_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestBz2, readTestDbTable from tol_data.dbpedia.gen_desc_data import genData @@ -57,9 +58,11 @@ class TestGenData(unittest.TestCase): '<http://dbpedia.org/resource/A_Hat> <http://www.w3.org/2000/01/rdf-schema#comment>' ' "Hats are not parrots, nor are they potatoes."@en .\n' )) + # Run dbFile = os.path.join(tempDir, 'descData.db') genData(labelsFile, idsFile, redirectsFile, disambigFile, typesFile, abstractsFile, dbFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT iri, label from labels'), diff --git a/backend/tests/enwiki/test_download_img_license_info.py b/backend/tests/enwiki/test_download_img_license_info.py index ed6e426..bd91478 100644 --- a/backend/tests/enwiki/test_download_img_license_info.py +++ b/backend/tests/enwiki/test_download_img_license_info.py @@ -1,6 +1,7 @@ import unittest from unittest.mock import Mock, patch -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable, readTestDbTable from tol_data.enwiki.download_img_license_info import downloadInfo @@ -53,6 +54,7 @@ TEST_RESPONSE1 = { } } } + TEST_RESPONSE2 = { 'batchcomplete': '', 'query': { @@ -152,8 +154,10 @@ class TestDownloadInfo(unittest.TestCase): (1, 'Octopus2.jpg'), } ) + # Run downloadInfo(imgDb) + # Check self.assertEqual( readTestDbTable(imgDb, 'SELECT name, license, artist, credit, restrictions, url from imgs'), @@ -162,6 +166,7 @@ class TestDownloadInfo(unittest.TestCase): 'https://upload.wikimedia.org/wikipedia/commons/5/57/Octopus2.jpg'), } ) + # Run with updated image-data db createTestDbTable( imgDb, @@ -172,6 +177,7 @@ class TestDownloadInfo(unittest.TestCase): } ) downloadInfo(imgDb) + # Check self.assertEqual( readTestDbTable(imgDb, 'SELECT name, license, artist, credit, restrictions, url from imgs'), diff --git a/backend/tests/enwiki/test_download_imgs.py b/backend/tests/enwiki/test_download_imgs.py index 2618b8a..aaf27bc 100644 --- a/backend/tests/enwiki/test_download_imgs.py +++ b/backend/tests/enwiki/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.enwiki.download_imgs import downloadImgs @@ -40,10 +41,12 @@ class TestDownloadInfo(unittest.TestCase): ('six','cc-by','','fred','','https://upload.wikimedia.org/6.png'), } ) + # Create temp output directory with tempfile.TemporaryDirectory() as outDir: # Run downloadImgs(imgDb, outDir, 0) + # Check expectedImgs = { '1.jpg': 'img:https://upload.wikimedia.org/1.jpg', diff --git a/backend/tests/enwiki/test_gen_desc_data.py b/backend/tests/enwiki/test_gen_desc_data.py index 801aa69..0d1536b 100644 --- a/backend/tests/enwiki/test_gen_desc_data.py +++ b/backend/tests/enwiki/test_gen_desc_data.py @@ -1,5 +1,6 @@ import unittest -import os, tempfile +import os +import tempfile from tests.common import readTestDbTable from tol_data.enwiki.gen_desc_data import genData @@ -12,6 +13,7 @@ class TestGenData(unittest.TestCase): # Run dbFile = os.path.join(tempDir, 'descData.db') genData(TEST_DUMP_FILE, dbFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT id, title FROM pages'), diff --git a/backend/tests/enwiki/test_gen_dump_index_db.py b/backend/tests/enwiki/test_gen_dump_index_db.py index e0715f3..b918f15 100644 --- a/backend/tests/enwiki/test_gen_dump_index_db.py +++ b/backend/tests/enwiki/test_gen_dump_index_db.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestBz2, readTestDbTable from tol_data.enwiki.gen_dump_index_db import genData @@ -10,15 +11,18 @@ def runGenData(indexFileContents: str): # Create temp index file indexFile = os.path.join(tempDir, 'index.txt.bz2') createTestBz2(indexFile, indexFileContents) + # Run dbFile = os.path.join(tempDir, 'data.db') genData(indexFile, dbFile) + # Read db return readTestDbTable(dbFile, 'SELECT title, id, offset, next_offset FROM offsets') class TestGenData(unittest.TestCase): def setUp(self): self.maxDiff = None # Remove output-diff size limit + def test_index_file(self): indexFileContents = ( '100:10:apple\n' @@ -33,6 +37,7 @@ class TestGenData(unittest.TestCase): ('banana ice-cream', 99, 300, 1000), ('Custard!', 2030, 1000, -1), }) + def test_emp_index(self): offsetsMap = runGenData('') self.assertEqual(offsetsMap, set()) diff --git a/backend/tests/enwiki/test_gen_img_data.py b/backend/tests/enwiki/test_gen_img_data.py index 1703b78..0a8f79d 100644 --- a/backend/tests/enwiki/test_gen_img_data.py +++ b/backend/tests/enwiki/test_gen_img_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable, readTestDbTable from tol_data.enwiki.gen_img_data import getInputPageIdsFromDb, genData @@ -20,8 +21,10 @@ class TestGetInputPageIdsFromDb(unittest.TestCase): ('and another', 2), } ) + # Run pageIds = getInputPageIdsFromDb(dbFile) + # Check self.assertEqual(pageIds, {1, 2}) @@ -40,9 +43,11 @@ class TestGenData(unittest.TestCase): ('Autism',25,0,-1), } ) + # Run imgDb = os.path.join(tempDir, 'imgData.db') genData({10, 25}, TEST_DUMP_FILE, indexDb, imgDb) + # Check self.assertEqual( readTestDbTable(imgDb, 'SELECT page_id, img_name from page_imgs'), @@ -51,8 +56,10 @@ class TestGenData(unittest.TestCase): (25, 'Autism-stacking-cans 2nd edit.jpg'), } ) + # Run with updated page-ids set genData({13, 10}, TEST_DUMP_FILE, indexDb, imgDb) + # Check self.assertEqual( readTestDbTable(imgDb, 'SELECT page_id, img_name from page_imgs'), diff --git a/backend/tests/enwiki/test_gen_pageview_data.py b/backend/tests/enwiki/test_gen_pageview_data.py index 5002eb0..0c4a35e 100644 --- a/backend/tests/enwiki/test_gen_pageview_data.py +++ b/backend/tests/enwiki/test_gen_pageview_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestBz2, createTestDbTable, readTestDbTable from tol_data.enwiki.gen_pageview_data import genData @@ -18,6 +19,7 @@ class TestGenData(unittest.TestCase): 'fr.wikipedia Four null desktop 12 T6U6\n' 'en.wikipedia Three null desktop 10 E4G5Z61\n' )) + # Create temp dump-index db dumpIndexDb = os.path.join(tempDir, 'dump_index.db') createTestDbTable( @@ -31,9 +33,11 @@ class TestGenData(unittest.TestCase): ('Four', 4, 0, -1), } ) + # Run dbFile = os.path.join(tempDir, 'data.db') genData(pageviewFiles, dumpIndexDb, dbFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT title, id, views from views'), 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'}) diff --git a/backend/tests/test_gen_desc_data.py b/backend/tests/test_gen_desc_data.py index cc0582d..8d21978 100644 --- a/backend/tests/test_gen_desc_data.py +++ b/backend/tests/test_gen_desc_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable, readTestDbTable from tol_data.gen_desc_data import genData @@ -37,6 +38,7 @@ class TestGenData(unittest.TestCase): ('<http://dbpedia.org/resource/Three>', 'Three from dbp'), } ) + # Create temp enwiki db enwikiDb = os.path.join(tempDir, 'enwiki_descs.db') createTestDbTable( @@ -70,6 +72,7 @@ class TestGenData(unittest.TestCase): (5, 'Five from enwiki'), } ) + # Create temp tree-of-life db dbFile = os.path.join(tempDir, 'data.db') createTestDbTable( @@ -86,8 +89,10 @@ class TestGenData(unittest.TestCase): ('seventh', 7), } ) + # Run genData(dbpediaDb, enwikiDb, dbFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT wiki_id, desc, from_dbp from descs'), diff --git a/backend/tests/test_gen_imgs.py b/backend/tests/test_gen_imgs.py index 1ddd438..efab361 100644 --- a/backend/tests/test_gen_imgs.py +++ b/backend/tests/test_gen_imgs.py @@ -1,6 +1,8 @@ import unittest from unittest.mock import patch -import tempfile, os, shutil +import tempfile +import os +import shutil from tests.common import createTestFile, createTestDbTable, readTestDbTable from tol_data.gen_imgs import genImgs @@ -95,9 +97,11 @@ class TestGenImgs(unittest.TestCase): ('node6', 'ott6', 10), } ) + # Run outDir = os.path.join(tempDir, 'img') genImgs(imgListFile, eolImgDir, outDir, eolImgDb, enwikiImgDb, pickedImgDir, pickedImgsFile, dbFile) + # Check self.assertEqual(set(os.listdir(outDir)), { 'ott1.jpg', diff --git a/backend/tests/test_gen_linked_imgs.py b/backend/tests/test_gen_linked_imgs.py index b989407..be4b0d1 100644 --- a/backend/tests/test_gen_linked_imgs.py +++ b/backend/tests/test_gen_linked_imgs.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable, readTestDbTable from tol_data.gen_linked_imgs import genData @@ -70,8 +71,10 @@ class TestGenData(unittest.TestCase): ('thirteen', 12, 'enwiki'), } ) + # Run genData(dbFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT name, otol_ids from linked_imgs'), diff --git a/backend/tests/test_gen_mapping_data.py b/backend/tests/test_gen_mapping_data.py index 9aa99b7..57c9ef7 100644 --- a/backend/tests/test_gen_mapping_data.py +++ b/backend/tests/test_gen_mapping_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestFile, createTestGzip, createTestDbTable, readTestDbTable from tol_data.gen_mapping_data import \ @@ -18,10 +19,12 @@ class TestReadTaxonomyFile(unittest.TestCase): SEP.join(['10', '20', 'ten', 'family', 'if:10,if:100', '', '', '\n']), SEP.join(['11', '100', 'eleven', '', 'igloo:1,ncbi:?', '', '', '\n']) ])) + # Run nodeToSrcIds = {} usedSrcIds = set() readTaxonomyFile(taxonomyFile, nodeToSrcIds, usedSrcIds) + # Check self.assertEqual(nodeToSrcIds, { 1: {'ncbi': 10}, @@ -34,6 +37,7 @@ class TestReadTaxonomyFile(unittest.TestCase): ('gbif', 1), ('if', 10) }) + class TestReadEolIdsFile(unittest.TestCase): def test_read(self): with tempfile.TemporaryDirectory() as tempDir: @@ -51,15 +55,18 @@ class TestReadEolIdsFile(unittest.TestCase): 10: {'ncbi': 10}, 20: {'ncbi': 23, 'gbif': 234} } + # Run usedSrcIds = {('ncbi', 10), ('gbif', 234), ('ncbi', 23)} nodeToEolId = {} readEolIdsFile(eolIdsFile, nodeToSrcIds, usedSrcIds, nodeToEolId) + # Check self.assertEqual(nodeToEolId, { 10: 1, 20: 101, }) + class TestReadWikidataDb(unittest.TestCase): def test_read(self): with tempfile.TemporaryDirectory() as tempDir: @@ -105,10 +112,12 @@ class TestReadWikidataDb(unittest.TestCase): nodeToEolId = { 20: 100, } + # Run nodeToWikiTitle = {} titleToIucnStatus = {} readWikidataDb(wikidataDb, nodeToSrcIds, usedSrcIds, nodeToWikiTitle, titleToIucnStatus, nodeToEolId) + # Check self.assertEqual(nodeToWikiTitle, { 10: 'one', @@ -123,6 +132,7 @@ class TestReadWikidataDb(unittest.TestCase): 10: 1, 20: 100, }) + class TestReadPickedMappings(unittest.TestCase): def test_read(self): with tempfile.TemporaryDirectory() as tempDir: @@ -155,8 +165,10 @@ class TestReadPickedMappings(unittest.TestCase): 12: 'two', 35: 'goanna', } + # Run readPickedMappings(pickedMappings, nodeToEolId, nodeToWikiTitle) + # Check self.assertEqual(nodeToEolId, { 1: 1, @@ -170,6 +182,7 @@ class TestReadPickedMappings(unittest.TestCase): 15: 'ghi', 35: 'jkl', }) + class TestReadGetEnwikiPageIds(unittest.TestCase): def test_read(self): with tempfile.TemporaryDirectory() as tempDir: @@ -191,14 +204,17 @@ class TestReadGetEnwikiPageIds(unittest.TestCase): 20: 'two', 30: 'three', } + # Run titleToPageId = {} getEnwikiPageIds(dumpIndexDb, nodeToWikiTitle, titleToPageId) + # Check self.assertEqual(titleToPageId, { 'one': 1, 'two': 22, }) + class TestGenData(unittest.TestCase): def test_mapping(self): with tempfile.TemporaryDirectory() as tempDir: @@ -275,8 +291,10 @@ class TestGenData(unittest.TestCase): ('third', 'ott3', 2), ] ) + # Run genData(taxonomyFile, eolIdsFile, wikidataDb, pickedMappings, dumpIndexDb, dbFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT name, id from eol_ids'), diff --git a/backend/tests/test_gen_name_data.py b/backend/tests/test_gen_name_data.py index 85e81d8..0dab23a 100644 --- a/backend/tests/test_gen_name_data.py +++ b/backend/tests/test_gen_name_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestFile, createTestDbTable, readTestDbTable from tol_data.gen_name_data import genData @@ -78,8 +79,10 @@ class TestGenData(unittest.TestCase): ('three', 2), ] ) + # Run genData(eolNamesFile, enwikiDb, pickedNamesFile, dbFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT name, alt_name, pref_alt, src FROM names'), diff --git a/backend/tests/test_gen_otol_data.py b/backend/tests/test_gen_otol_data.py index 25e65e3..cc0404a 100644 --- a/backend/tests/test_gen_otol_data.py +++ b/backend/tests/test_gen_otol_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestFile, readTestDbTable from tol_data.gen_otol_data import genData @@ -16,9 +17,11 @@ def runGenData(treeFileContents: str, annFileContents: str, pickedFileContents: # Create temp picked names file pickedFile = os.path.join(tempDir, 'pn.txt') createTestFile(pickedFile, pickedFileContents) + # Run genData() dbFile = os.path.join(tempDir, 'data.db') genData(treeFile, annFile, pickedFile, dbFile) + # Read database nodes = readTestDbTable(dbFile, 'SELECT name, id, tips FROM nodes') edges = readTestDbTable(dbFile, 'SELECT parent, child, p_support FROM edges') @@ -27,6 +30,7 @@ def runGenData(treeFileContents: str, annFileContents: str, pickedFileContents: class TestGenData(unittest.TestCase): def setUp(self): self.maxDiff = None # Remove output-diff size limit + def test_newick(self): treeFileContents = """ ( @@ -40,7 +44,9 @@ class TestGenData(unittest.TestCase): )cellular_organisms_ott1;""" annFileContents = '{"nodes": {}}' pickedFileContents = '' + nodes, edges = runGenData(treeFileContents, annFileContents, pickedFileContents) + self.assertEqual(nodes, { ('land plants', 'ott2', 1), ('traveller\'s tree', 'ott100', 1), @@ -66,9 +72,11 @@ class TestGenData(unittest.TestCase): ('citrus', 'lemon', 0), ('citrus', 'orange', 0), }) + def test_newick_invalid(self): with self.assertRaises(Exception): runGenData('(A,B,(C,D));', '{"nodes": {}}', '') + def test_annotations(self): treeFileContents = '(two_ott2, three_ott3, four_ott4)one_ott1;' annFileContents = """ @@ -91,7 +99,9 @@ class TestGenData(unittest.TestCase): } } }""" + nodes, edges = runGenData(treeFileContents, annFileContents, '') + self.assertEqual(nodes, { ('one', 'ott1', 3), ('two', 'ott2', 1), @@ -103,10 +113,13 @@ class TestGenData(unittest.TestCase): ('one', 'three', 1), ('one', 'four', 0), }) + def test_picked_names_file(self): treeFileContents = '(one_ott2, two_ott3)one_ott1;' pickedFileContents = 'one|ott2' + nodes, edges = runGenData(treeFileContents, '{"nodes": {}}', pickedFileContents) + self.assertEqual(nodes, { ('one [2]', 'ott1', 2), ('one', 'ott2', 1), diff --git a/backend/tests/test_gen_pop_data.py b/backend/tests/test_gen_pop_data.py index dd1cb22..b71ebc5 100644 --- a/backend/tests/test_gen_pop_data.py +++ b/backend/tests/test_gen_pop_data.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable, readTestDbTable from tol_data.gen_pop_data import genData @@ -30,8 +31,10 @@ class TestGenData(unittest.TestCase): ('node3', 3), } ) + # Run genData(pageviewsDb, dbFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT name, pop from node_pop'), diff --git a/backend/tests/test_gen_reduced_trees.py b/backend/tests/test_gen_reduced_trees.py index 2ae4dfd..99cbd92 100644 --- a/backend/tests/test_gen_reduced_trees.py +++ b/backend/tests/test_gen_reduced_trees.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestFile, createTestDbTable, readTestDbTable from tol_data.gen_reduced_trees import genData @@ -98,8 +99,10 @@ class TestGenData(unittest.TestCase): 'five\n' 'VIII\n' )) + # Run genData(None, dbFile, pickedNodesFile) + # Check self.assertEqual( readTestDbTable(dbFile, 'SELECT name, id, tips from nodes_p'), diff --git a/backend/tests/test_review_imgs_to_gen.py b/backend/tests/test_review_imgs_to_gen.py index d88523b..e98ab32 100644 --- a/backend/tests/test_review_imgs_to_gen.py +++ b/backend/tests/test_review_imgs_to_gen.py @@ -1,5 +1,7 @@ import unittest -import tempfile, os, shutil +import tempfile +import os +import shutil from tests.common import readTestFile, createTestDbTable from tol_data.review_imgs_to_gen import reviewImgs @@ -62,19 +64,24 @@ class TestReviewImgs(unittest.TestCase): ('four', 4), } ) + # Run outFile = os.path.join(tempDir, 'imgList.txt') reviewImgs(eolImgDir, enwikiImgDir, dbFile, outFile, 'all') + # Check self.assertEqual(set(readTestFile(outFile).splitlines()), { 'ott1 ' + os.path.join(eolImgDir, '1 10.jpg'), 'ott2', 'ott3 ' + os.path.join(enwikiImgDir, '3.png'), }) + # Add extra data createTestDbTable(dbFile, None, 'INSERT INTO nodes VALUES (?, ?, ?)',{('four', 'ott4', 2)}) + # Run reviewImgs(eolImgDir, enwikiImgDir, dbFile, outFile, 'all') + # Check self.assertEqual(set(readTestFile(outFile).splitlines()), { 'ott1 ' + os.path.join(eolImgDir, '1 10.jpg'), diff --git a/backend/tests/test_tilo.py b/backend/tests/test_tilo.py index cfc719a..718fb8b 100644 --- a/backend/tests/test_tilo.py +++ b/backend/tests/test_tilo.py @@ -1,5 +1,6 @@ import unittest -import tempfile, os +import tempfile +import os from tests.common import createTestDbTable from tilo import handleReq, TolNode, SearchSuggResponse, SearchSugg, InfoResponse, NodeInfo, DescInfo, ImgInfo @@ -122,8 +123,10 @@ class TestHandleReq(unittest.TestCase): self.tempDir = tempfile.TemporaryDirectory() self.dbFile = os.path.join(self.tempDir.name, 'data.db') initTestDb(self.dbFile) + def tearDown(self): self.tempDir.cleanup() + def test_node_req(self): response = handleReq(self.dbFile, {'QUERY_STRING': 'name=two&type=node&tree=trimmed'}) self.assertEqual(response, { @@ -131,6 +134,7 @@ class TestHandleReq(unittest.TestCase): 'three': TolNode('ott3', [], 'two', 1, False, None, None, None), 'four': TolNode('ott4', [], 'two', 1, True, None, 'ott4.jpg', None), }) + def test_node_toroot_req(self): response = handleReq(self.dbFile, {'QUERY_STRING': 'name=seven&type=node&toroot=1&excl=five&tree=trimmed'}) self.assertEqual(response, { @@ -138,6 +142,7 @@ class TestHandleReq(unittest.TestCase): 'six': TolNode('ott6', ['seven'], 'five', 1, 1, 'VI', 'ott6.jpg', 'endangered'), 'seven': TolNode('ott7', [], 'six', 1, 1, None, None, None), }) + def test_sugg_req(self): response = handleReq(self.dbFile, {'QUERY_STRING': 'name=t&type=sugg&tree=trimmed'}) self.assertEqual(response, SearchSuggResponse( @@ -148,6 +153,7 @@ class TestHandleReq(unittest.TestCase): ], False )) + def test_info_req(self): response = handleReq(self.dbFile, {'QUERY_STRING': 'name=six&type=info&tree=trimmed'}) self.assertEqual(response, InfoResponse( |
