def _assert_card_move_POST_ok(self, card, data=None): data = {} if not data else data response = self._send_card_move_POST_request(card.id, data) old_column = Column.objects(id=card.column_id).first() if 'new_column_id' in data: new_column = \ Column.objects(id=to_ObjectId(data['new_column_id'])).first() else: new_column = old_column updated_card = Card.objects(id=card.id).first() assert response.status_code == 200 assert updated_card.column_id == new_column.id if old_column != new_column: assert card not in old_column.cards expected_index = 0 if 'prev_card_id' in data: prev_card_id = to_ObjectId(data['prev_card_id']) found = False for i in range(len(new_column.cards)): if new_column.cards[i].id == prev_card_id: expected_index = i + 1 found = True break if not found: expected_index = len(new_column.cards) - 1 assert new_column.cards[expected_index] == card
def _assert_column_delete_POST_ok(self, column): assert Column.objects(id=column.id).count() == 1 assert Card.objects(column_id=column.id).count() == len(column.cards) response = self._send_column_delete_POST_request(column.id) response_json = json.loads(response.data.decode()) assert Column.objects(id=column.id).count() == 0 assert Card.objects(column_id=column.id).count() == 0 assert response.status_code == 200 assert response_json['id'] == str(column.id)
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'
def _assert_index_POST_ok(self, data, column_id): response = self._send_index_POST_request(data, column_id) response_json = json.loads(response.data.decode()) column = Column.objects(id=column_id).first() card = Card.objects(id=response_json['card']['_id']['$oid'], ).first() assert response.status_code == 201 assert card in column.cards assert card.column_id == column.id assert card.created assert card.created_by == self.user.id assert card.name == data['name']
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']
def decorated_function(*args, **kwargs): if 'column_id' in kwargs: column_id = kwargs['column_id'] elif 'column_id' in request.args: column_id = request.args['column_id'] else: abort(400) column = Column.objects(id=to_ObjectId(column_id)).first() if not column: abort(404) kwargs['column'] = column return func(*args, **kwargs)
def create_column(cls, board, **kwargs): column = Column() column.board_id = board.id column.created_by = kwargs.get('created_by', cls.user.id) column.name = kwargs.get( 'name', cls.fake.pystr(min_chars=1, max_chars=256), ) saved_column = column.save() board.columns.append(saved_column) board.save() return saved_column
def index_POST(board, **_): form = CreateColumnForm(request.form) if not form.validate_on_submit(): return jsonify(form.errors), 400 column = Column() form.populate_obj(column) column.board_id = board.id column.created_by = current_user.id column.save() board.columns.append(column) board.save() return jsonify({ 'column': column, }), 201
def card_move_POST(card, column, column_id, **_): payload = request.get_json(force=True) new_column_id = to_ObjectId(payload.get('new_column_id', column_id)) prev_card_id_raw = payload.get('prev_card_id') prev_card_id = to_ObjectId(prev_card_id_raw) if prev_card_id_raw else None if column_id == new_column_id: new_column = column else: new_column = Column.objects(id=new_column_id).first() if not new_column: abort(404) card.column_id = new_column_id card.save() column.cards.remove(card) column.save() if not prev_card_id: new_column.cards.insert(0, card) else: added_card = False for i in range(len(new_column.cards)): if new_column.cards[i].id == prev_card_id: new_column.cards.insert(i + 1, card) added_card = True break if not added_card: new_column.cards.append(card) new_column.save() return jsonify({ 'card': card, }), 200
def _assert_column_update_POST_ok(self, column, data): response = self._send_column_update_POST_request(column.id, data) updated_column = Column.objects(id=column.id).first() assert response.status_code == 200 assert updated_column.name == data['name']