def test_equal(self):
        row1 = chronojump_importer.Row()
        row1.set("name", "john")
        row1.set("year", 1970)

        row2 = chronojump_importer.Row()
        row2.set("name", "john")
        row2.set("year", 1971)

        self.assertNotEqual(row1, row2)
        row2.set("year", 1970)

        self.assertEqual(row1, row2)
    def test_update_ids_from_table(self):
        table_to_update = chronojump_importer.Table("table_to_update")
        row1 = chronojump_importer.Row()
        row1.set("name", "john")
        row1.set("personId", 1)

        row2 = chronojump_importer.Row()
        row2.set("name", "mark")
        row2.set("personId", 4)

        row3 = chronojump_importer.Row()
        row3.set("name", "alex")
        row3.set("personId", 5)

        table_to_update.insert_row(row1)
        table_to_update.insert_row(row2)
        table_to_update.insert_row(row3)

        column_to_update = 'personId'

        referenced_table = chronojump_importer.Table("referenced_table")
        row4 = chronojump_importer.Row()
        row4.set("personId", 11)
        row4.set("old_personId", 1)

        row5 = chronojump_importer.Row()
        row5.set("personId", 12)
        row5.set("old_personId", 4)

        referenced_table.insert_row(row4)
        referenced_table.insert_row(row5)

        old_reference_column = 'old_personId'
        new_reference_column = 'personId'

        table_to_update.update_ids(column_to_update, referenced_table,
                                   old_reference_column, new_reference_column)

        self.assertEqual(len(table_to_update._table_data), 3)

        def verify_exists(table, name, person_id):
            for row in table._table_data:
                if row.get('name') == name and row.get(
                        'personId') == person_id:
                    return True

            return False

        self.assertTrue(verify_exists(table_to_update, "john", 11))
        self.assertTrue(verify_exists(table_to_update, "mark", 12))
        self.assertTrue(verify_exists(table_to_update, "alex", 5))
    def test_update_session_ids(self):
        table = chronojump_importer.Table("test")
        row1 = chronojump_importer.Row()
        row1.set("sessionID", 2)
        row1.set("name", "john")

        row2 = chronojump_importer.Row()
        row2.set("sessionID", 3)
        row2.set("name", "mark")

        table.insert_row(row1)
        table.insert_row(row2)

        table.update_session_ids(4)
        for row in table._table_data:
            self.assertEqual(row.get('sessionID'), 4)
    def test_remove_duplicates_list(self):
        row1 = chronojump_importer.Row()
        row1.set("name", "john")
        row2 = chronojump_importer.Row()
        row2.set("name", "john")
        row3 = chronojump_importer.Row()
        row3.set("name", "sam")

        table = chronojump_importer.Table("Test")
        table.insert_row(row1)
        table.insert_row(row2)
        table.insert_row(row3)

        self.assertEqual(len(table), 3)
        table.remove_duplicates()

        self.assertEqual(len(table), 2)

        expected = [row1, row3]
        for row in table:
            expected.remove(row)

        self.assertEqual(len(expected), 0)
    def test_write(self, data):
        self._cursor.execute(
            "CREATE TABLE test (uniqueID INTEGER PRIMARY KEY, name TEXT)")
        self._cursor.execute("INSERT INTO test (uniqueID, name) VALUES (1, ?)",
                             (data['initial_name'], ))

        table = chronojump_importer.Table("test")
        row = chronojump_importer.Row()
        row.set(column_name="uniqueID", value="2")
        row.set(column_name="name", value=data['name_to_insert'])

        table.insert_row(row)

        self._database.write(table=table,
                             matches_columns=None,
                             avoids_duplicate_column="name")

        self._cursor.execute("SELECT * FROM test WHERE uniqueID=?", (2, ))
        result = self._cursor.fetchone()
        self.assertEqual(result[0], 2)
        self.assertEqual(result[1], data['expected_inserted_name'])
    def test_has_column(self):
        row = chronojump_importer.Row()
        row.set("name", "john")

        self.assertEqual(row.has_column("name"), True)
        self.assertEqual(row.has_column("year"), False)
    def test_columns(self):
        row = chronojump_importer.Row()
        row.set("name", "john")
        row.set("year", 1970)

        self.assertEqual(sorted(row.columns()), ["name", "year"])
    def test_get(self):
        row = chronojump_importer.Row()
        row.set("name", "sam")

        self.assertEqual(row.get("name"), "sam")