def list_(user, skin): list_ = List.create(user=user, name="Foo", slug="foo") for i in range(3): list_.item_containers.append(ItemContainer.create()) for _ in range(i + 1): list_.item_containers[-1].items.append(Item(skin=skin)) list_.save() return list_
def mutate(cls, *args, **kwargs): user = get_current_user() name = kwargs["name"] if not name: raise GraphQLError("Invalid name") slug = List.generate_slug(user, name) description = kwargs.get("description") or "" list_ = List.create(user=user, name=name, slug=slug, description=description) return cls(list=list_)
def test_get_current_user_lists(client, user, nb_lists, access_token): other_user = User.create(username="******", steam_id="bar") List.create(user=other_user, name="Foo", slug="foo") for _ in range(nb_lists): List.create(user=user, name="Foo", slug="foo") assert List.filter(user=user).count() == nb_lists url = url_for("graphql") res = client.post(url, headers={"Authorization": f"Bearer {access_token}"}, json={"query": get_current_user_lists_query}) assert res.status_code == HTTPStatus.OK res = res.json assert res["data"]["currentUserLists"] lists = [edge["node"] for edge in res["data"]["currentUserLists"]["edges"]] assert len(lists) == nb_lists
def adding_list(msg): user = User.get_by_id(msg.chat.id) if msg.text == '-': bot.send_message(msg.chat.id, _("Canceled"), reply_markup=mps.main_mp(msg.chat.id)) return elif len(msg.text) > 255: bot.send_message( msg.chat.id, _("Too long name. Max length is 255 symbols. Try another name: ")) bot.register_next_step_handler_by_chat_id(msg.chat.id, adding_list) return creating_list = List.get_or_none((List.name == msg.text) & (List.owner == user)) if creating_list is not None: sent_msg = bot.send_message( chat_id=msg.chat.id, text=_( "You have already created list with this name. Try another:"), reply_markup=types.ForceReply()) bot.register_next_step_handler(sent_msg, adding_list) else: creating_list = List.create(name=msg.text, owner=user) creating_list.subscribed_by = creating_list creating_list.save() bot.send_message(chat_id=msg.from_user.id, text=_("List _%s_ created") % msg.text, parse_mode='markdown', reply_markup=mps.main_mp(user.id)) msg_list = bot.send_message(chat_id=msg.from_user.id, text="📝 *%s*" % msg.text, parse_mode='markdown', reply_markup=mps.list_mp(creating_list.id)) creating_list.last_message_id = msg_list.message_id creating_list.save()