def test_infer_choice_fields_from_charfield_with_serialiser(self, js): js.dumps.return_value = '["purple", "yellow", "blue"]' ctx = infer_from_subrecord_field_path("FavouriteColour.name") choices = json.loads(ctx["lookuplist"]) self.assertEqual(choices, ["purple", "yellow", "blue"]) js.dumps.assert_called_once_with(["purple", "yellow", "blue"], cls=OpalSerializer)
def test_infer_choice_fields_from_charfield_with_serialiser(self, js): js.dumps.return_value = '["purple", "yellow", "blue"]' ctx = infer_from_subrecord_field_path("FavouriteColour.name") choices = json.loads(ctx["lookuplist"]) self.assertEqual(choices, ["purple", "yellow", "blue"]) js.dumps.assert_called_once_with( ["purple", "yellow", "blue"], cls=OpalSerializer )
def test_infer_from_path(self): ctx = infer_from_subrecord_field_path("DogOwner.name") self.assertEqual(ctx["label"], "Name") self.assertTrue("lookuplist" not in ctx) self.assertEqual(ctx["model"], "editing.dog_owner.name") self.assertFalse(ctx["required"]) ctx = infer_from_subrecord_field_path("DogOwner.dog") self.assertEqual(ctx["label"], "Dog") self.assertEqual(ctx["model"], "editing.dog_owner.dog") self.assertEqual(ctx["lookuplist"], "dog_list") self.assertFalse(ctx["required"]) ctx = infer_from_subrecord_field_path("Demographics.hospital_number") self.assertEqual(ctx["label"], "Hospital Number") # many to many ctx = infer_from_subrecord_field_path("HatWearer.hats") self.assertEqual(ctx["label"], "Hats") self.assertEqual(ctx["model"], "editing.hat_wearer.hats") self.assertEqual(ctx["lookuplist"], "hat_list")
def test_infer_required_fields(self): ctx = infer_from_subrecord_field_path("DogOwner.name") self.assertTrue(ctx["required"])
def test_infer_foreign_key_for_free_text(self): ctx = infer_from_subrecord_field_path("DogOwner.dog") self.assertEqual(ctx["label"], "Dog") self.assertEqual(ctx["model"], "editing.dog_owner.dog") self.assertEqual(ctx["lookuplist"], "dog_list") self.assertFalse(ctx["required"])
def test_infer_element_type_text(self): ctx = infer_from_subrecord_field_path("HoundOwner.name") self.assertNotIn("element_type", ctx)
def test_infer_char_field(self): ctx = infer_from_subrecord_field_path("DogOwner.name") self.assertEqual(ctx["label"], "Name") self.assertTrue("lookuplist" not in ctx) self.assertEqual(ctx["model"], "editing.dog_owner.name")
def test_infer_element_type_number(self): ctx = infer_from_subrecord_field_path("FavouriteNumber.number") self.assertEquals( ctx["element_type"], "number" )
def test_infer_choice_fields_from_charfield(self): ctx = infer_from_subrecord_field_path("FavouriteColour.name") choices = json.loads(ctx["lookuplist"]) self.assertEqual(choices, ["purple", "yellow", "blue"])
def test_infer_blank_fields(self): # at present we consider blank fields even if they are aren't nullable # to be not required ctx = infer_from_subrecord_field_path("Birthday.birth_date") self.assertFalse(ctx["required"])
def test_infer_many_to_many_fields(self): ctx = infer_from_subrecord_field_path("HatWearer.hats") self.assertEqual(ctx["label"], "Hats") self.assertEqual(ctx["model"], "editing.hat_wearer.hats") self.assertEqual(ctx["lookuplist"], "hat_list")
def test_get_label_from_the_model(self): ctx = infer_from_subrecord_field_path("Demographics.hospital_number") self.assertEqual(ctx["label"], "Hospital Number")
def test_infer_element_name(self): ctx = infer_from_subrecord_field_path("Birthday.birth_date") self.assertEquals(ctx["element_name"], "editing.birthday._client.id + '_birth_date'")
def test_infer_element_type_number(self): ctx = infer_from_subrecord_field_path("FavouriteNumber.number") self.assertEqual(ctx["element_type"], "number")
def test_infer_choice_fields_from_charfield(self): ctx = infer_from_subrecord_field_path("FavouriteColour.name") choices = json.loads(ctx["lookuplist"]) for choice in ["purple", "blue", "yellow"]: self.assertTrue(choice in choices)
def test_infer_element_name(self): ctx = infer_from_subrecord_field_path("Birthday.birth_date") self.assertEquals( ctx["element_name"], "editing.birthday._client.id + '_birth_date'" )
def test_get_label_from_the_model(self): ctx = infer_from_subrecord_field_path("HatWearer.wearing_a_hat") self.assertEqual(ctx["label"], "Wearing A Hat")