@RequireLogin()
def post(request):
    try:
        new = json.loads(request.body)
        assert "name" in new
    except ValueError:
        return HttpResponseBadRequest("invalid JSON")
    except AssertionError:
        return HttpResponseBadRequest("argument mismatch")

    if 'rules' in new:
        new['rules'] = [rule_model.validate(rule) for rule in new['rules']]
        if None in new['rules']:  # Invalid rules are re-assigned to None
            return HttpResponse("invalid rule(s) provided")

    dbc = db_model.connect()
    testplan = dbc.testplan.find_one({"name": new['name']})
    if testplan is not None:
        return HttpResponseBadRequest("testplan named '%s' already exists" % new['name'])

    new['createdAt'] = datetime.isoformat(datetime.now())
    new['updatedAt'] = datetime.isoformat(datetime.now())
    testplan_id = str(dbc.testplan.save(new))
    r = JsonResponse({"id": testplan_id}, status=200)
    r['location'] = "/api/testplan/%s" % testplan_id
    logger.info("test plan '%s' created by '%s'" % (testplan_id, request.user['username']))
    return r
Create new test plan.
dataset/ETHPy150Open emccode/heliosburn/heliosburn/django/hbproject/api/views/testplan.py/post