Exemplo n.º 1
0
    def fields() -> FieldEditor:
        """Returns a FieldEditor class instance to edit the Links table fields and their metadata

        Returns:
            *field_editor* (:obj:`FieldEditor`): A field editor configured for editing the Links table
            """
        return FieldEditor("links")
    def test_add(self):
        for tab in self.my_tables:
            table = FieldEditor(tab)
            qry = f'select count(*) from "attributes_documentation" where name_table="{tab}"'
            q = self.proj.conn.execute(qry).fetchone()[0]
            one = choice(list(table._original_values.keys()))
            self.proj.conn.commit()
            with self.assertRaises(ValueError) as em:
                table.add(one, self.randomword(30))
            self.assertEqual("attribute_name already exists",
                             str(em.exception), "failed in the wrong place")

            with self.assertRaises(ValueError) as em:
                table.add(f"{self.randomword(5)} {5}", self.randomword(30))
            self.assertEqual(
                'attribute_name can only contain letters, numbers and "_"',
                str(em.exception),
                "failed in the wrong place",
            )

            with self.assertRaises(ValueError):
                table.add(
                    choice("0123456789") + self.randomword(20),
                    self.randomword(30))
            new_one = self.randomword(20)
            while new_one[0] in "0123456789":
                new_one = self.randomword(20)
            table.add(new_one, self.randomword(30))
            self.proj.conn.commit()
            curr = self.proj.conn.cursor()
            curr.execute(
                f'select count(*) from "attributes_documentation" where name_table="{tab}"'
            )
            q2 = curr.fetchone()[0]
            self.assertEqual(q + 1, q2, "Adding element did not work")

            # If query fails, we failed to add new field to the database
            curr.execute(
                f'select "{new_one}" from "attributes_documentation" where name_table="{tab}"'
            )

            if "alpha" in table._original_values.keys():
                self.assertEqual(table.alpha, "Available for user convenience",
                                 "not being able to retrieve values")

            self.proj.conn.commit()
            del curr
 def test_building(self):
     for tab in ["modes", "links", "nodes", "link_types"]:
         table = FieldEditor(tab)
         qry = f'select count(*) from "attributes_documentation" where name_table="{tab}"'
         q = self.proj.conn.execute(qry).fetchone()[0]
         self.assertEqual(
             q, len(table._original_values),
             "Meta table populated with the wrong number of elements")
    def test_check_completeness(self):
        for table in self.my_tables:
            curr = self.proj.conn.cursor()

            # We add a bogus record to the attribute list
            val = self.randomword(30).lower()
            qry = 'INSERT INTO "attributes_documentation" VALUES (?,?," ");'
            curr.execute(qry, (table, val))
            self.proj.conn.commit()

            curr.execute(
                f'Select name_table from "attributes_documentation" where attribute="{val}"'
            )
            self.assertEqual(curr.fetchone()[0], table,
                             "Failed to insert bogus value")

            # Then we add a new field to the table
            val2 = self.randomword(10)
            curr.execute(f'Alter table "{table}" add column "{val2}" NUMERIC;')
            curr.execute(f"pragma table_info({table})")
            fields = [x[1] for x in curr.fetchall() if x[1] == val2]
            self.assertEqual([val2], fields, "failed to add a new field")

            table = FieldEditor(table)
            self.proj.conn.commit()
            curr = self.proj.conn.cursor()
            curr.execute(
                f'Select count(*) from "attributes_documentation" where attribute="{val}"'
            )
            self.assertEqual(curr.fetchone()[0], 0,
                             f"clean the table on loading failed {val}")

            curr.execute(
                f'Select count(*) from "attributes_documentation" where attribute="{val2}"'
            )
            self.assertEqual(curr.fetchone()[0], 1,
                             "clean the table on loading failed")
            print(table._original_values[val2])

            self.proj.conn.commit()
            del curr
Exemplo n.º 5
0
 def fields(self) -> FieldEditor:
     """Returns a FieldEditor class instance to edit the Modes table fields and their metadata"""
     return FieldEditor('modes')
Exemplo n.º 6
0
 def fields(self) -> FieldEditor:
     """Returns a FieldEditor class instance to edit the Link_Types table fields and their metadata"""
     return FieldEditor('link_types')
    def test_save(self):
        for tab in ["modes", "links", "nodes", "link_types"]:
            table = FieldEditor(tab)
            random_val = self.randomword(30)
            if "alpha" in table._original_values.keys():
                table.alpha = random_val
                table.save()
                table2 = FieldEditor(tab)

                self.assertEqual(table2.alpha, random_val,
                                 "Did not save values properly")

            if "link_id" in table._original_values.keys():
                table.link_id = random_val
                table.save()
                table2 = FieldEditor(tab)

                self.assertEqual(table2.link_id, random_val,
                                 "Did not save values properly")

            if "node_id" in table._original_values.keys():
                table.node_id = random_val
                table.save()
                table2 = FieldEditor(tab)

                self.assertEqual(table2.node_id, random_val,
                                 "Did not save values properly")

            self.proj.conn.commit()