コード例 #1
0
def test_importjson_without_drop(cli_runner, db, request):
    collection = "models"
    json_file = "{}/ressources/json/models.json.example".format(BASE_DIR)

    # Inserting an action card beforehand
    model1 = Model(
        footprintStructure={"footprint_category_1": "variable_1"},
        variableFormulas={
            "variable_1": {
                "+": [{
                    "var": "global_variable_name"
                }, 1295]
            }
        },
        globalCarbonVariables={"global_variable_name": 42},
    )
    model1.save()

    with open(json_file, "r") as fr:
        json_data = json.load(fr)
    count = len(json_data) if isinstance(json_data, list) else 1

    result = cli_runner.invoke(importjson,
                               ["--no-drop", collection, json_file])
    assert ("Successfully inserted {} objects in collection {}".format(
        count, collection) in result.output)
    assert len(Model.objects()) == count + 1

    def teardown():
        Model.drop_collection()

    request.addfinalizer(teardown)
コード例 #2
0
ファイル: conftest.py プロジェクト: JimmyE2017/back-end
def models(db, request):
    model1 = Model(
        footprintStructure={"var1": "var1"},
        globalCarbonVariables={"var1": "var1"},
        variableFormulas={"var1": "var1"},
        createdAt=datetime.utcnow(),
    )

    model2 = Model(
        footprintStructure={"var1": "var1"},
        globalCarbonVariables={"var1": "var1"},
        variableFormulas={"var1": "var1"},
        createdAt=datetime.utcnow() + timedelta(days=1),
    )

    model1.save()
    model2.save()

    def teardown():
        model1.delete()
        model2.delete()

    request.addfinalizer(teardown)
    return [model1, model2]
コード例 #3
0
def create_workshop(data: bytes) -> (dict, int):
    # Deserialize data
    schema = WorkshopSchema()
    data, err_msg, err_code = schema.loads_or_400(data)
    if err_msg:
        return err_msg, err_code

    # Check existence of given coachId
    coach_id = data["coachId"]
    coach = UserModel.find_by_id(coach_id)
    if coach is None:
        raise InvalidDataError("Coach does not exist : {}".format(coach_id))

    workshop = WorkshopModel(**data)
    # Append creator id
    workshop.creatorId = get_jwt_identity()
    # Append last created model id
    model = Model.find_last_created_model()
    workshop.model = model

    workshop.save()

    workshop.reload()
    return schema.dump(workshop), 200
コード例 #4
0
ファイル: conftest.py プロジェクト: JimmyE2017/back-end
def model(db, request):
    model = Model(
        footprintStructure={
            "cf1": "variable_1",
            "cf2": {
                "cf2_1": "variable_2",
                "cf2_2": "variable_3"
            },
        },
        globalCarbonVariables={
            "global_variable_1": 100,
            "global_variable_2": {
                "key1": 101,
                "key2": 102
            },
        },
        variableFormulas={
            "variable_1": {
                "+": [{
                    "var": "global_variable_1"
                }, {
                    "var": "survey_variable_1"
                }]
            },
            "variable_2": {
                "*": [
                    {
                        "var": {
                            "cat": [
                                "global_variable_2.", {
                                    "var": "survey_variable_2"
                                }
                            ]
                        }
                    },
                    {
                        "var": "survey_variable_3"
                    },
                ]
            },
            "variable_3": {
                "*": [
                    {
                        "var": {
                            "cat": [
                                "global_variable_2.", {
                                    "var": "survey_variable_2"
                                }
                            ]
                        }
                    },
                    0.5,
                ]
            },
        },
    )

    model.save()

    def teardown():
        model.delete()

    request.addfinalizer(teardown)
    return model
コード例 #5
0
 def teardown():
     Model.drop_collection()