Esempio n. 1
0
 def tearDown(self):
     """
     Delete the temporary database
     """
     self.dao = LocationDao()
     loc = Location("L042", "Drop-off bin outside Testing Center",
                    "2021-01-01 01:01:01")  # loc is location object
     self.dao.deleteLocation(loc)
Esempio n. 2
0
 def __init__(self, helperHandler, notificationHelper):
     self.helperHandler = helperHandler
     self.validCodes = self.helperHandler.extractQRCodesFromFile()
     self.validLocations = self.helperHandler.getValidLocationCodes()
     self.userDao = UserDAO()
     self.relationdao = RelationshipDAO()
     self.containerdao = ContainerDAO()
     self.locationdao = LocationDao()
     self.notificationHelper = notificationHelper
Esempio n. 3
0
    def testInsertWrongDate(self):
        """
        Test that we cannot add a incorrectly formatted date
        """
        loc = Location("L042", "Drop-off bin outside Roche Commons",
                       "01:01:01 2021-01-01")
        self.dao = LocationDao()

        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)
Esempio n. 4
0
    def testInsertLocationQRCodeTooLong(self):
        """
        Test that we cannot add a location_qrcode that is over 45 characters long
        """
        loc = Location("L043xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                       "Drop-off bin outside Roche Commons",
                       "2021-01-01 01:01:01")
        self.dao = LocationDao()

        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)
Esempio n. 5
0
    def testInsertDescriptionTooLong(self):
        """
        Test that we cannot add a description that is over 128 characters long
        """
        loc = Location(
            "L042",
            "Drop-off bin outside Roche Commons xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "2021-01-01 01:01:01")
        self.dao = LocationDao()

        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)
Esempio n. 6
0
    def testselectByLocationQRcode(self):
        """
        Test that we can select a location that exists in the database already
        """
        rc, msg = self.testInsertLocationSmoke()
        self.assertTrue(rc)

        qrcode = "L042"
        self.dao = LocationDao()
        rc, selectByLocationQRcode = self.dao.selectByLocationQRcode(qrcode)

        self.assertTrue(rc)
        self.assertEqual(qrcode, selectByLocationQRcode.location_qrcode)
Esempio n. 7
0
    def testselectByLocationQRcodeDoesntExist(self):
        """
        Test that we can't select a location that doesnt exist in the database already
        """
        rc, msg = self.testInsertLocationSmoke()
        self.assertTrue(rc)

        qrcode = "L043"
        self.dao = LocationDao()
        rc, selectByLocationQRcode = self.dao.selectByLocationQRcode(qrcode)

        self.assertFalse(rc)
        rc, selectByLocationQRcode = self.dao.selectByLocationQRcode(None)

        self.assertFalse(rc)
Esempio n. 8
0
    def testInsertLocationNoneType(self):
        loc = Location(None, "Drop-off bin outside Testing Center",
                       "2021-01-01 01:01:01", 0)
        self.dao = LocationDao()

        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)

        loc = Location("L043", None, "2021-01-01 01:01:01")
        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)

        loc = Location("L043", "Drop-off bin outside Testing Center", None)
        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)
Esempio n. 9
0
    def testDeleteLocationDoesntExist(self):
        """
        Test that we can't delete a location that doesn't exist
        """
        rc, msg = self.testInsertLocationSmoke()
        self.assertTrue(rc)

        loc = Location("L043", "Drop-off bin outside Roche Commons",
                       "2021-01-01 01:01:01")
        self.dao = LocationDao()

        rc, deleteLocation = self.dao.deleteLocation(loc)
        self.assertFalse(rc)

        rc, deleteLocation = self.dao.deleteLocation(None)
        self.assertFalse(rc)
Esempio n. 10
0
    def testDeleteLocation(self):
        """
        Test that we can delete a location from the database
        """
        rc, msg = self.testInsertLocationSmoke()
        self.assertTrue(rc)

        loc = Location("L042", "Drop-off bin outside Testing Center",
                       "2021-01-01 01:01:01")
        self.dao = LocationDao()

        rc, deleteLocation = self.dao.deleteLocation(loc)
        self.assertTrue(rc)

        rc, selectLocation = self.dao.selectByLocationQRcode("L042")
        self.assertFalse(rc)
Esempio n. 11
0
 def __init__(self, helperHandler):
     self.helperHandler = helperHandler
     self.beams_client = PushNotifications(
         instance_id='7032df3e-e5a8-494e-9fc5-3b9f05a68e3c',
         secret_key=
         '8AC9B8AABB93DFE452B2EFC2714FCF923841B6740F97207F4512F240264FF493')
     self.userDao = UserDAO()
     self.containerDao = ContainerDAO()
     self.authDao = AuthDao()
     self.locationDao = LocationDao()
Esempio n. 12
0
 def testInsertLocationSmoke(self):
     loc = Location("L042", "Drop-off bin outside Testing Center",
                    "2021-01-01 01:01:01")
     self.dao = LocationDao()
     return self.dao.insertLocation(loc)
Esempio n. 13
0
class ContainerHandler:
    def __init__(self, helperHandler, notificationHelper):
        self.helperHandler = helperHandler
        self.validCodes = self.helperHandler.extractQRCodesFromFile()
        self.validLocations = self.helperHandler.getValidLocationCodes()
        self.userDao = UserDAO()
        self.relationdao = RelationshipDAO()
        self.containerdao = ContainerDAO()
        self.locationdao = LocationDao()
        self.notificationHelper = notificationHelper

    def validateQRCode(self, qrcode, isLocation):
        # make sure valid qrcode
        if isLocation == False:
            res = self.containerdao.selectContainer(qrcode)
        elif isLocation == True:
            res = self.locationdao.selectByLocationQRcode(qrcode)
        if res[0] == False and isLocation == False:
            raise Exception('That is not a valid QR code.')
        elif res[0] == False and isLocation == True:
            raise Exception('That is not a valid Location.')

    def addContainer(self, request, containerDao):
        return self.containerCRUDS(request, containerDao, "insertContainer")

    def getContainer(self, request, containerDao):
        return self.containerCRUDS(request, containerDao, "selectContainer")

    def deleteContainer(self, request, containerDao):
        return self.containerCRUDS(request, containerDao, "deleteContainer")

    def updateContainer(self, request, containerDao):
        return self.containerCRUDS(request, containerDao, "updateContainer")

    #function values 0->add 1->get 2->delete
    def containerCRUDS(self, request, containerDao, function):
        containerDic = None
        t = "json"
        keys = ["qrcode", "auth_token", "email"]
        if function == ("selectContainer" or "updateContainer"):
            t = "args"
        try:
            containerDic = self.helperHandler.handleRequestAndAuth(
                request=request, keys=keys, t=t, hasAuth=True)
        except Exception as e:
            return json.dumps({"success": False, "message": str(e)})
        container = Container()
        container.dictToContainer(containerDic)
        if (function == "selectContainer"):
            function = "self.containerdao." + function + "(containerDic['qrcode'])"

        else:
            function = "self.containerdao." + function + "(container)"
        res = eval(function)
        if (type(res[1]) == type(container)):
            res = res[0], res[1].containerToDict()
        return self.helperHandler.handleResponse(res)

    def allContainers(self, request, containerDao):
        containerDic = None
        keys = ['email', 'auth_token']
        containers = []
        try:
            containerDic = self.helperHandler.handleRequestAndAuth(
                request, keys, t="args", hasAuth=True)
            res = self.containerdao.selectAll()
            self.helperHandler.falseQueryCheck(res)
            #BinCounts = self.containerdao.totalContainersInBins()
            #self.helperHandler.falseQueryCheck(BinCounts)
        except Exception as e:
            return json.dumps({"success": False, "message": str(e)})
        #Bin = BinCounts[1]
        for r in res[1]:
            tempCont = r.containerToDict()
            containers.append(tempCont)
        res = res[0], containers
        return self.helperHandler.handleResponse(res)

    def checkoutContainer(self, userContainer):
        try:
            self.validateQRCode(userContainer['qrcode'], False)
            userContainer['description'] = None
        except Exception as e:
            raise Exception(e)
        return userContainer

    def secretCheckout(self, userContainer):
        try:
            userContainer['status'] = "Pending Return"
            res = self.relationdao.selectAllByStatus(userContainer['email'],
                                                     userContainer['status'])
            self.helperHandler.falseQueryCheck(res)
            rel = (res[1][len(res[1]) - 1]
                   )  # retrieves the most recent pending return
            userContainer = rel.relationshipToDict()
            userContainer['status'] = "Checked Out"
            userContainer['email'] = "*****@*****.**"
        except Exception as e:
            raise Exception(e)
        return userContainer

    #Accepts list val in format  val = (email, qrcode, status, statusUpdateTime)
    def addRelationship(self, request, containerDao, relationshipDAO):
        userContainer = None
        hasAuth = True
        if "/checkoutContainer" in str(request):
            keys = [
                'email', 'qrcode', 'status', 'auth_token', 'location_qrcode'
            ]
            func = "self.checkoutContainer(userContainer)"  # ask the database team if they are check for pendings that will switch to returned for older user
        elif "/secretCheckout" in str(request):
            keys = ['email']
            func = "self.secretCheckout(userContainer)"
            hasAuth = False
        try:
            userContainer = self.helperHandler.handleRequestAndAuth(
                request=request, keys=keys, hasAuth=hasAuth)
            userContainer = eval(func)
            userContainer['statusUpdateTime'] = datetime.now().strftime(
                '%Y-%m-%d %H:%M:%S')
            old_code = relationshipDAO.getRecentUser(userContainer['qrcode'])

            #If user has already checked out the container they cannot check it out
            if "/checkoutContainer" in str(request):
                logging.info("Entering isCheckedOut testing")
                try:
                    containerStatus = relationshipDAO.isCheckedOut(
                        userContainer['email'], userContainer['qrcode'])
                    if (containerStatus[0] == True):
                        logging.info("Container is checked out already")
                        return json.dumps({
                            "success":
                            False,
                            "message":
                            "You already have this container Checked Out"
                        })
                except Exception as e:
                    logging.info("Exiting checked out testing")
            relationship = Relationship()
            relationship.dictToRelationship(userContainer)
            res = self.relationdao.insertRelationship(relationship)
            self.helperHandler.falseQueryCheck(res)
        except Exception as e:
            return json.dumps({"success": False, "message": str(e)})
        # send notification
        if old_code[0] is True:
            self.notificationHelper.sendNotification(old_code[1])
        return self.helperHandler.handleResponse(res)

    def getContainersForUser(self, request, containerDao, isSorted):
        relationship = None
        if "/secretGetRelationships" in str(request):
            keys = ['email']
            hasAuth = False
        else:
            keys = ['email', 'auth_token']
            hasAuth = True
        try:
            relationship = self.helperHandler.handleRequestAndAuth(
                request=request, keys=keys, t="args", hasAuth=hasAuth)
            res = self.relationdao.selectAllByEmail(relationship['email'])
            self.helperHandler.falseQueryCheck(res)
        except Exception as e:
            return json.dumps({"success": False, "message": str(e)})
        #print(res)
        res[1].reverse()
        dictList = []
        for item in res[1]:
            item = item.relationshipToDict()
            dictList.append(item)
        res = (True, dictList)
        if isSorted is True:
            sortDict = {
                'All': dictList,
                'Checked_Out': [],
                'Pending_Return': [],
                'Verified_Return': [],
                'Damaged_Lost': []
            }
            for item in dictList:
                #print(item['status'].replace(' ', '_'))
                sortDict[item['status'].replace(' ', '_')].append(item)
            res = (True, sortDict)
        return self.helperHandler.handleResponse(res)

    def reportContainer(self, userContainer):
        try:
            userContainer['location_qrcode'] = None
        except Exception as e:
            raise Exception(e)
        return userContainer

    def checkinContainer(self, userContainer):
        try:
            self.validateQRCode(userContainer['location_qrcode'], True)
            userContainer['statusUpdateTime'] = datetime.now().strftime(
                '%Y-%m-%d %H:%M:%S')
        except Exception as e:
            raise Exception(e)
        return userContainer

    def undoReport(self, userContainer):
        try:
            userContainer['status'] = 'Checked Out'
            userContainer['description'] = None
        except Exception as e:
            raise Exception(e)
        return userContainer

    def updateRelationship(
        self, request, containerDao
    ):  # we are going to do loction than the container so get loction for the front end here
        userContainer = None
        if "/checkinContainer" in str(request):
            keys = [
                'email', 'qrcode', 'status', 'auth_token', 'location_qrcode'
            ]
            func = "self.checkinContainer(userContainer)"
        elif "/reportContainer" in str(request):
            keys = ['email', 'qrcode', 'status', 'auth_token', 'description']
            func = "self.reportContainer(userContainer)"
        elif "/undoReportContainer" in str(request):
            keys = ['email', 'qrcode', 'auth_token']
            func = "self.undoReport(userContainer)"
        try:
            userContainer = self.helperHandler.handleRequestAndAuth(
                request, keys)
            userContainer = eval(func)
            self.validateQRCode(userContainer['qrcode'], False)

            #call method in relationdao that checks if current container is checked out, if not return json dumps false
            if "/checkinContainer" in str(request):
                try:
                    containerStatus = self.relationdao.isCheckedOut(
                        userContainer['email'], userContainer['qrcode'])
                    if (containerStatus[0] == False):
                        logging.info("Container not Checked Out")
                        return json.dumps({
                            "success":
                            False,
                            "message":
                            "Cannot return a Container that is Pending Return/Verified Return"
                        })
                except Exception as e:
                    logging.info("Exiting isPendingReturn testing")

            rel = self.relationdao.selectActiveQRcode(userContainer["qrcode"])
            if "/checkinContainer" in str(request):
                reward = self.addPoints(rel[1][0])
            self.helperHandler.falseQueryCheck(rel)
        except Exception as e:
            return json.dumps({"success": False, "message": str(e)})
        #print(dictOfUserAttrib)
        #change over to search by qrcode and active = 1
        relationship = rel[1][0]
        relDict = relationship.relationshipToDict()
        if "/undoReportContainer" in str(
                request) and relDict['status'] != "Damaged Lost":
            return json.dumps({
                "success": False,
                "message": "Container is not Damaged/Lost"
            })
        for key in userContainer:
            if key != "auth_token" and key != "email":
                relDict[key] = userContainer[key]
        relationship.dictToRelationship(relDict)
        res = self.relationdao.updateRelationship(relationship)
        if "/checkinContainer" in str(request):
            res = reward
        return self.helperHandler.handleResponse(res)

    def addPoints(self, rel):
        try:
            f = '%Y-%m-%d %H:%M:%S'
            relDict = rel.relationshipToDict()
            res = self.userDao.selectUser(relDict['email'])
            self.helperHandler.falseQueryCheck(res)
            user = res[1]
            userDict = user.userToDict()
            points = userDict['points']
            checkoutTime = str(relDict['statusUpdateTime'])
            authtimets = datetime.strptime(checkoutTime, f)
            timepassed = datetime.now() - authtimets
            if (timepassed.total_seconds() /
                    3600) >= 48 and relDict['status'] == "Checked Out":
                points = points + 5
                userDict['points'] = points
                reward = self.rewardCheck(15, userDict)
            elif (timepassed.total_seconds() /
                  3600) < 48 and relDict['status'] == "Checked Out":
                points = points + 15
                userDict['points'] = points
                reward = self.rewardCheck(15, userDict)
            else:
                reward = ""
            user.dictToUser(userDict)
            res = self.userDao.updateUser(user)
            self.helperHandler.falseQueryCheck(res)
        except Exception as e:
            raise Exception(e)
        return (True, reward)

    def rewardCheck(self, newPoints, userDic):
        if userDic['points'] // 500 > 0 and userDic['points'] % 500 < newPoints:
            userDic['reward_date'] = datetime.now().strftime(
                '%Y-%m-%d %H:%M:%S')
            return {'newReward': True, 'points': newPoints}
        else:
            return {'newReward': False, 'points': newPoints}

    def deleteRelationship(self, request, relationshipDao, hasAuth):
        relDict = None
        #auth_token not required for testing
        keys = ['email', 'qrcode']
        try:
            relDict = self.helperHandler.handleRequestAndAuth(request,
                                                              keys,
                                                              hasAuth=hasAuth)
            self.validateQRCode(relDict['qrcode'], False)
        except Exception as e:
            return json.dumps({"success": False, "message": str(e)})
        #get relationship object based on email and qrcode
        rel = self.relationdao.selectRelationship(relDict['email'],
                                                  relDict['qrcode'])
        if rel[0] is False:
            return self.helperHandler.handleResponse(rel)
        relationship = rel[1]
        relDict = relationship.relationshipToDict()
        #delete relationship from table
        res = self.relationdao.deleteRelationship(relationship)
        return self.helperHandler.handleResponse(res)
# to get all containers for admin

    def GetRelationships(self, request, relationshipDao, hasAuth):
        relDict = None
        keys = ['email', 'auth_token']
        try:
            relDict = self.helperHandler.handleRequestAndAuth(request,
                                                              keys,
                                                              t="args",
                                                              hasAuth=True)
        except Exception as e:
            return json.dumps({"success": False, "message": str(e)})
        if '/getallContainers' in str(request):
            rel = self.relationdao.selectAll()
            if rel[0] is False:
                return self.helperHandler.handleResponse(rel)
            relDict = []
            for item in rel[1]:
                relDict.append(item.relationshipToDict())
            rel = (True, relDict)
        elif '/getCounts' in str(request):
            sitedic = {
                "In Stock": self.containerdao.totalContainersInStock()[1],
                "Checked Out":
                self.containerdao.totalContainersCheckedOut()[1],
                "In Bin": self.containerdao.totalContainersInBins()[1],
                "Damaged Lost":
                self.containerdao.totalContainersDamagedLost()[1]
            }
            rel = [True, sitedic]
            if rel[0] is False:
                return self.helperHandler.handleResponse(rel)
        elif '/getCurrent' in str(request):
            rel = self.containerdao.selectRecentStatus()
            if rel[0] is False:
                return self.helperHandler.handleResponse(rel)

        return self.helperHandler.handleResponse(rel)
Esempio n. 14
0
 def __init__(self, helperHandler):
     self.helperHandler = helperHandler
     self.locationdao = LocationDao()
     self.containerdao = ContainerDAO()
Esempio n. 15
0
class LocationHandler:
    def __init__(self, helperHandler):
        self.helperHandler = helperHandler
        self.locationdao = LocationDao()
        self.containerdao = ContainerDAO()

    def locationcheckandAuth(self, request, locationDao):
        locationDic = None
        keys = ["qrcode", 'email', 'auth_token']
        try:
            locationDic = self.helperHandler.handleRequestAndAuth(
                request, keys)
            res = self.locationdao.selectByLocationQRcode(
                locationDic['qrcode'])
            self.helperHandler.falseQueryCheck(res)
        except Exception as e:
            return json.dumps({"success": False, "message": str(e)})
        if "/selectLocation" in str(request):
            return self.selectLocation(request, locationDao, res)
        elif "/clearLocation" in str(request):
            return self.clearlocation(request, locationDao, res)
        elif "/deleteLocation" in str(request):
            return self.deleteLocation(request, locationDao, res)

    def selectLocation(self, request, locationDao, res):
        res = res[0], res[1].locationToDict()
        return self.helperHandler.handleResponse(res)

    def clearlocation(self, request, locationDao, res):
        res[1].lastPickup = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        res2 = self.locationdao.updateLocation(res[1])

        return self.helperHandler.handleResponse(res2)

    def addLocation(self, request, locationDao):
        locationDic = None
        keys = ['location_qrcode', 'email', 'auth_token', 'description']
        try:
            locationDic = self.helperHandler.handleRequestAndAuth(
                request, keys)
        except Exception as e:
            return json.dumps({"success": False, "message": str(e)})
        locationDic['lastPickup'] = datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        location = Location()
        location.dictToLocation(locationDic)
        res = self.locationdao.insertLocation(location)
        return self.helperHandler.handleResponse(res)

    def deleteLocation(self, request, locationDao, res):
        res2 = locationDao.deleteLocation(res[1])
        return self.helperHandler.handleResponse(res2)

    def allLocations(self, request, locationDao):
        locationDic = None
        keys = ['email', 'auth_token']
        locations = []
        try:
            locationDic = self.helperHandler.handleRequestAndAuth(request,
                                                                  keys,
                                                                  t="args",
                                                                  hasAuth=True)
            res = self.locationdao.selectAll()
            self.helperHandler.falseQueryCheck(res)
            BinCounts = self.containerdao.totalContainersInBins()
            self.helperHandler.falseQueryCheck(BinCounts)
        except Exception as e:
            return json.dumps({"success": False, "message": str(e)})
        Bin = BinCounts[1]
        for r in res[1]:
            tempLoc = r.locationToDict()
            counter = 0
            for item in Bin:
                if item['location_qrcode'] == tempLoc['location_qrcode']:
                    counter = counter + 1
            tempLoc.update({'count': counter})
            locations.append(tempLoc)
        res = res[0], locations
        return self.helperHandler.handleResponse(res)

    def updateLocation(self, request, locationDao):
        locationDic = None
        keys = ['qrcode', 'email', 'auth_token', 'description']
        try:
            locationDic = self.helperHandler.handleRequestAndAuth(
                request, keys)
            res = self.locationdao.selectByLocationQRcode(
                locationDic['qrcode'])
            self.helperHandler.falseQueryCheck(res)
        except Exception as e:
            return json.dumps({"success": False, "message": str(e)})

        res[1].description = locationDic['description']
        res2 = self.locationdao.updateLocation(res[1])
        return self.helperHandler.handleResponse(res2)
Esempio n. 16
0
from location import Location
from locationDAO import LocationDao
dao = LocationDao()


def main():
    """
    Uncomment the desired method to test it
    """
    testSelectAll()
    #testSelectByLocationQRcode()
    #testInsertLocation()
    #testDeleteLocation()


def testSelectAll():
    print(dao.selectAll())  #returns all locations as objects


def testSelectByLocationQRcode():
    #location 1
    qrcode = "L001"
    print(dao.selectByLocationQRcode(
        qrcode))  #returns specific location object selected by location_qrcode
    #location 2
    qrcode = "L002"
    print(dao.selectByLocationQRcode(qrcode))
    #location 3
    qrcode = "L004"
    print(dao.selectByLocationQRcode(qrcode))
Esempio n. 17
0
class unitTestLocationDAO(unittest.TestCase):
    """
    Test the locationDAO class methods using the unit test framework.  
    To run these tests:
         python3 -m unittest unitTestLocationDAO.py
    """
    def setUp(self):
        """
       Setup a temporary database
       """

    def tearDown(self):
        """
        Delete the temporary database
        """
        self.dao = LocationDao()
        loc = Location("L042", "Drop-off bin outside Testing Center",
                       "2021-01-01 01:01:01")  # loc is location object
        self.dao.deleteLocation(loc)

    # test creating location
    def testInsertLocationSmoke(self):
        loc = Location("L042", "Drop-off bin outside Testing Center",
                       "2021-01-01 01:01:01")
        self.dao = LocationDao()
        return self.dao.insertLocation(loc)

    def testInsertLocation(self):
        """
        Test that we can add a location that doesn't exist in the database
        """
        rc, msg = self.testInsertLocationSmoke()
        self.assertTrue(rc)

    def testUpdateLocation(self):
        rc, msg = self.testInsertLocationSmoke()
        self.assertTrue(rc)

        loc = Location("L042", "Drop-off bin outside New Hall",
                       "2021-02-02 01:01:01")
        rc, msg = self.dao.updateLocation(loc)
        self.assertTrue(rc)

        rc, msg = self.dao.selectByLocationQRcode("L042")
        self.assertTrue(rc)

        self.assertTrue(
            str(msg.lastPickup) == "2021-02-02 01:01:01"
            and str(msg.description) == "Drop-off bin outside New Hall")

    def testInsertLocationTwice(self):
        """
        Test that we can't add a location twice
        First add should work correctly
        """
        rc, msg = self.testInsertLocationSmoke()
        self.assertTrue(rc)
        """
        Second add should fail
        """
        rc, msg = self.testInsertLocationSmoke()
        self.assertFalse(rc)
        self.assertEqual(msg, "Duplicate Entry")

    def testInsertLocationNoneType(self):
        loc = Location(None, "Drop-off bin outside Testing Center",
                       "2021-01-01 01:01:01", 0)
        self.dao = LocationDao()

        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)

        loc = Location("L043", None, "2021-01-01 01:01:01")
        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)

        loc = Location("L043", "Drop-off bin outside Testing Center", None)
        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)

    def testselectByLocationQRcode(self):
        """
        Test that we can select a location that exists in the database already
        """
        rc, msg = self.testInsertLocationSmoke()
        self.assertTrue(rc)

        qrcode = "L042"
        self.dao = LocationDao()
        rc, selectByLocationQRcode = self.dao.selectByLocationQRcode(qrcode)

        self.assertTrue(rc)
        self.assertEqual(qrcode, selectByLocationQRcode.location_qrcode)

    def testselectByLocationQRcodeDoesntExist(self):
        """
        Test that we can't select a location that doesnt exist in the database already
        """
        rc, msg = self.testInsertLocationSmoke()
        self.assertTrue(rc)

        qrcode = "L043"
        self.dao = LocationDao()
        rc, selectByLocationQRcode = self.dao.selectByLocationQRcode(qrcode)

        self.assertFalse(rc)
        rc, selectByLocationQRcode = self.dao.selectByLocationQRcode(None)

        self.assertFalse(rc)

    def testDeleteLocation(self):
        """
        Test that we can delete a location from the database
        """
        rc, msg = self.testInsertLocationSmoke()
        self.assertTrue(rc)

        loc = Location("L042", "Drop-off bin outside Testing Center",
                       "2021-01-01 01:01:01")
        self.dao = LocationDao()

        rc, deleteLocation = self.dao.deleteLocation(loc)
        self.assertTrue(rc)

        rc, selectLocation = self.dao.selectByLocationQRcode("L042")
        self.assertFalse(rc)

    def testDeleteLocationDoesntExist(self):
        """
        Test that we can't delete a location that doesn't exist
        """
        rc, msg = self.testInsertLocationSmoke()
        self.assertTrue(rc)

        loc = Location("L043", "Drop-off bin outside Roche Commons",
                       "2021-01-01 01:01:01")
        self.dao = LocationDao()

        rc, deleteLocation = self.dao.deleteLocation(loc)
        self.assertFalse(rc)

        rc, deleteLocation = self.dao.deleteLocation(None)
        self.assertFalse(rc)

    def testInsertLocationQRCodeTooLong(self):
        """
        Test that we cannot add a location_qrcode that is over 45 characters long
        """
        loc = Location("L043xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                       "Drop-off bin outside Roche Commons",
                       "2021-01-01 01:01:01")
        self.dao = LocationDao()

        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)

    def testInsertDescriptionTooLong(self):
        """
        Test that we cannot add a description that is over 128 characters long
        """
        loc = Location(
            "L042",
            "Drop-off bin outside Roche Commons xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "2021-01-01 01:01:01")
        self.dao = LocationDao()

        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)

    def testInsertWrongDate(self):
        """
        Test that we cannot add a incorrectly formatted date
        """
        loc = Location("L042", "Drop-off bin outside Roche Commons",
                       "01:01:01 2021-01-01")
        self.dao = LocationDao()

        rc, insertLocation = self.dao.insertLocation(loc)
        self.assertFalse(rc)