Example #1
0
def action():
    """Perform a command sent from user interface via form or AJAX.
    Currently includes adding/removing user's meals from meal plans"""
    if request.method == "POST" and request.form:
        command = request.form.get("command")
        id = request.form.get("id")
    if request.method  == "GET" and request.args:
        command = request.args.get("command").lower()
        id = request.args.get("id")
    try:
        id = int(id)
    except:
        id = None

    if not command or not id:
        return("Missing or invalid params")

    user = User.from_db(db=db, id=session.get("user_id"))

    d = {
        "add_meal"   : lambda user, id: user.add_meal(id),
        "remove_meal": lambda user, id: user.remove_meal(id),
    }
    try:
        obj = d[command](user, id)
    except KeyError:
        return("Missing or invalid params")

    return("success")
Example #2
0
 def __set_user(self, user, passwd="8888", employee=False):
     if employee is False:
         self.user_info = User(user)
         self.product_test = productAction(self.user_info)
     else:
         self.employee_info = Employee(user, passwd)
         self.product_test = productAction(self.employee_info)
Example #3
0
def login(request):
    if request.method == 'POST':
        userinfo = json.loads(request.body)
        username = userinfo['username']
        password = userinfo['password']
        res = User.login(user_name=username, password=password)
        return JsonResponse(res, safe=False)
Example #4
0
def register():
    """Register user"""

    # User reached route via POST (as by submitting a form via POST)
    if request.method == "POST":

        # Ensure valid username was submitted
        try:
            name = username_valid(request.form.get("username"))
        except TypeError:
            name = None
        if not name:
            return apology("must provide valid username")

        # Querry database and check if the username is already taken
        if User.exists_in_db(db=db, name=name):
            return apology("this username is already taken")

        # Ensure both passwords were submitted
        password = request.form.get("password")
        confirmation = request.form.get("confirmation")
        if not password or not confirmation:
            return apology("must provide password and its confirmation")

        # Ensure passwords match
        if not password == confirmation:
            return apology("passwords do not match")

        # Store a user entry in the database
        password_hash = generate_password_hash(password)
        user = User(name=name, password_hash=password_hash, db=db)

        # Commit the user changes to DB
        try:
            result = user.write_to_db()
        except:
            result = False

        # Log the user in
        return login(first=True)

    # User reached route via GET (as by clicking a link or via redirect)
    else:
        # Forget any user_id
        session.clear()

        return render_template("register.html")
Example #5
0
def changepassword(request):
    if request.method == 'POST':
        username = request.POST['username']
        old_password = request.POST['old_password']
        new_password = request.POST['new_password']
        res = User.change_password(user_name=username, old_password=old_password, new_password=new_password)

        return JsonResponse(res, safe=False)
Example #6
0
def register(request):
    if request.method == 'POST':
        userinfo = json.loads(request.body)
        username = userinfo['username']
        email = userinfo['email']
        password = userinfo['password']
        res = User.register(user_name=username, password=password, email=email)

        return JsonResponse(res, safe=False)
Example #7
0
def index():
    """Show user's home page"""

    user = User.from_db(db=db, id=session.get("user_id"))
    try:
        recipe_ids = {m.id for m in user.meals}
        recipes = [Recipe.from_db(db=db, id=id) for id in recipe_ids]
    except AttributeError:
        recipes=[]

    return render_template("index.html", meals=recipes)
Example #8
0
def get_JSON():
    """Get JSON repr of an object"""
    if request.method == "POST" and request.form:
        obj_type = request.form.get("obj_type")
        id = request.form.get("id")
    if request.method  == "GET" and request.args:
        obj_type = request.args.get("obj_type").lower()
        id = request.args.get("id")
    try:
        id = int(id)
    except:
        id = None

    if obj_type in ["user", "valid_meals"]:
        if not session.get("is_admin") or not id:
            id = session.get("user_id")
    elif not id:
        return("Missing or invalid params")


    # Users can access only their own user obj and valid_meals
    user_id = session.get("user_id")
    d = {
        "allergy"            : lambda db, id: Allergy.from_db(db, id),
        "ingredient_category": lambda db, id: IngredientCategory.from_db(db, id),
        "ingredient"         : lambda db, id: Ingredient.from_db(db, id),
        "recipe"             : lambda db, id: Recipe.from_db(db, id),
        "user"               : lambda db, id: User.from_db(db, id),
        "valid_meals"        : lambda db, id: User.from_db(db, id).get_valid_recipes_id(),
    }
    try:
        obj = d[obj_type](db, id)
    except KeyError:
        return("Missing or invalid params")

    response = app.response_class(
        response=enc.encode(obj),
        mimetype='application/json'
    )

    return response
Example #9
0
def account(form):
    """Show account settings for GET.
    Write new user settings to  DB for POST.
    """
    user = User.from_db(db=db, id=session.get("user_id"))

    # User reached "/account" route via GET (as by clicking a link or via redirect)
    if request.method == "GET" and not form:
        allergies = db.get_rows("allergies", order_by="name ASC")
        user_allergies = {x.id for x in user.allergies}

        return render_template("account.html", allergies=allergies, user_allergies=user_allergies)

    # User reached "/account/<form>" route via POST (as by submitting a form via POST)
    if form == "allergies":
        allergy_ids = request.form.getlist("allergies")
        allergies = {Allergy.from_db(db, id) for id in allergy_ids}
        user.allergies = allergies
    elif form == "password":
        current_password = request.form.get("current_password")
        new_password = request.form.get("new_password")
        confirmation = request.form.get("confirmation")

        if not current_password:
            flash("Must provide valid current password", category="danger")
            return redirect("account")
        if not all([new_password, confirmation]):
            flash("Must provide new password and repeat it", category="danger")
            return redirect("account")
        if not new_password == confirmation:
            flash("New passwords don't match", category="danger")
            return redirect("account")
        if not check_password_hash(user.password_hash, current_password):
            flash("Incorrect current password", category="danger")
            return redirect("account")

        user.password_hash = generate_password_hash(new_password)

    # Commit the user changes to DB
    try:
        result = user.write_to_db()
    except:
        result = False

    if result:
        flash("Changes saved successfully!")
    else:
        flash("Something went wrong :(", category="danger")

    return redirect("/account")
Example #10
0
    def __init__(self):
        Gtk.Window.__init__(self, title="NTBSG")
        container = Gtk.Grid(row_spacing=20, column_spacing=7)

        self.user = User()
        self.user.add_workspace().add_session()     # default create user, workspace, and session

        # Init Servers
        iserver = InteractionServer()

        header = self.create_window_header()
        buttons_box = self.create_stages_buttons()
        tag_area = TagArea(iserver)
        self.pdml_view = PDMLView(iserver, tag_area)
        session_view = SessionView()

        container.attach(header, 0, 0, 4, 1)
        container.attach(buttons_box, 0, 1, 4, 1)
        container.attach(self.pdml_view, 1, 2, 3, 2)
        container.attach(session_view, 0, 2, 1, 1)
        container.attach(tag_area, 0, 3, 1, 1)

        self.add(container)
Example #11
0
def login(first=False):
    """Log user in"""

    # Forget any user_id
    session.clear()

    if first:
        flash("We recommend to visit the 'Account' page if you have any food allergies")

    # User reached route via POST (as by submitting a form via POST)
    if request.method == "POST":

        # Ensure valid username was submitted
        try:
            name = username_valid(request.form.get("username"))
        except TypeError:
            name = None
        if not name:
            return apology("must provide valid username", 403)

        # Ensure password was submitted
        password = request.form.get("password")
        if not password:
            return apology("must provide password", 403)

        # Ensure user exists and querry for credentials
        user = User.from_db(db=db, name=name)
        if not user:
            return apology("user does not exist", 403)

        # Ensure password is correct
        if not check_password_hash(user.password_hash, password):
            return apology("invalid username or password", 403)

        # Remember which user has logged in
        session["user_id"] = user.id
        session["is_admin"] = user.is_admin

        # Redirect user to home page
        return redirect("/")

    # User reached route via GET (as by clicking a link or via redirect)
    return render_template("login.html")
Example #12
0
def itinerary_search():
    try:
        TypeUser = request.args.get('TypeUser', 'Défaut')
        P_Permis = request.args.get('P_Permis', False)
        if P_Permis == "true":
            P_Permis = True
        else:
            P_Permis = False
        P_Meteo = request.args.get('P_Meteo', True)
        if P_Meteo == "true":
            P_Meteo = True
        else:
            P_Meteo = False
        P_Charge = request.args.get('P_Charge', False)
        if P_Charge == "true":
            P_Charge = True
        else:
            P_Charge = False
    except:
        abort(400)
    try:
        org = request.args.get('origine', "Champs de Mars")
        dest = request.args.get('destination', "Place de la Nation")
        print(
            "type utilisateur:{}\npermis:{}\nmeteo:{}\nchargé:{}\norigine:{}\ndestination:{}\n"
            .format(TypeUser, P_Permis, P_Meteo, P_Charge, org, dest))

        origin = Place(org)
        destination = Place(dest)
        iti = Itinerary(origin=origin, destination=destination)
        Utilisateur = User(TypeUser,
                           driving_license=P_Permis,
                           weather=P_Meteo,
                           loaded=P_Charge)
        resultat = Suggested_Itineraries(Utilisateur, iti)

        content = jsonify(resultat)

        return content

    except:
        abort(500)
Example #13
0
def admin_display(obj_type):
    """Show admin page for selected object type"""
    template = obj_type + ".html" if obj_type else "admin.html"
    if obj_type == "allergies":
        kwargs = {"rows":Allergy.get_summary(db)}
    elif obj_type == "ingredient_categories":
        kwargs = {"rows":IngredientCategory.get_summary(db)}
    elif obj_type == "ingredients":
        kwargs = {"rows"      : Ingredient.get_summary(db),
                  "categories": db.get_rows("ingredient_categories"),
                  "allergies" : db.get_rows("allergies")}
    elif obj_type == "recipes":
        kwargs = {"rows"       : Recipe.get_summary(db),
                  "ingredients": db.get_rows("ingredients")}
    elif obj_type == "users":
        kwargs = {"rows"      : User.get_summary(db),
                  "allergies" : db.get_rows("allergies")}
    else:
        kwargs = {}

    return render_template(template, **kwargs)
Example #14
0
def admin_remove(obj_type):
    """Remove an object from DB"""
    if request.method == "POST" and request.form:
        id = request.form.get("id")
    if request.method  == "GET" and request.args:
        id = request.args.get("id")
    try:
        id = int(id)
    except:
        id = None

    if not id:
        return("Missing or invalid params")

    d = {
        "allergies"            : lambda db, id: Allergy.from_db(db, id).remove_from_db(),
        "ingredient_categories": lambda db, id: IngredientCategory.from_db(db, id).remove_from_db(),
        "ingredients"          : lambda db, id: Ingredient.from_db(db, id).remove_from_db(),
        "recipes"              : lambda db, id: Recipe.from_db(db, id).remove_from_db(),
        "users"                : lambda db, id: User.from_db(db, id).remove_from_db(),
    }
    try:
        d[obj_type](db, id)
        # If a recipe was removed remove its image
        if obj_type == "recipes":
            filename = str(id) + ".jpg"
            try:
                os.remove(os.path.join(app.config["RECIPE_IMG_PATH"], filename))
            except FileNotFoundError:
                pass
        flash("Entry deleted successfully!")
    except KeyError:
        return ("Object type not found")
    except DBError:
        flash("Cannot delete entry with dependents (referenced by other entries)!", category="danger")
    except:
        flash("Something went wrong :(", category="danger")

    return redirect("admin/" + obj_type)
Example #15
0
class Main(unittest.TestCase):
    L = Log('Main')
    tool = Tool()
    user = User("18602832572", "123456a", register=False)
    appbuyeraction = AppBuyerAction(user)
    webbuyeraction = WebBuyerAction(user)
    pa = PromoterAction(Employee('100028', '123456'))
    # user = User("13658082213", "123456a", register=False)
    # buyeraction = BuyerAction(user)
    # employee = Employee(buyeraction.get_customer_account(), '123456')
    emp = Employee("100005", "123456")
    dataTRADE = Config('trade').data
    service = ServiceAction(emp)
    seller_agent = SellerAgent(user)

    def tearDown(self):
        pass

    def setUp(self):
        pass

    def test2000(self):
        """
        mobile卖家中介模糊搜索农场
        :return:
        """
        selleragency = SellerAgent(self.user)
        selleragency.mobile_seller_agent_search_farm("漫花庄园", language='zh')

    def test2001(self):
        """
        mobile卖家中介新增农场备注
        :return:
        """
        selleragency = SellerAgent(self.user)
        selleragency.mobile_seller_agency_add_remark(415,
                                                     "lalal",
                                                     language='zh')

    def test2002(self):
        """
        mobile卖家中介关闭农场
        :return:
        """
        selleragency = SellerAgent(self.user)
        selleragency.mobile_seller_agency_close_farm(522, 30, language='zh')

    def test2003(self):
        """
        mobile卖家中介关闭农场列表
        :return:
        """
        selleragency = SellerAgent(self.user)
        selleragency.mobile_seller_agency_close_farm_list(419, language='zh')

    def test2004(self):
        """
        mobile卖家中介农场详情
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.mobile_seller_agency_farm_detail(140.7842627,
                                                     37.8301386,
                                                     523,
                                                     language='zh')

    def test2005(self):
        """
        mobile卖家中介已发布农场列表
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.mobile_seller_agency_farm_list(2, language='zh')

    def test2006(self):
        """
        mobile卖家中介已发布农场地图页
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.mobile_seller_agency_map_list(140.7842627,
                                                  37.8301386,
                                                  language='zh')

    def test2007(self):
        """
        mobile卖家中介农场详情
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.mobile_seller_agency_update_farm(516, {"area": 12},
                                                     language='zh')

    def test2008(self):
        """
        mobile卖家中介农场主
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.mobile_seller_agency_farmer_detail(528, language='zh')

    def test2009(self):
        """
        mobile卖家中介更新农场主
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.mobile_seller_agency_farmer_update(
            528,
            '王二麻子',
            1,
            "2018-01-01",
            18602883456,
            "https://zyp-farm-2.oss-ap-southeast-1.aliyuncs.com/data/farm/head/1535092943322.jpg",
            '嘿嘿嘿',
            11,
            language='zh')

    def test2010(self):
        """
        mobile卖家中介增加资质
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.mobile_seller_agency_use_add(
            '王二麻子',
            "叽里呱啦大公司", '[{"type": "2",'
            '"url": "https://zyp-farm-2.oss-ap-southeast-1.aliyuncs.com/data/farm/head/1535093109545.jpg"},'
            '{"type": "3",'
            '"url": "https://zyp-farm-2.oss-ap-southeast-1.aliyuncs.com/data/farm/head/1535092873551.jpg"},'
            '{"type": "4",'
            '"url": "https://zyp-farm-2.oss-ap-southeast-1.aliyuncs.com/data/farm/head/1535092943322.jpg"}]',
            language='zh')

    def test2011(self):
        """
        mobile卖家中介资质状态
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.mobile_seller_agency_use_status(language='zh')

    def test2012(self):
        """
        mobile卖家中介农场意向买家列表
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.mobile_seller_agency_farm_buyer_list(414,
                                                         3,
                                                         1,
                                                         language='zh')

    def test2013(self):
        """
        mobile卖家中介消息意向买家列表
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.mobile_seller_agency_message_buyer_list(language='zh')

    def test2014(self):
        """
        mobile卖家中介IM发送农场
        :return:
        """
        selleragency = SellerAgent(self.user)
        selleragency.mobile_seller_agency_im_send_farm_list("庄园",
                                                            language='zh')

    def test2015(self):
        """
        web卖家中介新增备注
        :return:
        """
        selleragency = SellerAgent(self.user)
        selleragency.web_seller_agency_add_remark(415,
                                                  "web自动化测试备注",
                                                  language='zh')

    def test2016(self):
        """
        web卖家中介新增农场
        :return:
        """
        selleragency = SellerAgent(self.user)
        selleragency.web_seller_agent_add_farm("web测试大娃二娃农场名",
                                               "种植",
                                               "南澳大利亚",
                                               "2000万-3500万",
                                               "5000亩-10000亩",
                                               language='zh')

    def test2017(self):
        """
        web卖家中介关闭农场
        :return:
        """
        selleragency = SellerAgent(self.user)
        selleragency.web_seller_agency_close_farm(522, 30, language='zh')

    def test2018(self):
        """
        web卖家中介关闭农场列表
        :return:
        """
        selleragency = SellerAgent(self.user)
        selleragency.web_seller_agency_close_farm_list(419, language='zh')

    def test2019(self):
        """
        web卖家中介农场详情
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.web_seller_agency_farm_detail(140.7842627,
                                                  37.8301386,
                                                  523,
                                                  language='zh')

    def test2020(self):
        """
        web卖家中介已发布农场列表
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.web_seller_agency_farm_list(2, language='zh')

    def test2021(self):
        """
        web卖家中介更新农场
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.web_seller_agency_update_farm(516, {"area": 12},
                                                  language='zh')

    def test2022(self):
        """
        web卖家中介农场主
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.web_seller_agency_farmer_detail(528, language='zh')

    def test2023(self):
        """
        web卖家中介更新农场主
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.web_seller_agency_farmer_update(528,
                                                    {'realName': ' web测试'},
                                                    language='zh')

    def test2024(self):
        """
        web卖家中介增加资质
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.web_seller_agency_use_add(
            '王二麻子',
            "叽里呱啦大公司", '[{"type": "2",'
            '"url": "https://zyp-farm-2.oss-ap-southeast-1.aliyuncs.com/data/farm/head/1535093109545.jpg"},'
            '{"type": "3",'
            '"url": "https://zyp-farm-2.oss-ap-southeast-1.aliyuncs.com/data/farm/head/1535092873551.jpg"},'
            '{"type": "4",'
            '"url": "https://zyp-farm-2.oss-ap-southeast-1.aliyuncs.com/data/farm/head/1535092943322.jpg"}]',
            language='zh')

    def test2025(self):
        """
        web卖家中介资质状态
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.web_seller_agency_use_status(language='zh')

    def test2026(self):
        """
        web卖家中介农场意向买家列表
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.web_seller_agency_farm_buyer_list(414, 3, 1, language='zh')

    def test2027(self):
        """
        web卖家中介消息意向买家列表
        :return:
        """
        seleragency = SellerAgent(self.user)
        seleragency.web_seller_agency_message_buyer_list(language='zh')

    def test2028(self):
        """
        mobile卖家中介新增农场
        :return:
        """
        selleragency = SellerAgent(self.user)
        selleragency.mobile_seller_agent_add_farm("web测试大娃二娃农场名",
                                                  "种植",
                                                  "南澳大利亚",
                                                  "2000万-3500万",
                                                  "5000亩-10000亩",
                                                  language='zh')

    def test0001(self):
        """
        app买家绑定销售ID
        :return:
        """

        re = self.appbuyeraction.app_buyer_sale_bind(487)
        print(re)
        re = self.appbuyeraction.app_buyer_query_sale(487)
        print(re)

    def test0002(self):
        """
        app查询用户个人信息
        :return:
        """
        user_info = self.appbuyeraction.app_buyer_user_detail()
        print(user_info)

    def test0003(self):
        """
        app感兴趣
        :return:
        """
        print(
            self.appbuyeraction.app_get_order_no(
                self.appbuyeraction.app_get_farm_list_first_id()))

    def test0004(self):
        """
        app用户修改个人信息
        :return:
        """
        self.appbuyeraction.app_buyer_update_user(
            "星买家", "男", "成都大农科技有限公司", "前端工程师",
            "http://zyp-farm-2.oss-ap-southeast-1.aliyuncs.com/data/farm/head/1530012058085.png"
        )

    def test0005(self):
        """
        app上传购买资质
        :return:
        """
        farm_id = self.appbuyeraction.app_get_farm_list_first_id()
        is_add = self.appbuyeraction.app_buyer_resource_is_add(
            self.appbuyeraction.app_get_order_no(farm_id))
        r = self.appbuyeraction.app_buyer_resource_add(
            farm_id, self.appbuyeraction.app_get_order_no(farm_id))
        print(is_add)
        print(r)

    def test0006(self):
        """
        app查看购买资质详情
        :return:
        """
        farm_id = self.appbuyeraction.app_get_farm_list_first_id()
        r = self.appbuyeraction.app_buyer_resource_detail(
            self.appbuyeraction.app_get_order_no(farm_id))
        print(r)

    def test0008(self):
        """
        app卖家中介上传及认证
        :return:
        """
        self.seller_agent.mobile_approve_seller_agent("张鹏飞", "大农科技")
        self.tool.operator_approve_seller_agent("18380581401", True)

    def test0009(self):
        """
        app卖家中介绑定客服,地推
        :return:
        """
        self.pa.promoter_bind_seller_agent(self.user.user_id)

    def test0007(self):
        """
        app卖家发布场--买家感兴趣--客服邀请上传资质--买家上传资质--客服审核资质
        :return:
        """
        farm_id = self.seller_agent.mobile_seller_agent_add_farm(
            "调试农场名",
            "种植",
            "南澳大利亚",
            "2000万-3500万",
            "5000亩-10000亩",
            language='zh')
        # farm_id = self.buyeraction.app_get_farm_id()
        order_no = self.appbuyeraction.app_get_order_no(farm_id)
        order_id = self.tool.query_order_id_by_order_no(order_no)
        self.service.service_send_auth_url(order_id)
        self.appbuyeraction.app_buyer_resource_is_add(order_no)
        self.appbuyeraction.app_buyer_resource_add(farm_id, order_no)
        response_resource_list = self.service.service_buyer_resource_list(
            order_no, self.user.real_name)
        response_resource_list = json.loads(response_resource_list)
        resource_list = response_resource_list.get('content').get('datas')
        resource_id = None
        for resource in resource_list:
            resource_order_no = resource.get('orderNo')
            if resource_order_no == order_no:
                resource_id = resource.get('id')
        self.service.service_buyer_resource_audit(resource_id, 2, "接口测试不通过")

    def test0010(self):
        """
        app农场列表
        :return:
        """
        print(self.appbuyeraction.app_get_farm_list())

    def test0011(self):
        """
        app农场详情
        :return:
        """
        self.appbuyeraction.app_get_farm_detail(
            self.appbuyeraction.app_get_farm_list_first_id())

    def test0012(self):
        """
        web端
        卖家发布场--买家感兴趣--客服邀请上传资质--买家上传资质--客服审核资质
        :return:
        """
        farm_id = self.seller_agent.web_seller_agent_add_farm("调试农场名",
                                                              "种植",
                                                              "南澳大利亚",
                                                              "2000万-3500万",
                                                              "5000亩-10000亩",
                                                              language='zh')
        order_no = self.webbuyeraction.web_get_order_no(farm_id)
        order_id = self.tool.query_order_id_by_order_no(order_no)
        self.service.service_send_auth_url(order_id)
        self.webbuyeraction.web_buyer_resource_is_add(order_no)
        self.webbuyeraction.web_buyer_resource_add(farm_id, order_no)
        response_resource_list = self.service.service_buyer_resource_list(
            order_no, self.user.real_name)
        response_resource_list = json.loads(response_resource_list)
        resource_list = response_resource_list.get('content').get('datas')
        resource_id = None
        for resource in resource_list:
            resource_order_no = resource.get('orderNo')
            if resource_order_no == order_no:
                resource_id = resource.get('id')
        self.service.service_buyer_resource_audit(resource_id, 2, "接口测试不通过")

    def test0013(self):
        """
        app查询是都显示认证提示
        :return:
        """
        self.appbuyeraction.app_buyer_update_show_auth()

    def test0014(self):
        """
        添加订阅规则
        :return:
        """
        self.appbuyeraction.app_buyer_subscribe_add()

    def test0015(self):
        """
        订阅规则详情
        :return:
        """
        self.appbuyeraction.app_buyer_subscribe_detail()

    def test0016(self):
        """
        修改订阅规则
        :return:
        """
        self.appbuyeraction.app_buyer_subscribe_update()
Example #16
0
import sqlite3
from werkzeug.security import generate_password_hash

from backend.DBHandler import DBHandler
from backend.User import User

db = DBHandler()

USER = "******"

try:
    db.create_schema()
    user = User(name=USER,
                password_hash=generate_password_hash(USER),
                is_admin=True,
                db=db)
    user.write_to_db()

    print("New DB initialized successfully, 'admin' user created.")
except sqlite3.OperationalError:
    print("The DB already exists and has a schema. Operation aborted.")
Example #17
0
class MainWindow(Gtk.Window):
    user = None
    pdmlview = None

    def __init__(self):
        Gtk.Window.__init__(self, title="NTBSG")
        container = Gtk.Grid(row_spacing=20, column_spacing=7)

        self.user = User()
        self.user.add_workspace().add_session()     # default create user, workspace, and session

        # Init Servers
        iserver = InteractionServer()

        header = self.create_window_header()
        buttons_box = self.create_stages_buttons()
        tag_area = TagArea(iserver)
        self.pdml_view = PDMLView(iserver, tag_area)
        session_view = SessionView()

        container.attach(header, 0, 0, 4, 1)
        container.attach(buttons_box, 0, 1, 4, 1)
        container.attach(self.pdml_view, 1, 2, 3, 2)
        container.attach(session_view, 0, 2, 1, 1)
        container.attach(tag_area, 0, 3, 1, 1)

        self.add(container)

    def create_window_header(self):
        system_title = gu.bold_label("  Network Traffic Based Software Generation")
        create_session = Gtk.Button("Create Session")
        create_session.connect("clicked", self.on_clicked_create_session)

        open_session = Gtk.Button("Open Session")
        open_session.connect("clicked", self.on_clicked_open_session)

        close_session = Gtk.Button("Close Session")

        switch_workspace = Gtk.Button("Switch Workspace")
        switch_workspace.connect("clicked", self.on_clicked_switch_workspace)

        open_pcap = Gtk.Button("Open PCAP")
        open_pcap.connect("clicked", self.on_clicked_open_pcap)

        terminal = Gtk.Button("Terminal")
        terminal.connect("clicked", self.on_clicked_terminal)

        box = gu.create_box([system_title, create_session, open_session,
                             close_session, switch_workspace, open_pcap, terminal])
        box.set_spacing(15)
        return box

    def on_clicked_switch_workspace(self, button):
        wl.run_popwindow()

    def on_clicked_open_pcap(self, button):
        pcap_window = PCAPWindow()

        created_pdml = pcap_window.get_pdmlfile()
        if created_pdml is not None:
            session = self.user.getworkspace().getsession()
            pdmlstate = session.add_pdmlstate(created_pdml)
            self.pdml_view.set_pdmlstate(pdmlstate)

    def on_clicked_create_session(self, button):
        sp.run_popwindow()

    def on_clicked_open_session(self, button):
        osw.run_popwindow()

    def on_clicked_terminal(self, button):
        test_path = "/home/jesus/PycharmProjects/code/"
        system("gnome-terminal -e 'bash -c \"cd '" + test_path + "'; exec bash\"'")

    def create_stages_buttons(self):
        stage1_img = Gtk.Image.new_from_file("stage1.png")
        stage1_button = Gtk.Button()
        stage1_button.add(stage1_img)

        stage2_img = Gtk.Image.new_from_file("stage2.png")
        stage2_button = Gtk.Button()
        stage2_button.add(stage2_img)

        stage3_img = Gtk.Image.new_from_file("stage3.png")
        stage3_button = Gtk.Button()
        stage3_button.connect("clicked", self.on_clicked_stage3)
        stage3_button.add(stage3_img)

        stage4_img = Gtk.Image.new_from_file("stage4.png")
        stage4_button = Gtk.Button()
        stage4_button.add(stage4_img)

        buttons = gu.create_box([Gtk.Label("\t\t"), stage1_button, stage2_button,  # REMOVE LATER
                                 stage3_button, stage4_button])
        buttons.set_spacing(70)
        return buttons

    def on_clicked_stage3(self, button):
        smv.run_popwindow()
Example #18
0
 def set_user(self, user):
     self.search=User(user)
     return self.search
Example #19
0
class Main(unittest.TestCase):
    op_account = Config('config').data['User'][Config(
        'config').data['run']]['op']
    product_name = Config('productname').data['product_name']
    L = Log('Main')
    toot = Tool()
    # 登录
    buyer = User('18380581406')
    # 切换角色
    pa = PurchaserAction(buyer)
    at = AndroidTool()
    distributor = User('18380581416')
    di = DistributorAction(distributor)

    supplier = User('18380581426')
    su = SupplierAction(supplier)

    operator = Employee(op_account['account'], op_account['password'], 1)
    op = OperatorAction(operator)

    def tearDown(self):
        pass

    def setUp(self):
        url = 'http://203.6.234.220:9660/download/attachments/1016059/user-avatar'
        resp = self.di._mobile_apply_channel_status()
        if resp.get('content') in (1, 2, 3):
            if resp.get('content') in (1, 3):
                self.di._mobile_apply_channel()
            resp = self.op._admin_audit_list(1, 10, 2, self.distributor.mobile,
                                             2).get('content').get('datas')[0]
            self.op._admin_audit_pass(id=resp.get('id'),
                                      user_id=resp.get('userId'),
                                      positive=url,
                                      negative=url,
                                      name='Draven',
                                      gender=1,
                                      birthday='2018-11-11',
                                      id_num='513902199309091011',
                                      province=41,
                                      city=4140,
                                      district=1101104,
                                      address='领馆科技')
        resp = self.di._mobile_apply_channel_status()
        if resp.get('content') == 4:
            self.di._mobile_shop_server_server(10, 10)
            self.di._mobile_shop_server_server(20, 10)

        shop_info = self.di.get_shop_id_by_type(self.distributor.user_id)
        shop_id = shop_info.get('content').get('shopId')
        self.distributor.channel_shop_id = shop_id

        self.L.logger.debug('客户端查询地址列表')
        address_list = self.pa._mobile_address_list()
        if len(address_list['content']) == 0:
            self.L.logger.debug('用户添加收货地址')
            self.pa._mobile_address_add('xiu', self.buyer.mobile, '41', '4101',
                                        '天府五街', 'E3-9', 104.069, 30.539, 1)

    def test0033(self):
        try:
            apk_path = '/Users/hengxin/Downloads/苗叔-20181130\(v1.0.24\).apk'
            self.at.launch_app_by_apk(apk_path)
            self.at.login_miaoshu("18602832572", "888888")
            self.at.enter_shop("自动化刷单勿删")
            self.at.pay_product()
            self.at.tear_down_miaoshu()
            Mail().send_html_email()
            self.L.logger.info("测试完成, 邮件发送成功")
        except Exception as e:
            self.at.get_screen_shot()
            self.L.logger.debug("错误信息: %s" % e)
            self.at.tear_down_miaoshu()

    def test0034(self):
        """
        服务订单的完整流程
        :return:
        """
        shopinfo = self.di.get_shop_id_by_type(self.distributor.user_id)
        shop_id = shopinfo.get('content').get('shopId')
        self.distributor.channel_shop_id = shop_id
        shop = Shop(self.distributor)
        self.L.logger.debug('渠道商新增商品')
        for i in range(3):
            p = Product(user=self.distributor, product_name=str(i))
            self.di.product_save(p)
        self.L.logger.debug('添加接单点')
        self.di.add_address(shop)
        self.L.logger.debug('开始接单')
        self.di.switch_status(shop_id=shop_id)

        order_no = self.di._mobile_channel_service_order_submit(
            buyerId=self.buyer.user_id,
            shopId=shop_id,
            serviceType=20,
            doorTime='2019-12-16 08:00',
            content='养猪',
            earnestMoneyPrice=1,
            doorAddress='ce',
            lng=103,
            lat=40)
        self.di._mobile_channel_service_order_detail(order_no['content'])
        order_info = self.pa._mobile_customer_service_order_detail(
            order_no['content'])
        caindex = self.pa.cashier_index(
            order_info['content']['earnestMoneyTradeNo'])
        self.pa.weipay_pay(order_info['content']['earnestMoneyTradeNo'],
                           caindex['content']['channelList'][0]['id'],
                           order_info['content']['earnestMoneyPrice'])
        self.pa.pay_callback(order_info['content']['earnestMoneyTradeNo'],
                             order_info['content']['earnestMoneyPrice'])
        time.sleep(15)
        self.pa._mobile_customer_service_order_detail(order_no['content'])
        self.di._mobile_channel_service_order_detail(order_no['content'])
        self.di._mobile_channel_service_order_finish_door(
            order_no['content'], 10)

        order_info = self.pa._mobile_customer_service_order_detail(
            order_no['content'])
        caindex = self.pa.cashier_index(
            order_info['content']['tailMoneyTradeNo'])
        self.pa.weipay_pay(order_info['content']['tailMoneyTradeNo'],
                           caindex['content']['channelList'][0]['id'],
                           order_info['content']['tailMoneyPrice'])
        self.pa.pay_callback(order_info['content']['tailMoneyTradeNo'],
                             order_info['content']['tailMoneyPrice'])

        time.sleep(15)
        self.pa._mobile_customer_service_order_detail(order_no['content'])
        self.di._mobile_channel_service_order_detail(order_no['content'])

    def test0035(self):
        """
        服务订单的取消流程
        :return:
        """
        shopinfo = self.di.get_shop_id_by_type(self.distributor.user_id)
        shop_id = shopinfo.get('content').get('shopId')
        self.distributor.channel_shop_id = shop_id

        shop = Shop(self.distributor)
        self.L.logger.debug('渠道商新增商品')
        for i in range(3):
            p = Product(user=self.distributor, product_name=str(i))
            self.di.product_save(p)
        self.L.logger.debug('添加接单点')
        self.di.add_address(shop)
        self.L.logger.debug('开始接单')
        self.di.switch_status(shop_id=shop_id)

        order_no = self.di._mobile_channel_service_order_submit(
            buyerId=self.buyer.user_id,
            shopId=shop_id,
            serviceType=10,
            doorTime='2019-12-16 08:00',
            content='养猪',
            earnestMoneyPrice=1,
            doorAddress='ce',
            lng=103,
            lat=40)
        self.di._mobile_channel_service_order_detail(order_no['content'])
        self.pa._mobile_customer_service_order_detail(order_no['content'])
        self.pa._mobile_customer_service_order_cancel(order_no['content'])
        self.pa._mobile_customer_service_order_detail(order_no['content'])
        self.di._mobile_channel_service_order_detail(order_no['content'])

    def test0036(self):
        """
        张鹏飞:服务订单列表  订单状态,10:待下单, 20:待上门, 30:已结款, 40:已完成, 50: 已取消
        :return:
        """
        self.L.logger.debug("卖家服务订单列表")
        self.di._mobile_channel_service_order_list(10)
        self.di._mobile_channel_service_order_list(20)
        self.di._mobile_channel_service_order_list(30)
        self.di._mobile_channel_service_order_list(40)
        self.di._mobile_channel_service_order_list(50)
        self.L.logger.debug("买家服务订单列表")
        self.pa._mobile_customer_service_order_list(10)
        self.pa._mobile_customer_service_order_list(20)
        self.pa._mobile_customer_service_order_list(30)
        self.pa._mobile_customer_service_order_list(40)
        self.pa._mobile_customer_service_order_list(50)

    def test0037(self):
        """
        张鹏飞:商品订单正向流程
        :return:
        """
        shop_info = self.di.get_shop_id_by_type(self.distributor.user_id)
        shop_id = shop_info.get('content').get('shopId')
        self.distributor.channel_shop_id = shop_id

        self.L.logger.debug('苗叔查询运费模板列表')
        freight_list = self.di.all_freight()
        if len(freight_list['content']) <= 1:
            self.L.logger.debug('苗叔添加运费模板')
            self.di.freight_save_or_update(shop_id, '测试模板66', 500, 10000, 2000)

        self.L.logger.debug('更新店铺信息')
        shop = Shop(self.distributor)
        self.di.update_shop_info(shop)
        self.L.logger.debug('渠道商新增商品')
        for i in range(3):
            p = Product(user=self.distributor,
                        product_name=random.choice(self.product_name))
            self.di.product_save(p)
            if i == 0:
                self.L.logger.debug('苗叔筛选查看库存商品列表')
                store_list = self.di.store_list_product(p)
                pro_code = store_list.get('content').get('datas')[0]['pcode']
                self.L.logger.debug('苗叔更新商品库存')
                self.di.store_update_product(pro_code)

                self.L.logger.debug('苗叔筛选查看商品列表')
                pro_list = self.di.list_product(p)
                pro_code = pro_list.get('content').get('datas')[0]['pcode']
                self.L.logger.debug('苗叔上架商品')
                self.di.status_update_product(pro_code)
                self.L.logger.debug('苗叔下架商品')
                self.di.status_update_product(pro_code, 20)
                self.L.logger.debug('苗叔删除商品')
                self.di.status_update_product(pro_code, 30)

        self.L.logger.debug('添加接单点')
        self.di.add_address(shop)
        self.L.logger.debug('开始接单')
        self.di.switch_status(shop_id=shop_id)

        self.L.logger.debug('客户端查询地址列表')
        address_list = self.pa._mobile_address_list()
        address = address_list['content'][0]
        add_id = address['id']

        self.L.logger.debug('客户端查询店铺信息')
        self.pa.get_shop_info_by_id(shop_id)
        self.L.logger.debug('店铺内商品列表')
        product_list = self.pa.get_shop_products_by_shop_id(shop_id)
        p_code = self.pa.tool.get_pro_code_by_pro_list(product_list['content'])

        self.L.logger.debug('添加购物车')
        self.pa.cart_add(p_code)
        self.L.logger.debug('购物车列表')
        cart_list = self.pa.get_cart_list()
        self.L.logger.debug('购物车结算')
        sure_order = self.pa.cart_balance(
            self.pa.tool.get_cart_ids_by_cart_list(cart_list, shop_id), add_id)
        self.L.logger.debug('确认提交订单')
        order = self.pa.submit_order(
            self.pa.tool.order_info_change(sure_order))
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('收银台')
        order_pay_info = self.pa.cashier_index(order['content']['tradeNo'])
        self.L.logger.debug('支付')
        self.pa.weipay_pay(order['content']['tradeNo'],
                           order_pay_info['content']['channelList'][0]['id'],
                           order_pay_info['content']['amount'])
        self.L.logger.debug('付款')
        self.pa.pay_callback(order['content']['tradeNo'],
                             order_pay_info['content']['amount'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('买家未完成配送前取消订单')
        self.pa._mobile_customer_order_apply_refund(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('苗叔拒绝取消订单')
        self.di._mobile_channel_order_refuse(order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('渠道商完成配送')
        self.di.finish_send_order(order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('买家完成配送后取消订单')
        self.pa._mobile_customer_order_apply_refund(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('苗叔拒绝取消订单')
        self.di._mobile_channel_order_refuse(order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('用户确认收货')
        self.pa.confirm_receive(order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])

    def test0038(self):
        """
        张鹏飞:待付款订单取消
        :return:
        """
        shop_info = self.di.get_shop_id_by_type(self.distributor.user_id)
        shop_id = shop_info.get('content').get('shopId')
        self.distributor.channel_shop_id = shop_id

        self.L.logger.debug('更新店铺信息')
        shop = Shop(self.distributor)
        self.di.update_shop_info(shop)
        self.L.logger.debug('渠道商新增商品')
        for i in range(3):
            p = Product(user=self.distributor, product_name=str(i))
            self.di.product_save(p)
        self.L.logger.debug('添加接单点')
        self.di.add_address(shop)
        self.L.logger.debug('开始接单')
        self.di.switch_status(shop_id=shop_id)

        self.L.logger.debug('客户端查询地址列表')
        address_list = self.pa._mobile_address_list()
        address = address_list['content'][0]
        add_id = address['id']

        self.L.logger.debug('客户端查询店铺信息')
        self.pa.get_shop_info_by_id(shop_id)
        self.L.logger.debug('店铺内商品列表')
        product_list = self.pa.get_shop_products_by_shop_id(shop_id)
        p_code = self.pa.tool.get_pro_code_by_pro_list(product_list['content'])

        self.L.logger.debug('添加购物车')
        self.pa.cart_add(p_code)
        self.L.logger.debug('购物车列表')
        cart_list = self.pa.get_cart_list()
        self.L.logger.debug('购物车结算')
        sure_order = self.pa.cart_balance(
            self.pa.tool.get_cart_ids_by_cart_list(cart_list, shop_id), add_id)
        self.L.logger.debug('确认提交订单')
        order = self.pa.submit_order(
            self.pa.tool.order_info_change(sure_order))
        self.L.logger.debug('关闭订单')
        self.pa.order_close(order['content']['orderNo'])

    def test0039(self):
        """
        张鹏飞:待配送订单取消成功
        :return:
        """
        shop_info = self.di.get_shop_id_by_type(self.distributor.user_id)
        shop_id = shop_info.get('content').get('shopId')
        self.distributor.channel_shop_id = shop_id

        self.L.logger.debug('更新店铺信息')
        shop = Shop(self.distributor)
        self.di.update_shop_info(shop)
        self.L.logger.debug('渠道商新增商品')
        for i in range(3):
            p = Product(user=self.distributor, product_name=str(i))
            self.di.product_save(p)
        self.L.logger.debug('添加接单点')
        self.di.add_address(shop)
        self.L.logger.debug('开始接单')
        self.di.switch_status(shop_id=shop_id)

        # self.L.logger.debug('用户添加收货地址')
        # self.pa._mobile_address_add('xiu', 19982917912, '41', '4101', '天府五街', 'E3-9', 104.069, 30.539, 1)
        self.L.logger.debug('客户端查询地址列表')
        address_list = self.pa._mobile_address_list()
        address = address_list['content'][0]
        add_id = address['id']

        self.L.logger.debug('客户端查询店铺信息')
        self.pa.get_shop_info_by_id(shop_id)
        self.L.logger.debug('店铺内商品列表')
        product_list = self.pa.get_shop_products_by_shop_id(shop_id)
        p_code = self.pa.tool.get_pro_code_by_pro_list(product_list['content'])

        self.L.logger.debug('添加购物车')
        self.pa.cart_add(p_code)
        self.L.logger.debug('购物车列表')
        cart_list = self.pa.get_cart_list()
        self.L.logger.debug('购物车结算')
        sure_order = self.pa.cart_balance(
            self.pa.tool.get_cart_ids_by_cart_list(cart_list, shop_id), add_id)
        self.L.logger.debug('确认提交订单')
        order = self.pa.submit_order(
            self.pa.tool.order_info_change(sure_order))
        self.L.logger.debug('订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('收银台')
        order_pay_info = self.pa.cashier_index(order['content']['tradeNo'])
        self.L.logger.debug('支付')
        self.pa.weipay_pay(order['content']['tradeNo'],
                           order_pay_info['content']['channelList'][0]['id'],
                           order_pay_info['content']['amount'])
        self.L.logger.debug('付款')
        self.pa.pay_callback(order['content']['tradeNo'],
                             order_pay_info['content']['amount'])

        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('买家未完成配送前取消订单')
        self.pa._mobile_customer_order_apply_refund(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('苗叔拒绝取消订单')
        self.di._mobile_channel_order_refuse(order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('买家未完成配送前取消订单')
        self.pa._mobile_customer_order_apply_refund(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('苗叔同意取消订单')
        self.di._mobile_channel_order_agree(order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])

    def test0040(self):
        """
        张鹏飞:已配送完成的订单,买家取消订单,卖家同意
        :return:
        """
        shop_info = self.di.get_shop_id_by_type(self.distributor.user_id)
        shop_id = shop_info.get('content').get('shopId')
        self.distributor.channel_shop_id = shop_id

        self.L.logger.debug('更新店铺信息')
        shop = Shop(self.distributor)
        self.di.update_shop_info(shop)
        self.L.logger.debug('渠道商新增商品')
        for i in range(3):
            p = Product(user=self.distributor, product_name=str(i))
            self.di.product_save(p)
        self.L.logger.debug('添加接单点')
        self.di.add_address(shop)
        self.L.logger.debug('开始接单')
        self.di.switch_status(shop_id=shop_id)

        # self.L.logger.debug('用户添加收货地址')
        # self.pa._mobile_address_add('xiu', 19982917912, '41', '4101', '天府五街', 'E3-9', 104.069, 30.539, 1)
        self.L.logger.debug('客户端查询地址列表')
        address_list = self.pa._mobile_address_list()
        address = address_list['content'][0]
        add_id = address['id']

        self.L.logger.debug('客户端查询店铺信息')
        self.pa.get_shop_info_by_id(shop_id)
        self.L.logger.debug('店铺内商品列表')
        product_list = self.pa.get_shop_products_by_shop_id(shop_id)
        p_code = self.pa.tool.get_pro_code_by_pro_list(product_list['content'])

        self.L.logger.debug('添加购物车')
        self.pa.cart_add(p_code)
        self.L.logger.debug('购物车列表')
        cart_list = self.pa.get_cart_list()
        self.L.logger.debug('购物车结算')
        sure_order = self.pa.cart_balance(
            self.pa.tool.get_cart_ids_by_cart_list(cart_list, shop_id), add_id)
        self.L.logger.debug('确认提交订单')
        order = self.pa.submit_order(
            self.pa.tool.order_info_change(sure_order))
        self.L.logger.debug('订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('收银台')
        order_pay_info = self.pa.cashier_index(order['content']['tradeNo'])
        self.L.logger.debug('支付')
        self.pa.weipay_pay(order['content']['tradeNo'],
                           order_pay_info['content']['channelList'][0]['id'],
                           order_pay_info['content']['amount'])
        self.L.logger.debug('付款')
        self.pa.pay_callback(order['content']['tradeNo'],
                             order_pay_info['content']['amount'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('买家未完成配送前取消订单')
        self.pa._mobile_customer_order_apply_refund(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('苗叔拒绝取消订单')
        self.di._mobile_channel_order_refuse(order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('渠道商完成配送')
        self.di.finish_send_order(order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('买家完成配送后取消订单')
        self.pa._mobile_customer_order_apply_refund(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])
        self.L.logger.debug('苗叔同意取消订单')
        self.di._mobile_channel_order_agree(order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('买家订单详情')
        self.pa.order_detail(order['content']['orderNo'])
        self.L.logger.debug('卖家订单详情')
        self.di.shopping_order_detail(order['content']['orderNo'])

    def test0041(self):
        """
        张鹏飞:商品订单列表  订单状态,10:待下单, 20:待上门, 30:已结款, 40:已完成, 50: 已取消
        :return:
        """
        self.L.logger.debug("卖家商品订单待处理列表")
        self.di.list_order(20)
        self.L.logger.debug("卖家商品订单待买家收货列表")
        self.di.list_order(30)
        self.L.logger.debug("卖家商品订单已完成列表")
        self.di.list_order(40)
        self.L.logger.debug("卖家商品订单已退款已取消列表")
        self.di.list_order(70)
        self.L.logger.debug("买家商品订单列表")
        self.pa.order_list(10)
        self.pa.order_list(20)
        self.pa.order_list(30)
        self.pa.order_list(40)
        self.pa.order_list((50, 70))

    def test0042(self):
        """
        baiying:苗叔向基地购买商品正向流程
        :return:
        """
        shop_info = self.su.get_shop_id_by_type(self.supplier.user_id)
        shop_id = shop_info.get('content').get('shopId')
        self.supplier.supplier_shop_id = shop_id
        self.L.logger.debug('更新店铺信息')
        shop = Shop(self.supplier)
        self.su.update_shop_info(shop)
        self.L.logger.debug('基地新增商品')
        for i in range(3):
            p = Product(user=self.supplier, product_name=str(i))
            self.su.product_save(p)
        self.L.logger.debug('基地地址')
        address_list = self.su.history_address(shop_id)
        if len(address_list['content']) == 0:
            self.L.logger.debug('基地添加店铺地址')
            self.su._mobile_address_add('xiu', self.buyer.mobile, '41', '4101',
                                        '天府五街', 'E3-9', 104.069, 30.539, 1)
        self.L.logger.debug('开始接单')
        self.su.switch_status(shop_id=shop_id)
        self.L.logger.debug('客户端查询地址列表')
        address_list = self.di._mobile_address_list()
        address = address_list['content'][0]
        add_id = address['id']
        self.L.logger.debug('客户端查询店铺信息')
        self.di.get_shop_info_by_id(shop_id)
        self.L.logger.debug('店铺内商品列表')
        product_list = self.pa.get_shop_products_by_shop_id(shop_id)
        p_code = self.pa.tool.get_pro_code_by_pro_list(product_list['content'])
        self.L.logger.debug('添加购物车')
        self.di.cart_add(p_code)
        self.L.logger.debug('购物车列表')
        cart_list = self.di.get_cart_list()
        self.L.logger.debug('购物车结算')
        sure_order = self.di.cart_balance(
            self.pa.tool.get_cart_ids_by_cart_list(cart_list, shop_id), add_id)
        self.L.logger.debug('确认提交订单')
        order = self.di.submit_order(
            self.pa.tool.order_info_change(sure_order))
        self.L.logger.debug('苗叔订单详情')
        self.di._mobile_supply_customer_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('收银台')
        order_pay_info = self.di.cashier_index(order['content']['tradeNo'])
        self.L.logger.debug('支付')
        self.di.weipay_pay(order['content']['tradeNo'],
                           order_pay_info['content']['channelList'][0]['id'],
                           order_pay_info['content']['amount'])
        self.L.logger.debug('付款')
        self.di.pay_callback(order['content']['tradeNo'],
                             order_pay_info['content']['amount'])
        time.sleep(10)
        self.L.logger.debug('苗叔订单详情')
        self.di._mobile_supply_customer_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('基地订单详情')
        self.su._mobile_supply_channel_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('苗叔未完成配送前取消订单')
        self.di._mobile_supply_customer_order_apply_refund(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('苗叔订单详情')
        self.di._mobile_supply_customer_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('基地订单详情')
        self.su._mobile_supply_channel_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('苗叔未完成配送前取消订单')
        self.L.logger.debug('基地拒绝取消订单')
        self.su._mobile_supply_channel_order_refuse(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('苗叔订单详情')
        self.di._mobile_supply_customer_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('基地订单详情')
        self.su._mobile_supply_channel_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('基地完成配送')
        self.su._mobile_supply_channel_order_finish_send(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('苗叔订单详情')
        self.di._mobile_supply_customer_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('基地订单详情')
        self.su._mobile_supply_channel_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('苗叔完成配送后取消订单')
        self.di._mobile_supply_customer_order_apply_refund(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('苗叔订单详情')
        self.di._mobile_supply_customer_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('基地订单详情')
        self.su._mobile_supply_channel_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('基地拒绝取消订单')
        self.su._mobile_supply_channel_order_refuse(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('苗叔订单详情')
        self.di._mobile_supply_customer_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('基地订单详情')
        self.su._mobile_supply_channel_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('苗叔确认收货')
        self.di._mobile_supply_customer_order_confirm_receive(
            order['content']['orderNo'])
        time.sleep(10)
        self.L.logger.debug('苗叔订单详情')
        self.di._mobile_supply_customer_order_detail(
            order['content']['orderNo'])
        self.L.logger.debug('基地订单详情')
        self.su._mobile_supply_channel_order_detail(
            order['content']['orderNo'])

    def test0043(self):
        """
        张鹏飞:运营后台订单数据
        :return:
        """
        self.op._admin_report_order_pie_sta('2018-12-1', '2018-12-20')
        self.op._admin_report_order_summary_sta('2018-12-1', '2018-12-20')
        self.op._admin_report_service_order_service_data_card(
            '2018-12-1', '2018-12-20')
        self.op._admin_report_service_order_service_data_trend(
            '2018-12-1', '2018-12-20')
        self.op._admin_report_service_order_service_type_distribution(
            '2018-12-1', '2018-12-20')
Example #20
0
from django.core.mail import send_mail
from random import Random
from django.db.models.signals import pre_delete
from django.dispatch.dispatcher import receiver
# from django.views.decorators.csrf import csrf_exempt,csrf_protect
from django.http import JsonResponse
import json
import codecs
import csv
import os
import re
import pandas as pd
# codecs专门用作编码转换,当我们要做编码转换的时候可以借助codecs很简单的进行编码转换
from requests_toolbelt.multipart.decoder import MultipartDecoder

User.test_database()
files = Files()


def random_password(random_length=6):
    temp_password = ''
    chars = 'abcdefghijklmnopqrstuvwsyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
    length = len(chars) - 1
    random = Random()
    for i in range(random_length):
        temp_password += chars[random.randint(0, length)]
    return temp_password


# send_mail的参数分别是:邮件标题,邮件内容,发件箱(settings.py中设置过的那个),收件箱列表(可以发送给多个人)
# 失败静默(若发送失败,报错提示我们)
Example #21
0
    def _mobile_account_sales_bill(self, pageSize, pageNum):
        data = {'_tk_': self.user.token, '_deviceId_': self.user.device_id, 'pageSize': pageSize, 'pageNum': pageNum}
        response = self.request.post(url='https://dev.ms.pay.sjnc.com/mobile/account/sales-bill', data=data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response


if __name__ == '__main__':
    from backend.User import User
    user = User('18382373185')
    us = userAction(user)
    # us._admin_situation_info("2018-12-18", "2018-12-19")
    # us._admin_situation_service_order_quantity("2018-12-18", "2018-12-19")
    # us._admin_situation_service_tansactions("2018-12-18", "2018-12-19")
    # us._mobile_account_sales_amount()
    # us._mobile_account_sales_bill(1, 2)

    # us._mobile_apply_channel()
    # us._mobile_apply_supplier()
    # us._mobile_apply_channel_status()
    # us._mobile_apply_supplier_status()
    # us._admin_audit_list('1', '20', '4', '18382373185', '2')
    # us._admin_audit_upload()
    # us._admin_audit_pass('127', '1210', 'https://dnkj-family-farm-1.oss-cn-huhehaote.aliyuncs.com/data/ms-user/applyMa'
    #                      'terials/1544852604402.png?Expires=1544852897&OSSAccessKeyId=LTAIln07EgYJRc0Z&S''ignature=jTDa'
Example #22
0
 def set_user(self, user):
     self.user = User(user)
     return self.user
        suggested_itineraries['results'][option_nb][
            'duration'] = transport_option.total_duration
        suggested_itineraries['results'][option_nb][
            'polyline_encoded'] = transport_option.total_polyline
        suggested_itineraries['results'][option_nb]['instructions'] = repr(
            transport_option).replace("\n", "<br />")

        if transport_option is 'driving':
            suggested_itineraries['results'][option][
                'distance'] = transport_option.driving_distance
        if transport_option is 'walking':
            suggested_itineraries['results'][option][
                'distance'] = transport_option.walking_distance
        if transport_option is 'bicycling':
            suggested_itineraries['results'][option][
                'distance'] = transport_option.bicycling_distance
        if transport_option is 'uber':
            suggested_itineraries['results'][option][
                'wait_time'] = transport_option.uber_wait_duration

    return suggested_itineraries


if __name__ == "__main__":
    """Script de test"""
    origin = Place("8 avenue Adrien Hebrard")
    destination = Place("nation")
    iti = Itinerary(origin=origin, destination=destination)
    pierre = User('PMR', True, False, False)
    print(Suggested_Itineraries(pierre, iti))
        response = self.request.post(
            url='http://dev.ms.shop.sjnc.com/mobile/address/history',
            data=data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response


if __name__ == '__main__':
    from backend.User import User
    seller = User("18382373185")
    da = SupplierAction(seller)
    # da._mobile_supply_channel_order_list(20, 1, 2)
    # da._mobile_supply_channel_order_detail('JDSP2018121911181295506002')
    # da._mobile_supply_channel_order_refuse("JDSP2018121911191917806004")
    # da._mobile_supply_channel_order_agree("JDSP2018121911181295506002")
    # da._mobile_supply_channel_order_finish_send("JDSP2018121914191079106010")
    # da._mobile_supply_channel_order_pending_count(146)
    # da.supp_upload('E:/MiaoShuAutoTest31/utils/picture/1.jpeg', '1.jpeg')
    # da.supp_update(da.supp_upload('./../actions/1.jpeg', '1.jpeg'),
    #                da.supp_upload('./../actions/1.jpg', '1.jpg'))
    # da.supp_get_fail()
    #seller.change_identity(3)
    # da.shop_get()
    # da.upload_avatar('E:/MiaoShuAutoTest31/utils/picture/1.jpeg', '1.jpeg')
    # da.shop_send_verify_code("13400000000")
Example #25
0
def admin_write(obj_type):
    """Write new object to DB or edit an existing one based on submitted form"""
    # Set basic values present for all object types
    name = request.form.get("name")
    try:
        id = int(request.form.get("id"))
        if not id:
            id = None
    except ValueError:
        id = None

    # Construct object to be written
    if obj_type == "allergies":
        obj = Allergy(name, db, id)
    elif obj_type == "ingredient_categories":
        obj = IngredientCategory(name, db, id)
    elif obj_type == "ingredients":
        category_id = request.form.get("category_id")
        category = IngredientCategory.from_db(db=db, id=category_id)
        allergy_ids = request.form.getlist("allergies")
        allergies = {Allergy.from_db(db=db, id=id) for id in allergy_ids}

        obj = Ingredient(name, category, allergies, db, id)
    elif obj_type == "recipes":
        instructions = request.form.get("instructions")

        contents = set()
        try:
            form_contents = json.loads(request.form.get("contents"))
        except:
            form_contents = None
        for fc in form_contents:
            ingredient = Ingredient.from_db(db=db, id=fc["ingredient_id"])
            try:
                amount = float(fc["amount"])
            except KeyError:
                amount = 0
            units = fc["units"] if fc["units"] != "" else None

            contents.add(Content(ingredient, amount, units))

        obj = Recipe(name, instructions, contents, db, id)

        # Define function to be called only if object is written to DB successfully
        def if_written():
            # Apply image changes to the filesystem
            filename = str(obj.id) + ".jpg"
            if request.form.get("image-delete"):
                # Current image is to be deleted if exists
                try:
                    os.remove(os.path.join(app.config["RECIPE_IMG_PATH"], filename))
                except FileNotFoundError:
                    pass
            else:
                # New image is to be saved
                image = request.files.get("image")
                if image:
                    extension = image.filename.split(".").pop()
                    if extension in ALLOWED_IMG_EXTENSIONS:
                        image.save(os.path.join(app.config["RECIPE_IMG_PATH"], filename))
                    else:
                        flash("Only .jpg, .jpeg images allowed", category=danger)
    elif obj_type == "users":
        obj = User.from_db(db, id)
        obj.is_admin = request.form.get("is_admin")
        obj.name = request.form.get("name")
    else:
        return ("Object type not found")


    try:
        result = obj.write_to_db()
    except:
        result = False

    if result:
        flash("Changes saved successfully!")
        try:
            if_written()
        except UnboundLocalError:
            pass
    else:
        flash("Something went wrong :(", category="danger")

    return redirect("admin/" + obj_type)