Beispiel #1
0
    def test_invalid_uuid(self):
        notes = note_factory(1, TAGS)

        uuids = [1, "2", "asdf", hex(random.randint(0, 1_000_000))]

        for uuid_bad in uuids:
            with self.subTest(uuid_bad=uuid_bad):
                notes[0] = notes[0]._replace(uuid=uuid_bad)
                infile = note_csv_factory(notes)
                with self.assertRaises(lgd.CSVError):
                    _, _ = lgd.note_import(self.conn, infile)
Beispiel #2
0
    def test_invalid_created_at(self):
        notes = note_factory(1, TAGS)

        dates = [
            1,
            "1",
            "asdf",
            "2020-04-01",
            "2020-04-01 12",
            "2020-04-01 12:00",
            "2020-04-01 12:00:00.123456",
        ]

        for date_bad in dates:
            with self.subTest(date_bad=date_bad):
                notes[0] = notes[0]._replace(created_at=date_bad)
                infile = note_csv_factory(notes)
                with self.assertRaises(lgd.CSVError):
                    _, _ = lgd.note_import(self.conn, infile)
Beispiel #3
0
    def test_note_export_equality(self):
        # Retrieve Notes inserted during setup.
        notes1 = set(lgd.select_notes(self.conn))
        self.assertEqual(len(notes1), len(NOTES))

        # Export from the setUp DB.
        notes = lgd.select_notes(self.conn, localtime=False)
        notefile = io.StringIO()
        _ = lgd.note_export(self.conn, notes, notefile)
        notefile.seek(0)

        # Set up a second DB
        conn2 = lgd.get_connection(DB_IN_MEM)
        lgd.db_setup(conn2, lgd.DB_MIGRATIONS)

        # Import the Notes from the 1st DB into the 2nd.
        _, _ = lgd.note_import(conn2, notefile)

        # Retrieve the Notes from the 2nd DB.
        # Check that the notes retrieved from both DBs are equal.
        notes2 = set(lgd.select_notes(conn2))
        self.assertEqual(notes1, notes2)
Beispiel #4
0
 def setUp(self):
     self.conn = lgd.get_connection(DB_IN_MEM)
     lgd.db_setup(self.conn, lgd.DB_MIGRATIONS)
     self.inserted, self.updated = lgd.note_import(self.conn,
                                                   get_note_csv())
Beispiel #5
0
 def test_note_import_update(self):
     inserted, updated = lgd.note_import(self.conn, get_note_csv())
     self.assertEqual(inserted + updated, len(NOTES))
     self.assertEqual(inserted, 0)
     self.assertEqual(updated, self.inserted)
     self.assertEqual(updated, len(NOTES), f"Number updated: {updated}")
Beispiel #6
0
 def test_invalid_fieldnames(self):
     infile = io.StringIO("a,b,c,d\n" "1,2,3,4\n")
     with self.assertRaises(lgd.CSVError):
         _, _ = lgd.note_import(self.conn, infile)
Beispiel #7
0
 def test_note_import_new(self):
     inserted, updated = lgd.note_import(self.conn, get_note_csv())
     self.assertEqual(inserted, len(NOTES))
     self.assertEqual(updated, 0)