def test_update_post_verify_content(self):
        _calling_method()
        api.create_category(name="Test_category", id=4)
        response = api.get_category(id=4)
        category = response.json()

        new_post = {"title": "Test Title",
                    "body": "Test body",
                    "category_id": 4
                    }

        update_post = {"id": 6,
                       "title": "Test Title updated",
                       "body": "Test body updated",
                       "category": category.get("name"),
                       "category_id": 4
                       }

        api.create_post(**new_post)
        api.update_post(**update_post)

        expected = {"title": update_post.get("title"),
                    "body": update_post.get("body"),
                    "category": category.get("name"),
                    "category_id": update_post.get("category_id"),
                    "id": 5  # to deal with know issue of get_post returning id+1 when selecting id=5 or above
                    }

        self.assertTrue(api._verify_post(expected, id=expected.get("id"), exclude_id=True))
    def test_get_post_verify_contents_id_5(self):
        _calling_method()
        kwargs = {"title": "Encounter in the Dawn",
                  "body": "As he led the tribe down to the river in the dim light of dawn, Moon-Watcher paused uncertainly at a familiar spot. Something, he knew, was missing; but what it was, he could not remember. He wasted no mental effort on the problem, for this morning he had more important matters on his mind.",
                  "category_id": 1,
                  "id": 5
                  }

        api.create_category(name="Test_category", id=4)

        response = api.get_category(id=1)
        category = response.json()

        expected = {"title": kwargs.get("title"),
                    "body": kwargs.get("body"),
                    "category": category.get("name"),
                    "category_id": kwargs.get("category_id"),
                    "id": kwargs.get("id"),
                    }

        new_post = {"title": "Test Title",
                    "body": "Test body",
                    "category_id": 4
                    }

        api.create_post(**new_post)
        self.assertTrue(api._verify_post(expected, id=expected.get("id")))
Beispiel #3
0
def category_id_to_category_name(id):
    d = get_category(id)

    if 'name' in d:
        return d['name']

    logger.warn(
        f"Cannot find name for category id '{id}'. Saving just category id.")
    return id
Beispiel #4
0
def setup():
    #turn string of team names into a list
    teams = request.form.get("team_names").split(",")
    teams.pop()

    #initialize global variables
    global info
    global categories
    global questions
    global scores
    global score_rule
    global penalty

    #info is a dictionary: keys are question categories selected by user
    #values are lists containing true/false values where true means question has been answered already
    info = {}

    #categories is a list of question categories selected by user
    categories = []
    
    #questions is a list containing each card's question, incorrect and correct answers
    questions = []
    
    #scores is a dictionary: keys are team names and values are # of points earned by teams
    scores = {}
    for team in teams:
        scores[team] = 0

    #cats: local variable storing inputted categories from HTML form
    cats = request.form.getlist("category")
    
    for cat in cats:
        info[api.get_category(int(cat))] = [False] * 5
        questions.append(api.get_questions(int(cat)))
        categories.append(api.get_category(int(cat)))
    score_rule = request.form.get('score_rule')
    if (score_rule == "customized"):
        penalty = int(request.form.get('deduct'))
    return render_template("questions.html", correct = json.dumps(""),teams=teams, info=info, categories=json.dumps(categories), clicked=json.dumps(info),scores=scores)
    def test_get_post_verify_contents_id_1(self):
        _calling_method()
        kwargs = {"title": "The Road to Extinction",
                  "body": "The drought had lasted now for ten million years, and the reign of the terrible lizards had long since ended. Here on the Equator, in the continent which would one day be known as Africa, the battle for existence had reached a new climax of ferocity, and the victor was not yet in sight. In this barren and desiccated land, only the small or the swift or the fierce could flourish, or even hope to survive.",
                  "category_id": 1
                  }

        response = api.get_category(id=1)
        category = response.json()

        expected = {"title": kwargs.get("title"),
                    "body": kwargs.get("body"),
                    "category": category.get("name"),
                    "category_id": kwargs.get("category_id"),
                    "id": 1
                    }

        self.assertTrue(api._verify_post(expected, id=expected.get("id")))
Beispiel #6
0
def get_first_category(category_ids):
    """
    Retrieve the first group from a list of group_ids
    """

    return api.get_category(category_ids[0]) if category_ids else None
Beispiel #7
0
def item_diff_content(request, template_name):
    '''
    商品层级
    :param request:
    :param template_name:
    :return:
    '''
    result = {'status': 0, 'message': ''}

    month_ragezb_data, day_ragezb_data, month_rage_data, day_rage_data = [], [], [], []
    param = json.loads(request.body)

    data_source = param.get("data_source")
    min_rate = param.get("min_rate")
    max_rate = param.get("max_rate")
    category_id = param.get("category_id")
    min_date = param.get("min_date")
    max_date = param.get("max_date")
    dates = param.get("dates")

    if not data_source:
        return JsonResponse({'status': 0, 'message': '参数错误'}, safe=False)

    if not api.is_digit(min_rate):
        return JsonResponse({'status': 0, 'message': '参数错误'}, safe=False)

    if not api.is_digit(max_rate):
        return JsonResponse({'status': 0, 'message': '参数错误'}, safe=False)

    if not category_id:
        return JsonResponse({'status': 0, 'message': '参数错误'}, safe=False)

    if (not min_date or not max_date) and not dates:
        return JsonResponse({'status': 0, 'message': '参数错误'}, safe=False)

    param["compare_table"] = api.get_compare_table(data_source)
    param["shop_ids"] = "69302618,66098091,73401272"
    param["min_rate"] = float(min_rate) / 100.0
    param["max_rate"] = float(max_rate) / 100.0

    if min_date and max_date:
        month_ragezb_data = api.item_month_ragezb_data(param)
        month_rage_data = api.item_month_rage_data(param)

    if dates:
        param["dates"] = "','".join(dates.split(","))
        day_ragezb_data = api.item_day_ragezb_data(param)
        day_rage_data = api.item_day_rage_data(param)

    category = api.get_category(category_id)
    data = dict(
        month_ragezb_data=month_ragezb_data,
        day_ragezb_data=day_ragezb_data,
        month_rage_data=json.dumps(month_rage_data),
        day_rage_data=json.dumps(day_rage_data),
        category_name=category.name,
    )

    response = render(request, template_name, data)

    result["status"] = 1
    result["data"] = response.content

    return JsonResponse(result, safe=False)
Beispiel #8
0
def category_diff_content(request, template_name):
    '''
    品类层级
    :param request:
    :param template_name:
    :return:
    '''
    result = {'status': 0, 'message': ''}

    month_ragezb_data, day_ragezb_data, month_rage_data, day_rage_data = [], [], [], []
    param = json.loads(request.body)

    data_source = param.get("data_source", 1)
    min_qty = param["min_qty"] = param["min_qty"] if param.get("min_qty") else "40"
    min_rate = param.get("min_rate", -10)
    max_rate = param.get("max_rate", 10)
    category_id = param.get("category_id")
    min_date = param.get("min_date")
    max_date = param.get("max_date")
    dates = param.get("dates")

    if not data_source:
        return JsonResponse({'status': 0, 'message': '参数错误'}, safe=False)

    if not min_qty.isdigit():
        return JsonResponse({'status': 0, 'message': '参数错误'}, safe=False)

    if not api.is_digit(min_rate):
        return JsonResponse({'status': 0, 'message': '参数错误'}, safe=False)

    if not api.is_digit(max_rate):
        return JsonResponse({'status': 0, 'message': '参数错误'}, safe=False)

    if (not min_date or not max_date) and not dates:
        return JsonResponse({'status': 0, 'message': '参数错误'}, safe=False)

    if category_id:
        param["category_where"] = ' and categoryid = {0} '.format(category_id)
        category_list = [api.get_category(category_id).values("id", "name")]
    else:
        param["category_where"] = ""
        category_list = Category.objects.filter(pid=0, industry=16).values("id", "name")

    param["compare_table"] = api.get_compare_table(data_source)
    param["shop_ids"] = "69302618,66098091,73401272"
    param["min_rate"] = float(min_rate) / 100.0
    param["max_rate"] = float(max_rate) / 100.0

    if min_date and max_date:
        daterange_list = api.get_daterange_list(min_date, max_date)
        month_rage_data = api.category_month_rage_data(param, daterange_list, category_list)
        month_rage_shop_data = api.category_month_rage_shop_data(param, daterange_list, category_list)

    if dates:
        daterange_list = dates.split(",")
        param["dates"] = "','".join(daterange_list)

        day_rage_data = api.category_day_rage_data(param, daterange_list, category_list)
        day_rage_shop_data = api.category_day_rage_shop_data(param, daterange_list, category_list)

    data = dict(
        month_rage_data=json.dumps(month_rage_data),
        month_rage_shop_data=json.dumps(month_rage_shop_data),
        day_rage_data=json.dumps(day_rage_data),
        day_rage_shop_data=json.dumps(day_rage_shop_data),
        category_list=category_list,
    )

    response = render(request, template_name, data)

    result["status"] = 1
    result["data"] = response.content

    return JsonResponse(result, safe=False)
 def test_get_category_not_found_404(self):
     _calling_method()
     response = api.get_category(4)
     self.assertEqual(404, response.status_code,
                      f"Incorrect Response Code return : {response.status_code} but expected 404")
 def test_get_category_found_200(self):
     _calling_method()
     api.create_category(name="Test_category", id=4)
     response = api.get_category(4)
     self.assertEqual(200, response.status_code,
                      f"Incorrect Response Code return : {response.status_code} but expected 200")