import jingrow
from jingrow.deferred_insert import deferred_insert, save_to_db
from jingrow.tests.utils import JingrowTestCase


class TestDeferredInsert(JingrowTestCase):
	def test_deferred_insert(self):
		route_history = {"route": jingrow.generate_hash(), "user": "Administrator"}
		deferred_insert("Route History", [route_history])

		save_to_db()
		self.assertTrue(jingrow.db.exists("Route History", route_history))

		route_history = {"route": jingrow.generate_hash(), "user": "Administrator"}
		deferred_insert("Route History", [route_history])
		jingrow.clear_cache()  # deferred_insert cache keys are supposed to be persistent
		save_to_db()
		self.assertTrue(jingrow.db.exists("Route History", route_history))
