def gen_org_info(): org_info = OrgInfo() org_info.address = loremipsum.sentence(max_char=20) org_info.name = loremipsum.sentence(max_char=20) org_info.description = loremipsum.paragraph() org_info.email = "*****@*****.**" save(org_info)
def mock_mentions(times_to_mock=5): for _ in range(times_to_mock): m = Mention() m.alert_id = _gen_uuid() m.url = "http://unifide.sg" m.title = loremipsum.sentence(max_char=choice(range(20, 30))) m.summary = loremipsum.sentence(max_char=choice(range(20, 30))) m.keyword = _gen_uuid() Mention.collection().save(m.serialize())
def _spawn_items_containers(pl): containers_to_cr8 = [loremipsum.sentence(30) for _ in range(choice(range(1, 3)))] all_pl = map(lambda x: pl + [x], containers_to_cr8) items_to_cr8 = [loremipsum.sentence(30) for _ in range(choice(range(5, 10)))] for item_name in items_to_cr8: i = Item() i.name = item_name i.description = loremipsum.paragraph() i.price = choice(range(1, 100)) i.container_id = container_from_path(pl)._id i.save() for container_pl_to_cr8 in all_pl: save_container_path(container_pl_to_cr8) return all_pl
def gen_discounts(model, existing_path_lis=[]): """ Generate discounts for individual containers from a model """ if existing_path_lis is None: existing_path_lis = [] for container_name, attr_dic in model.items(): path_lis = existing_path_lis + [container_name] container_obj = items.container_from_path(path_lis) discount_obj = Discount() discount_obj.coll_name = items.Container.coll_name() discount_obj.obj_id = container_obj._id discount_obj.discount_lifetime_type = DiscountLifetime.FOREVER discount_obj.name = loremipsum.sentence(max_char=30) discount_obj.description = loremipsum.paragraph() discount_obj.status = DiscountStatus.ENABLED if ContainerAttr.DISCOUNT_PERCENTAGE in attr_dic: perc = attr_dic[ContainerAttr.DISCOUNT_PERCENTAGE] discount_obj.discount_percentage = perc discount_obj.save() if ContainerAttr.DISCOUNT_ABSOLUTE in attr_dic: amount = attr_dic[ContainerAttr.DISCOUNT_ABSOLUTE] discount_obj.absolute_discounted_price = amount discount_obj.save() #gen recursive models if "containers" in model: gen_discounts(model["containers"], path_lis)
def gen_articles(total_items=20): for _ in range(total_items): basic_attr = { "name": loremipsum.sentence(max_char=choice(range(10, 20))), "image": None, "description": loremipsum.paragraph(), } publish_datetime = __gen_random_datetime(MOCK_DATE_RANGE_DAYS) items.save_item(basic_attr, ARTICLE_PATH, publish_datetime)
def _spawn_items(pl): items_to_cr8 = [loremipsum.sentence(30) for _ in range(choice(range(10, 20)))] all_items = [] for item_name in items_to_cr8: i = Item() i.name = item_name i.description = loremipsum.paragraph() i.price = choice(range(1, 100)) i.container_id = container_from_path(pl)._id i._id = i.save() all_items += [i] return all_items
def new_item_coupon(coupon_code, value, obj_id): c = Coupon() c.coupon_scope = CouponScope.ITEM_ONLY c.coll_name = items.Item.coll_name() c.obj_id = obj_id c.coupon_code = coupon_code c.coupon_value = value c.valid_times = 1 c.coupon_lifetime_type = CouponLifetime.FOREVER c.user_scope = CouponUserScope.ALL c.name = loremipsum.sentence() c.description = loremipsum.paragraph() c.status = CouponStatus.AVAILABLE c.save()
def gen_container_coupon(coupon_code, value, container_id): c = Coupon() c.coupon_scope = CouponScope.CONTAINER_WIDE c.coll_name = items.Container.coll_name() c.obj_id = container_id c.coupon_code = coupon_code c.coupon_value = value c.valid_times = 1 c.coupon_lifetime_type = CouponLifetime.FOREVER c.user_scope = CouponUserScope.ALL c.name = loremipsum.sentence() c.description = loremipsum.paragraph() c.status = CouponStatus.AVAILABLE c.save()
def gen_orders(user_lis, item_lis, total_orders=50): for _ in range(total_orders): random_item = choice(item_lis) random_user = choice(user_lis) dic = { "user_id": random_user.obj_id(), "obj_id": random_item.obj_id(), "coll_name": "item", "quantity": choice(range(1, 2)), "special_notes": loremipsum.sentence(), "status": OrderStatus.OK, } order_obj = Order.unserialize(dic) save(order_obj)
def gen_items(total_items=5): container_obj = items.container_from_path(GEN_ITEM_PATH_LIS) if container_obj is None: container_obj = items.save_container_path(GEN_ITEM_PATH_LIS) item_lis = [] for _ in range(total_items): dic = { "name": loremipsum.sentence(max_char=choice(range(10, 20))), "media": None, "description": loremipsum.paragraph(max_char=choice(range(40, 100))), "quantity": choice(range(1, 20)), "price": choice(range(1, 20)), "container_id": container_obj.obj_id(), } item_obj = items.Item.unserialize(dic) item_obj._id = items.save(item_obj) item_lis += [item_obj] return item_lis
def random_string(len=24): token_len = int(len / 4) return random_char_seq(token_len) + loremipsum.sentence(len - token_len)
def random_string(len=24): return random_char_seq(len / 4) + loremipsum.sentence(len - len / 4)
def mock_keywords(times_to_mock=3): for _ in range(times_to_mock): kw = loremipsum.sentence(10) print "Registering %s.." % (kw) register(kw) print "Done"