diff --git a/test/test_database.py b/test/test_database.py index 2cd6375b16e5353c7c1d3eec1d3bdeb656454f8d..9446f85f3b3699a6e0e991b52911db33a085cfa2 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -180,6 +180,24 @@ class DatabaseTest(unittest.TestCase): self.assertRegex(actual[i]['code'], "[A-Z]{" + str(code_len) + "}") self.assertEqual(entry['type'], actual[i]['type']) + def test_update_codebook(self): + """Test that the codes get updated.""" + # Get number of entries + stmt = 'SELECT COUNT(*) FROM CodeBook ORDER BY Word' + number_of_entries = self.database.conn.execute(stmt).fetchall()[0][0] + # Get old and updated word-code combinations + stmt = 'SELECT Word, Code FROM CodeBook' + old = self.database.conn.execute(stmt).fetchall() + self.database.update_codebook() + updated = self.database.conn.execute(stmt).fetchall() + # Collect approximately score of not updated pairs + pairs = 0 + for i in range(0, number_of_entries, 2): + if old[i]['Code'] == updated[i]['Code']: + pairs = pairs + 1 + # Test that at least some of the test are new + self.assertTrue(pairs < number_of_entries) + if __name__ == '__main__': unittest.main()