Exemplo n.º 1
0
 def _assert_board_delete_POST_ok(self, board):
     assert Board.objects(id=board.id).count() == 1
     assert Column.objects(board_id=board.id).count() == len(board.columns)
     response = self._send_board_delete_POST_request(board.id)
     response_json = json.loads(response.data.decode())
     assert Board.objects(id=board.id).count() == 0
     assert Column.objects(board_id=board.id).count() == 0
     assert response.status_code == 200
     assert response_json['url'] == \
         '/user/boards?message=Board+has+been+deleted.&category=success'
Exemplo n.º 2
0
 def _assert_board_GET_ok(self, board_id, message=None):
     response = self._send_board_GET_request(board_id, message)
     board = Board.objects(id=board_id).first()
     assert response.status_code == 200
     assert board.name.encode() in response.data
     if message:
         assert message.encode() in response.data
Exemplo n.º 3
0
 def _assert_index_POST_ok(self, data, board_id):
     response = self._send_index_POST_request(data, board_id)
     response_json = json.loads(response.data.decode())
     board = Board.objects(id=board_id).first()
     column = Column.objects(
         id=response_json['column']['_id']['$oid'], ).first()
     assert response.status_code == 201
     assert column in board.columns
     assert column.board_id == board.id
     assert column.created
     assert column.created_by == self.user.id
     assert column.name == data['name']
Exemplo n.º 4
0
 def _assert_board_update_POST_ok(self, board, data, updated=True):
     response = self._send_board_update_POST_request(board.id, data)
     updated_board = Board.objects(id=board.id).first()
     assert response.status_code == 200
     if updated:
         assert b'This board has been updated' in response.data
         assert updated_board.name == data['name']
         assert str(updated_board.owner_id) == data['owner']
         assert updated_board.visibility == data['visibility']
     else:
         assert b'No update needed.' in response.data
         assert board.name == updated_board.name
         assert board.owner_id == updated_board.owner_id
         assert board.visibility == updated_board.visibility
Exemplo n.º 5
0
 def _assert_index_POST_ok(self, data, expected_type=BoardType.PERSONAL):
     response = self._send_index_POST_request(data)
     response_json = json.loads(response.data.decode())
     board = Board.objects(id=response_json['id']).first()
     owner = get_owner_from_id(data['owner'])
     assert response.status_code == 201
     assert response_json['url'] == \
         '/board/{}?message=New+board+has+been+created.' \
         '&category=success'.format(board.id)
     assert board.created_by == self.user.id
     assert board.name == data['name']
     assert str(board.owner_id) == data['owner']
     assert board.type == expected_type.id
     assert board.visibility == data['visibility']
     assert board in owner.boards
Exemplo n.º 6
0
    def create_board(cls, **kwargs):
        board = Board()
        board.created_by = kwargs.get('created_by', cls.user.id)
        board.name = kwargs.get(
            'name',
            cls.fake.pystr(min_chars=1, max_chars=256),
        )
        board.owner_id = kwargs.get('owner_id', cls.user.id)
        board.type = kwargs.get('type', BoardType.PERSONAL.id)
        board.visibility = kwargs.get('visibility', BoardVisibility.PRIVATE.id)
        saved_board = board.save()

        user = User.objects(id=saved_board.owner_id).first()
        if user:
            user.boards.append(saved_board)
            user.save()

        return saved_board
Exemplo n.º 7
0
def index_POST():
    if not current_user.is_authenticated:
        return jsonify({
            'error':
            'Could not create board because you are not logged in.',
        }), 401

    form = CreateBoardForm(request.form)

    if not form.validate_on_submit():
        return jsonify(form.errors), 400

    owner = get_owner_from_id(form.owner.data)

    board = Board()
    board.created_by = current_user.id
    board.name = form.name.data
    board.owner_id = owner.id
    board.type = BoardType.PERSONAL.id if owner.id == current_user.id \
        else BoardType.TEAM.id
    board.visibility = form.visibility.data
    board.save()

    owner.boards.append(board)
    owner.save()

    return jsonify({
        'id':
        str(board.id),
        'url':
        url_for(
            'board.board_GET',
            board_id=board.id,
            message='New board has been created.',
            category='success',
        ),
    }), 201
Exemplo n.º 8
0
        def decorated_function(*args, **kwargs):
            if 'board_id' in kwargs:
                board_id = kwargs['board_id']
            elif 'board_id' in request.args:
                board_id = request.args['board_id']
            else:
                abort(400)

            board = Board.objects(id=to_ObjectId(board_id)).first()

            if not board:
                abort(404)

            actual_permissions = get_board_permissions(board)

            for permission in required_permissions:
                if permission not in actual_permissions:
                    abort(403)

            kwargs['board'] = board
            kwargs['permissions'] = actual_permissions

            return func(*args, **kwargs)
Exemplo n.º 9
0
 def _assert_settings_delete_account_POST_ok(self, user, data):
     assert Board.objects(owner_id=user.id).count() == len(user.boards)
     response = self._send_settings_delete_account_POST_request(data)
     assert response.status_code == 200
     assert b'Your account has been deleted' in response.data
     assert Board.objects(owner_id=user.id).count() == 0