def _assert_card_delete_POST_ok(self, card): assert Card.objects(id=card.id).count() == 1 response = self._send_card_delete_POST_request(card.id) response_json = json.loads(response.data.decode()) assert Card.objects(id=card.id).count() == 0 assert response.status_code == 200 assert response_json['id'] == str(card.id)
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_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 decorated_function(*args, **kwargs): card_id = kwargs['card_id'] card = Card.objects(id=to_ObjectId(card_id)).first() if not card: abort(404) kwargs['card'] = card return func(*args, **kwargs)
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 create_card(cls, column, **kwargs): card = Card() card.column_id = column.id card.created_by = kwargs.get('created_by', cls.user.id) card.name = kwargs.get( 'name', cls.fake.pystr(min_chars=1, max_chars=256), ) saved_card = card.save() column.cards.append(saved_card) column.save() return saved_card
def index_POST(column, **_): form = CreateCardForm(request.form) if not form.validate_on_submit(): return jsonify(form.errors), 400 card = Card() form.populate_obj(card) card.column_id = column.id card.created_by = current_user.id card.save() column.cards.append(card) column.save() return jsonify({ 'card': card, }), 201
def _assert_card_update_POST_ok(self, card, data): response = self._send_card_update_POST_request(card.id, data) updated_card = Card.objects(id=card.id).first() assert response.status_code == 200 assert updated_card.name == data['name']