Skip to content

Commit

Permalink
#9 db setup code for the future client_rest CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
len0rd committed Jan 18, 2019
1 parent b3b34d9 commit 42c48c3
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
1 change: 0 additions & 1 deletion server/src/apis/image_submit_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def get(self):
dao = getClassificationDAO(manual)

results = dao.getPendingTargets()
print(results)
if results is None or not results or not results[0]:
return {'message': 'Could not locate any targets pending submission'}, 404

Expand Down
Binary file added server/src/test/assets/rawFrame.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 94 additions & 0 deletions server/src/test/setup_db_for_client_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import os, unittest
from config import defaultConfigPath
from test.test_helpers import truncateTable
from dao.incoming_image_dao import IncomingImageDAO
from dao.manual_cropped_dao import ManualCroppedDAO
from dao.outgoing_manual_dao import OutgoingManualDAO
from dao.model.incoming_image import incoming_image
from dao.model.manual_cropped import manual_cropped
from dao.model.outgoing_manual import outgoing_manual


def setupClientRestTestDb():
# truncate all the tables:
truncateTable('incoming_image')
truncateTable('incoming_gps')
truncateTable('incoming_state')
truncateTable('manual_cropped')
truncateTable('outgoing_manual')
truncateTable('outgoing_autonomous')

# figure out the absolute path to our raw test image:
rawImg = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/assets/rawFrame.jpg')
# figure out the path for our cropped test img
cropImg = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/assets/star.png')

# setup incoming image table first
imageIds= setupIncomingImageTable(rawImg)
# use ids from incoming_image to setup manual_cropped table
cropIds = setupManualCroppedTable(cropImg, imageIds)
setupManualOutgoingTable(cropIds)


def setupIncomingImageTable(rawImgPath):
dao = IncomingImageDAO(defaultConfigPath())
incModel = incoming_image()
incModel.focal_length = 16.0
incModel.time_stamp = 1547453775.2
incModel.image_path = rawImgPath
incModel.manual_tap = False
incModel.autonomous_tap = False
incImageId1 = dao.addImage(incModel)
assert incImageId1 != -1

# just gonna use a slightly different number so we can tell the difference between the two inserts
incModel.focal_length = 17.0
incImageId2 = dao.addImage(incModel)
assert incImageId2 != -1
return (incImageId1, incImageId2)

def setupManualCroppedTable(cropImgPath, imageIds):
dao = ManualCroppedDAO(defaultConfigPath())
incModel = manual_cropped()
incModel.image_id = imageIds[0]
incModel.time_stamp = 1547453775.2
incModel.cropped_path = cropImgPath
incModel.crop_coordinate_tl = "(12, 34)"
incModel.crop_coordinate_br = "(56, 78)"
cropId1 = dao.upsertCropped(incModel)
assert cropId1 != -1

incModel.crop_coordinate_tl = "(90, 110)"
incModel.crop_coordinate_br = "(120, 130)"
cropId2 = dao.upsertCropped(incModel)
assert cropId2 != -1

incModel.image_id = imageIds[1]
incModel.crop_coordinate_tl = "(140, 150)"
incModel.crop_coordinate_br = "(160, 170)"
cropId3 = dao.upsertCropped(incModel)
assert cropId3 != -1
return (cropId1, cropId2, cropId3)

def setupManualOutgoingTable(cropImgIds):
dao = OutgoingManualDAO(defaultConfigPath())
testIns = outgoing_manual()
testIns.crop_id = cropImgIds[0]
testIns.type = 'standard'
testIns.shape = 'circle'
testIns.background_color = 'white'
testIns.alphanumeric = 'A'
testIns.alphanumeric_color = 'black'
assert dao.addClassification(testIns) != -1

testIns.crop_id = cropImgIds[1]
testIns.alphanumeric_color = 'orange'
testIns.background_color = 'gray'
assert dao.addClassification(testIns) != -1

testIns.crop_id = cropImgIds[2]
testIns.shape = 'triangle'
testIns.alphanumeric = 'B'
testIns.background_color = 'blue'
assert dao.addClassification(testIns) != -1

0 comments on commit 42c48c3

Please sign in to comment.