def test_append_to_synonyms_partial(self):
        """ Updating by just passing the key-value pair which changed"""

        data = PropertyTemplate(
            "First Name",
            "firstname",
            "administrative",
            "The first name of a person",
            synonyms=["forename"],
        )

        res = requests.post(url=self.url, json=data.to_dict())
        self.assertEqual(res.status_code, 201)

        # Only change the attribute
        update = {"synonyms": ["forename", "given name"]}

        entry_id = res.json()["id"]
        url_id = self.url + f"/id/{entry_id}"

        res = requests.put(url=url_id, json=update)
        self.assertEqual(res.status_code, 200)

        res = requests.get(url=url_id)
        self.assertEqual(res.status_code, 200)
        self.assertEqual(res.json()["synonyms"], ["forename", "given name"])
    def test_post_property_cv(self):
        """ Insert property with vocabulary other than cv"""

        data = PropertyTemplate("string", "string", "string", "string")

        res = requests.post(url=self.url, json=data.to_dict())
        self.assertEqual(res.status_code, 201)
    def test_append_to_synonyms_entire_dataset(self):
        """ Update by passing the entire dataset to the API"""

        data = PropertyTemplate(
            "First Name",
            "firstname",
            "administrative",
            "The first name of a person",
            synonyms=["forename"],
        )

        res = requests.post(url=self.url, json=data.to_dict())
        self.assertEqual(res.status_code, 201)

        # Update the entry
        data.synonyms = ["forename", "given name"]

        entry_id = res.json()["id"]
        url_id = self.url + f"/id/{entry_id}"

        res = requests.put(url=url_id, json=data.to_dict())
        self.assertEqual(res.status_code, 200)

        res = requests.get(url=url_id)
        self.assertEqual(res.status_code, 200)
        self.assertEqual(res.json()["synonyms"], ["forename", "given name"])
Beispiel #4
0
    def test_form_with_fieldList_and_FormField(self):

        template_form = FormTemplate("Contacts", "contact_form", "A form to register multiple contacts")\
            .add_field(
            FieldTemplate("FieldList",
                          PropertyTemplate("Contact List", "contact_list", "administrative", "A contact list"),
                          ArgsTemplate("DataObjects", [
                              FormFieldTemplate(PropertyTemplate("Contact", "contact", "administrative", "A contact"))
                                       .add_field(
                                  FieldTemplate("StringField",
                                                PropertyTemplate("First Name", "firstname","administrative",
                                                                 "first name of user")))
                                       .add_field(
                                  FieldTemplate("StringField",
                                                PropertyTemplate("Last Name", "lastname","administrative",
                                                                 "last name of user")))
                          ]),
                          min_entries=1))

        with self.app.test_request_context():
            act_form_name, form_cls = JsonFlaskParser().to_form(
                template_form.to_dict())
            form_instance = form_cls()
            self.assertEqual(act_form_name, "contact_form")
            self.assertTrue(hasattr(form_instance, "contact_list"))
            contact_list_field = getattr(form_instance, "contact_list")
            self.assertEqual(getattr(contact_list_field, "type"), "FieldList")
            entry_form = getattr(contact_list_field, "entries")[0]
            self.assertTrue(hasattr(entry_form.form, "firstname"))
            self.assertTrue(hasattr(entry_form.form, "lastname"))
Beispiel #5
0
    def test_form_with_formfield(self):

        data_type_ctrl_voc = ControlledVocabularyTemplate("Data Type", "data_type", "All supported data types")\
            .add_item(ItemTemplate("Text", "text", "Uncontrolled text input"))\
            .add_item(ItemTemplate("Boolean", "boolean", "Boolean input"))\
            .add_item(ItemTemplate("Controlled Vocabulary", "ctrl_voc", "Value from defined list"))

        template_form = FormTemplate("Property", "property", "Form to change a property")\
            .add_field(
            FormFieldTemplate(prop=PropertyTemplate("Vocabulary Type", "voc_type", "administrative",
                                                    "Vocabulary Type restricts the possible inputs."))\

                .add_field(
                FieldTemplate("SelectField",
                              PropertyTemplate("Data type", "data_type", "administrative", "The data type",
                                               ValueTypeTemplate("ctrl_voc", data_type_ctrl_voc))))
                .add_field(
                # TODO replace StringField with SelectField
                FieldTemplate("StringField",
                              PropertyTemplate("Controlled Vocabulary", "ctrl_voc", "administrative",
                                               "The controlled vocabulary"))))

        form_name, from_cls = JsonFlaskParser().to_form(
            template_form.to_dict())

        with self.app.test_request_context():
            form_instance = from_cls()
Beispiel #6
0
    def test_post_property_cv_reference(self):
        """ Insert property with correct cv """

        data = PropertyTemplate("string", "string", "string", "string",
                                ValueTypeTemplate("ctrl_voc",
                                                  ControlledVocabularyTemplate("Test CV", "Test CV", "Test CV")
                                                  .add_item(ItemTemplate("test 1", "test 1", "First item"))
                                                  .add_item(ItemTemplate("test 2", "test 2", "First item"))))

        res = requests.post(url=self.url, json=data.to_dict())
        self.assertEqual(res.status_code, 201)
Beispiel #7
0
def get_login_form():
    email = PropertyTemplate("E-Mail", "email", "administrative", "The email")
    password = PropertyTemplate("Password", "password", "administrative",
                                "The password")

    form = FormTemplate("Login", "user_login", "Form to login a user") \
        .add_field(FieldTemplate("StringField", email,
                                 validators={"args": {"objects": [{"class_name": "DataRequired"}]}})) \
        .add_field(FieldTemplate("PasswordField", password,
                                 validators={"args": {"objects": [
                                     {"class_name": "DataRequired"},
                                     {"class_name": "Length", "kwargs": {"max": 64, "min": 8}}
                                 ]}}))

    return form
Beispiel #8
0
def insert_two(self):
    """ Insert a normal and a deprecated entry"""

    props = [
        PropertyTemplate("label1", "name1", "level_1", "description 1"),
        PropertyTemplate("label2", "name2", "level_2", "description 2", deprecated=True),
    ]

    results = [requests.post(self.url, json=prop.to_dict()) for prop in props]

    for index, res in enumerate(results):
        if res.status_code != 201:
            raise Exception(f"Could not insert {props[index]}. {res.json()}")

    return results
Beispiel #9
0
    def test_simple_field_attributes_in_kwargs(self):

        template_field = FieldTemplate("StringField",
                                       PropertyTemplate(
                                           "User Name", "user_name", None,
                                           None),
                                       label="User Name",
                                       description="A simple string field")

        act_name, act_field = JsonFlaskParser._parse_field(
            template_field.to_dict())

        self.assertEqual(act_field.kwargs["label"], "User Name")
        self.assertEqual(act_field.kwargs["description"],
                         "A simple string field")

        with self.app.test_request_context():
            form_cls = type("TestForm", (FlaskForm, ), {})
            setattr(form_cls, act_name, act_field)

            form = form_cls()

            self.assertTrue(hasattr(form, "user_name"))
            field = getattr(form, "user_name")
            self.assertEqual(getattr(field, "type"), "StringField")
Beispiel #10
0
    def test_form_with_fieldList(self):
        """Create form which contains a FieldList"""

        template_form = FormTemplate("Property", "property", "Form to change a property")\
            .add_field(
            FieldTemplate("FieldList",
                          PropertyTemplate("Synonyms", "synonyms", "administrative", "List of synonyms"),
                          ArgsTemplate("DataObjects", [
                              FieldTemplate("StringField",
                                            PropertyTemplate("Synonym", "synonym", "administrative",
                                                             "A single synonym"))]),
                          min_entries=1))

        with self.app.test_request_context():
            form_name, form_cls = JsonFlaskParser().to_form(
                template_form.to_dict())
            form_instance = form_cls()

            self.assertTrue(hasattr(form_instance, "synonyms"))
            synonym_field = getattr(form_instance, "synonyms")
            self.assertEqual(getattr(synonym_field, "type"), "FieldList")
            string_field = getattr(synonym_field, "entries")[0]
            self.assertEqual(getattr(string_field, "type"), "StringField")