Exemplo n.º 1
0
    def test_complete_chore_late(self):
        self.addChoreToDB("sweep")
        chore = Chore.getChore(1)
        user = User.getUser("*****@*****.**")
        user.addChore(chore)
        deadline = datetime.strptime("11/30/2017", "%m/%d/%Y")
        chore.setDeadline(deadline)

        response = requests.put('http://*****:*****@ucla.edu")
        totalChores = performance["total"]
        onTimeChores = performance["onTime"]

        self.assertTrue(completed)
        self.assertIsNone(userEmail)
        self.assertIsNone(deadline)
        self.assertEqual(totalChores, 1)
        self.assertEqual(onTimeChores, 0)
Exemplo n.º 2
0
    def test_get_incompleted_chores(self):
        params = {'groupID': 1, 'completed': 'True'}
        response = requests.get(
            'http://localhost:8080/api/group/get-completed-or-incompleted-chores',
            params=params)
        self.assertEqual(response.status_code, 200)

        chore2 = Chore.getChore(2)
        self.assertEqual(chore2.getName(), 'Sweeping')
Exemplo n.º 3
0
    def test_modify_chore_name(self):
        self.addChoreToDB("vacuum")
        response = requests.put('http://localhost:8080/api/chore/modify',
                                data='{"id": 1, "name": "vacuum bedroom"}')
        self.assertEqual(response.status_code, 200)

        chore = Chore.getChore(1)
        choreName = chore.getName()

        self.assertEqual(choreName, "vacuum bedroom")
Exemplo n.º 4
0
    def test_create_chore(self):
        response = requests.post('http://localhost:8080/api/chore/create',
                                 data='{"name": "vacuum", "groupID": 1}')
        self.assertEqual(response.status_code, 200)

        chore = Chore.getChore(1)
        choreName = chore.getName()
        groupID = chore.getGroupID()

        self.assertEqual(choreName, "vacuum")
        self.assertEqual(groupID, 1)
Exemplo n.º 5
0
    def test_complete_chore_invalid_input(self):
        self.addChoreToDB("sweep")
        chore = Chore.getChore(1)
        user = User.getUser("*****@*****.**")
        user.addChore(chore)
        deadline = datetime.strptime("12/12/2020", "%m/%d/%Y")
        chore.setDeadline(deadline)

        response = requests.put('http://localhost:8080/api/chore/complete',
                                data='{"id": 500}')
        self.assertGreaterEqual(response.status_code, 400)
Exemplo n.º 6
0
def completeChore():
    """
    User completes a chore.
    
    Precondition: chore must be assigned to a user and have a deadline.
    
    :param id: the unique ID corresponding to the target chore
    :type id: int
    
    :return: a message confirming that the chore was successfully completed, status code
    :rtype: str, int
    
    :raises KeyError: chore ID was not specified
    :raises sqlalchemy.orm.exc.NoResultFound: chore corresponding to the specified ID does not exist
    """
    data = request.data
    dataDict = loads(data)

    try:
        choreID = dataDict['id']
    except KeyError:
        error = "No ID specified"
        return error, 400

    try:
        chore = Chore.getChore(choreID)
    except NoResultFound:
        error = "Chore not found"
        return error, 404

    userEmail = chore.getUserEmail()
    if userEmail is None:
        error = "Chore is not assigned to a user"
        return error, 412

    deadline = chore.getDeadline()
    if deadline is None:
        error = "Chore does not have a deadline"
        return error, 412

    group = Group.getGroup(chore.getGroupID())
    group.incrementPerformanceTotalByEmail(userEmail)
    if not chore.deadlinePassed():
        group.incrementPerformanceOnTimeByEmail(userEmail)

    chore.setCompleted(True)
    chore.setDeadline(None)

    user = User.getUser(userEmail)
    user.removeChore(chore)

    return "Chore successfully completed"
Exemplo n.º 7
0
    def test_create_chore_optional_input(self):
        response = requests.post(
            'http://localhost:8080/api/chore/create',
            data=
            '{"name": "sweep", "groupID": 1, "description": "sweep bedroom and living room"}'
        )
        self.assertEqual(response.status_code, 200)

        chore = Chore.getChore(1)
        choreName = chore.getName()
        groupID = chore.getGroupID()
        description = chore.getDescription()

        self.assertEqual(choreName, "sweep")
        self.assertEqual(groupID, 1)
        self.assertEqual(description, "sweep bedroom and living room")
Exemplo n.º 8
0
    def test_assign_chore(self):
        self.addChoreToDB("sweep")
        response = requests.put(
            'http://*****:*****@ucla.edu", "deadline": "12/31/2017"}')
        self.assertEqual(response.status_code, 200)

        chore = Chore.getChore(1)
        userEmail = chore.getUserEmail()
        deadline = chore.getDeadline().strftime('%m/%d/%Y')
        completed = chore.getCompleted()

        self.assertEqual(userEmail, "*****@*****.**")
        self.assertEqual(deadline, "12/31/2017")
        self.assertEqual(completed, False)
Exemplo n.º 9
0
def modifyChore():
    """
    Modify the name and/or description of a chore.
    
    :param id: the unique ID corresponding to the target chore
    :param name: (optional) the new name for the chore
    :param description: (optional) the new description for the chore
    
    :type id: int
    :type name: str
    :type description: str
    
    :return: a message confirming whether the chore was successfully modified, status code
    :rtype: str, int
    
    :raises KeyError: chore ID was not specified
    :raises sqlalchemy.orm.exc.NoResultFound: chore corresponding to the specified ID does not exist
    """
    data = request.data
    dataDict = loads(data)

    try:
        choreID = dataDict['id']
    except KeyError:
        error = "No ID specified"
        return error, 400

    try:
        chore = Chore.getChore(choreID)
    except NoResultFound:
        error = "Chore not found"
        return error, 404

    if 'name' in dataDict:
        choreName = dataDict['name']
        chore.setName(choreName)

    if 'description' in dataDict:
        choreDescription = dataDict['description']
        chore.setDescription(choreDescription)

    return "Chore successfully modified"
Exemplo n.º 10
0
def getChoreByID():
    """
    Get information about a chore.
    
    :param id: the unique ID corresponding to the target chore
    :type id: int
    
    :return: a JSON object that contains information about the chore, status code
    :rtype: JSON object, int
    
    :raises sqlalchemy.orm.exc.NoResultFound: chore corresponding to the specified ID does not exist
    """
    choreIDstr = request.args.get('id')
    if choreIDstr is None:
        error = "No ID specified"
        return error, 400
    choreID = int(choreIDstr)
    try:
        chore = Chore.getChore(choreID)
    except NoResultFound:
        error = "Chore not found"
        return error, 404

    return jsonify(chore.serialize)
Exemplo n.º 11
0
def assignUserOrDeadlineToChore():
    """
    Assign a user and/or deadline to a chore.
    
    Notes:
    For initial assignment, email and deadline are required parameters.
    For editing the deadline or assigned user later, email and deadline are optional parameters.
    Postcondition: both user and deadline must not be null.
    
    :param id: the unique ID corresponding to the target chore
    :param email: the email of the user who will be assigned to the chore
    :param deadline: the new deadline for the chore (format: "mm/dd/yyyy")
    
    :type id: int
    :type email: str
    :type deadline: str
    
    :return: a message confirming that the user and deadline have been set, status code
    :rtype: str, int
    
    :raises KeyError: chore ID was not specified
    :raises sqlalchemy.orm.exc.NoResultFound: chore ID does not exist, or user email does not exist
    """
    data = request.data
    dataDict = loads(data)

    try:
        choreID = dataDict['id']
    except KeyError:
        error = "Chore ID not specified"
        return error, 400

    try:
        chore = Chore.getChore(choreID)
    except NoResultFound:
        error = "Chore not found"
        return error, 404

    chore.setCompleted(False)

    userEmail = None
    deadline = None

    if chore.userEmail is None and chore.deadline is None:
        try:
            userEmail = dataDict['email']
            deadline = dataDict['deadline']
        except KeyError:
            error = "Need to specify user email and deadline"
            return error, 400
    else:
        if 'email' in dataDict:
            userEmail = dataDict['email']
        if 'deadline' in dataDict:
            deadline = dataDict['deadline']

    if userEmail is not None:
        try:
            user = User.getUser(userEmail)
        except NoResultFound:
            error = "User not found"
            return error, 404
        user.addChore(chore)

    if deadline is not None:
        choreDeadlineStr = dataDict['deadline']
        choreDeadline = datetime.strptime(choreDeadlineStr, "%m/%d/%Y")
        chore.setDeadline(choreDeadline)

    return "User assignment and deadline set successfully"