emmental/db/test_decade.py
Anna Schumaker 63e2e6473d db: Add a function so Decades can list their Years
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2021-08-23 13:14:58 -04:00

58 lines
1.8 KiB
Python

# Copyright 2021 (c) Anna Schumaker.
import db
import sqlite3
import unittest
from gi.repository import GObject
class TestDecadeTable(unittest.TestCase):
def setUp(self):
db.reset()
def test_decade_table_init(self):
self.assertIsInstance(db.decade.Table, db.decade.DecadeTable)
db.execute("SELECT decadeid,decade FROM decades")
def test_decade_table_insert(self):
decade = db.decade.Table.insert(2020)
self.assertIsInstance(decade, db.decade.Decade)
self.assertIsInstance(decade, db.objects.Row)
self.assertEqual(decade.decade, 2020)
self.assertEqual(str(decade), "2020s")
with self.assertRaises(sqlite3.IntegrityError):
db.decade.Table.insert(2020)
def test_decade_table_delete(self):
decade = db.decade.Table.find(2020)
db.decade.Table.delete(decade)
self.assertIsNone(db.decade.Table.lookup(2020))
def test_decade_table_get(self):
decade = db.decade.Table.insert(2020)
self.assertEqual(db.decade.Table.get(1), decade)
self.assertIsNone(db.decade.Table.get(2))
def test_decade_table_lookup(self):
decade = db.decade.Table.insert(2020)
self.assertEqual(db.decade.Table.lookup(2020), decade)
self.assertIsNone(db.decade.Table.lookup(2021))
def test_decade_compare(self):
d2010 = db.decade.Table.insert(2010)
d2020 = db.decade.Table.insert(2020)
self.assertTrue(d2010 < d2020)
self.assertTrue(d2020 > d2010)
self.assertFalse(d2010 > d2020)
self.assertFalse(d2020 < d2010)
def test_decade_years(self):
decade = db.decade.Table.insert(2020)
y2020 = db.year.Table.insert(2020)
y2021 = db.year.Table.insert(2021)
self.assertEqual(decade.years(), [ y2020, y2021 ])