def test_that_models_can_be_overridden(self):
     gen_paed_record(formulation="form_tra")
     gen_paed_record(formulation="form_trb")
     gen_adult_record(formulation="form_tra", new=300, existing=300)
     definition_builder = DefinitionFactory().traced(
         tracer={
             "slug": "trace1",
             "patient_formulations": ["form_tra", "form_trb"]
         })
     definition_builder.model("Paed").model_overrides(
         {"trace1": {
             "id": "Adult",
             "formulations": ["form_tra"]
         }})
     definition_builder.tracing_formulations("patient_formulations",
                                             "form_tra", "form_trb")
     definition_builder.are_equal()
     definition = definition_builder.get()
     response = self.app.post_json(self.url,
                                   user="******",
                                   params=definition,
                                   expect_errors=True)
     json_response = loads(response.content.decode("utf8"))
     self.assertEqual(200, response.status_code)
     assert_that(
         json_response,
         has_entry(
             equal_to("groups"),
             has_item(
                 has_entries({
                     "name":
                     equal_to("G1"),
                     "aggregation":
                     "SUM",
                     "values":
                     equal_to([["form_tra", 300.0, 300.0]]),
                     "factored_values":
                     equal_to([["form_tra", 300.0, 300.0]]),
                     "headers":
                     equal_to(["new", "existing"]),
                     "result":
                     equal_to(600.0),
                 })),
         ),
     )
    def test_equal_to(self):
        gen_consumption_record(formulation="form1",
                               opening_balance=10,
                               closing_balance=20)
        gen_consumption_record(formulation="form2",
                               opening_balance=40,
                               closing_balance=30)
        definition_builder = DefinitionFactory().sampled().formulations(
            "form1", "form2")
        definition_builder.fields("opening_balance", "closing_balance")
        definition_builder.model("Consumption")
        definition_builder.are_equal()
        response = self.app.post_json(
            self.url,
            user="******",
            params=definition_builder.get(),
            expect_errors=True,
        )
        json_response = loads(response.content.decode("utf8"))

        assert_that(
            json_response,
            has_entry(
                equal_to("groups"),
                has_item(
                    has_entries({
                        "name":
                        equal_to("G1"),
                        "aggregation":
                        "SUM",
                        "values":
                        equal_to([["form1", 10.0, 20.0], ["form2", 40.0,
                                                          30.0]]),
                        "headers":
                        equal_to(["opening_balance", "closing_balance"]),
                        "result":
                        equal_to(100.0),
                    })),
            ),
        )
        self.assertEqual(200, response.status_code)
        assert_that(
            json_response,
            has_entry(
                equal_to("groups"),
                has_item(
                    has_entries({
                        "name":
                        equal_to("G2"),
                        "aggregation":
                        "SUM",
                        "values":
                        equal_to([["form1", 10.0, 20.0], ["form2", 40.0,
                                                          30.0]]),
                        "headers":
                        equal_to(["opening_balance", "closing_balance"]),
                        "result":
                        equal_to(100.0),
                    })),
            ),
        )

        assert_that(
            json_response,
            has_entry(equal_to("result"),
                      has_entries({"DEFAULT": equal_to("YES")})),
        )