Exemplo n.º 1
0
def test_get_list():
    session: Session = database_connection.get_session()
    list_2 = list_dao.get_list(session, 2)
    assert list_2.id == 2
    assert list_2.list == 'list 2'
    assert list_2.items == []
    session.close()
Exemplo n.º 2
0
def test_remove_list():
    session: Session = database_connection.get_session()
    list_dao.remove_list(session, 1)
    result = database_helper.query_all('SELECT id, list FROM list;')
    assert len(result) == 1
    assert result[0][0] == 2
    assert result[0][1] == 'list 2'
    session.close()
Exemplo n.º 3
0
def test_update_list():
    session: Session = database_connection.get_session()
    list_dao.update_list(session, 1, {'list': 'new list'})
    result = database_helper.query_one(
        'SELECT id, list FROM list WHERE id = 1;')

    assert result[0] == 1
    assert result[1] == 'new list'
    session.close()
Exemplo n.º 4
0
def run(request: int):
    """
    Remove a list

    :param request: A list id
    :return: None
    """
    logging.info('Removing a list')
    session: Session = database_connection.get_session()
    try:
        list_dao.remove_list(session, request)
    finally:
        session.close()
Exemplo n.º 5
0
def test_insert_list():
    session: Session = database_connection.get_session()
    repository_list: RepositoryList = RepositoryList()
    repository_list.list = 'list 123'
    list_dao.create_list(session, repository_list)
    database_helper.connect_to_database()
    result = database_helper.query_all('SELECT id, list FROM list;')

    database_helper.execute(f"DELETE FROM list WHERE id = {result[0][0]};")
    database_helper.disconnect_from_database()

    assert len(result) == 1
    assert result[0][0] > 0
    assert result[0][1] == 'list 123'
    session.close()
Exemplo n.º 6
0
def run(request: int):
    """
    Get a list

    :param request: A list id
    :return: The list
    """
    session: Session = database_connection.get_session()
    try:
        logging.info('Creating new list')
        repository_list = list_dao.get_list(session, request)
        domain_list: ModelList = repository_list.map_to_domain() if repository_list is not None else None
    finally:
        session.close()

    return domain_list
Exemplo n.º 7
0
def run(request: Dict[Any, Union[int, ModelList]]):
    """
    Update a list

    :param request: A list id and the list to update its fields. Ex: {id: 1, list: List(...)}
    :return: The number of rows changed
    """
    logging.info('Updating a list')
    session: Session = database_connection.get_session()
    try:
        request_id, request_list = unfold_request(request)
        repository_list: RepositoryList = map_to_repository(request_list)
        dict_list = entity_as_dict(repository_list)
        result = list_dao.update_list(session, request_id, dict_list)
    finally:
        session.close()
    return result
Exemplo n.º 8
0
def run(request):
    """
    Get all lists

    :param request: None
    :return: A list of the existing lists
    """
    logging.info('Getting all lists')
    session: Session = database_connection.get_session()
    try:
        domain_lists: List[ModelList] = [
            repository_list.map_to_domain()
            for repository_list in list_dao.get_lists(session)
        ]
        logging.debug('lists: %s' % domain_lists)
    finally:
        session.close()
    return domain_lists
Exemplo n.º 9
0
def run(request: ModelList):
    """
    Create a new list

    :param request: A list
    :return: The recently created list
    """
    logging.info('Creating new list')
    session: Session = database_connection.get_session()
    try:
        repository_list: RepositoryList = map_to_repository(request)
        domain_list: ModelList = list_dao.create_list(session, repository_list).map_to_domain()
    except Exception:
        session.rollback()
        raise
    finally:
        session.close()
    return domain_list
Exemplo n.º 10
0
def test_get_lists():
    session: Session = database_connection.get_session()
    lists = sorted(list_dao.get_lists(session), key=lambda x: x.id)

    logging.info(lists)

    assert 2 == len(lists)

    assert 1 == lists[0].id
    assert 'list 1' == lists[0].list
    assert 1 == len(lists[0].items)
    assert 1 == lists[0].items[0].id
    assert 'item 1' == lists[0].items[0].item
    assert 1 == lists[0].items[0].list

    assert 2 == lists[1].id
    assert 'list 2' == lists[1].list
    assert 0 == len(lists[1].items)
    session.close()