예제 #1
0
def __create_todo_item(title: str):
    id = __get_items_collection().insert_one({
        "title":
        title,
        "status":
        ItemStatus.NOT_STARTED.value
    })
    return Item(id=id, title=title, status=ItemStatus.NOT_STARTED)
예제 #2
0
def test_recent_done_items():
    """ Only show tasks done today """
    items = [
        Item(
            '1', 'item', 'description', CardStatus.DOING,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '2', 'item', 'description', CardStatus.TODO,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '3', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '4', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '5', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '6', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item('7', 'item', 'description', CardStatus.DONE, datetime.utcnow()),
    ]
    item_view_model = ViewModel(items, current_user, WRITER_LIST)
    assert item_view_model.recent_done_items == [items[-1]]
예제 #3
0
def test_show_all_done_items_is_false_for_five_or_more_cards():
    items = [
        Item(
            '1', 'item', 'description', CardStatus.DOING,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '2', 'item', 'description', CardStatus.TODO,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '3', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '4', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '5', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '6', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '7', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
    ]
    item_view_model = ViewModel(items, current_user, WRITER_LIST)
    assert item_view_model.show_all_done_items == False
예제 #4
0
def test_older_done_items():
    items = [
        Item(
            '1', 'item', 'description', CardStatus.DOING,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '2', 'item', 'description', CardStatus.TODO,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '3', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '4', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '5', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '6', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item('7', 'item', 'description', CardStatus.DONE, datetime.utcnow()),
    ]
    item_view_model = ViewModel(items, current_user, WRITER_LIST)
    assert item_view_model.older_done_items == items[2:6]
예제 #5
0
def test_show_all_done_items_is_true_for_fewer_than_five_cards():
    """ Only show all done items if less than 5 done items """
    items = [
        Item(
            '1', 'item', 'description', CardStatus.DOING,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '2', 'item', 'description', CardStatus.TODO,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '3', 'item', 'description', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
    ]
    item_view_model = ViewModel(items, current_user, WRITER_LIST)
    assert item_view_model.show_all_done_items == True
예제 #6
0
def get_items(db):
    items = []
    for item in db.find():
        items.append(
            Item(
                item['_id'],
                ItemStatus(item['status']),
                item['title']
            )
        )
    return sorted(items, key=lambda k: k.status.value)
def test_CheckTodoList():
    items = []
    items.append(Item(1, ItemStatus.TODO))

    view = ViewModel(items, User())

    assert len(view.todo_items) == 1
    assert len(view.finished_items) == 0
    assert len(view.doing_items) == 0
    assert view.has_todo_items == True
    assert view.has_doing_items == False
    assert view.has_finished_items == False
예제 #8
0
def test_filter_items():
    items = [
        Item(
            '1', 'item1', 'description1', CardStatus.TODO,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '2', 'item2', 'description2', CardStatus.TODO,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '3', 'item3', 'description3', CardStatus.DOING,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
        Item(
            '4', 'item4', 'description4', CardStatus.DONE,
            datetime.strptime('2021-03-31T16:47:17.915Z',
                              '%Y-%m-%dT%H:%M:%S.%fZ')),
    ]
    item_view_model = ViewModel(items, current_user, WRITER_LIST)
    assert item_view_model.items_todo == items[:2]
    assert item_view_model.items_doing == [items[2]]
    assert item_view_model.items_done == items[-1:]
예제 #9
0
def save_item(id, list):
    """
    Updates an existing item in the session. If no existing item matches the ID of the specified item, nothing is saved.

    Args:
        item: The item to save.
    """
    params = {
        'key': os.environ['TRELLO_ACCOUNT_KEY'],
        'token': os.environ['TRELLO_SECRET_KEY'],
        'idList': list
    }
    response = requests.put('https://api.trello.com/1/cards/' + id,
                            params=params)
    r = response.json()
    return Item(r['id'], r['name'], r['desc'], r['idList'])
예제 #10
0
def get_item_view_model():
    items = []
    items.append(Item('1', 'todo item 1', '', '1', 'To Do'))
    items.append(Item('2', 'todo item 2', '', '1', 'To Do'))
    items.append(Item('3', 'doing item 1', '', '2', 'Doing'))
    items.append(Item('4', 'doing item 2', '', '2', 'Doing'))
    items.append(Item('5', 'doing item 3', '', '2', 'Doing'))
    items.append(Item('6', 'done item 1', '', '3', 'Done'))
    print(items)

    yield ViewModel(items)
예제 #11
0
def get_item(id):
    """
    Fetches the saved item with the specified ID.

    Args:
        id: The ID of the item.

    Returns:
        item: The saved item, or None if no items match the specified ID.
    """
    params = {
        'key': os.environ['TRELLO_ACCOUNT_KEY'],
        'token': os.environ['TRELLO_SECRET_KEY']
    }
    response = requests.get('https://api.trello.com/1/cards/' + id,
                            params=params)
    r = response.json()
    return Item(r['id'], r['name'], r['desc'], r['idList'])
예제 #12
0
    def get_items(self) -> List[dict]:
        """
        Fetches all saved items. 

        Returns:
            list: The list of saved items.
        """
        item_list = []
        for item in self.items.find():
            id = item['_id']
            title = item['name']
            description = item['desc']
            status = CardStatus.get_status(item['status'])
            last_modified_date = item['dateLastActivity']
            item_list.append(Item(id, title, description, status, last_modified_date))

        sorted_cards = sorted(item_list, key=lambda card: card.status.value, reverse=True) 
        return sorted_cards
예제 #13
0
def get_items():
    """
    Fetches all saved items from the session.

    Returns:
        list: The list of saved items.
    """
    params = {
        'key': os.environ['TRELLO_ACCOUNT_KEY'],
        'token': os.environ['TRELLO_SECRET_KEY']
    }
    response = requests.get('https://api.trello.com/1/boards/' +
                            os.environ['BOARD_ID'] + '/cards',
                            params=params)
    listResponse = get_lists()
    objList = []
    for r in response.json():
        objList.append(
            Item(r['id'], r['name'], r['desc'], r['idList'],
                 listResponse[r['idList']]['name']))
    return objList
예제 #14
0
def map_doc_to_item(doc: Dict) -> Item:
    return Item(id=str(doc["_id"]),
                title=doc["title"],
                status=ItemStatus.from_str(doc["status"]))