def test_trigger_list(self):
        created0 = db_api.trigger_create(TRIGGERS[0])
        created1 = db_api.trigger_create(TRIGGERS[1])

        fetched = db_api.triggers_get_all()

        self.assertEqual(2, len(fetched))
        self.assertDictEqual(created0, fetched[0])
        self.assertDictEqual(created1, fetched[1])
    def test_trigger_list(self):
        created0 = db_api.trigger_create(TRIGGERS[0])
        created1 = db_api.trigger_create(TRIGGERS[1])

        fetched = db_api.triggers_get_all()

        self.assertEqual(2, len(fetched))
        self.assertDictEqual(created0, fetched[0])
        self.assertDictEqual(created1, fetched[1])
    def test_trigger_create_and_get(self):
        created = db_api.trigger_create(TRIGGERS[0])
        self.assertIsInstance(created, dict)

        fetched = db_api.trigger_get(created['id'])
        self.assertIsInstance(fetched, dict)
        self.assertDictEqual(created, fetched)
    def test_commit_multiple_objects(self):
        db_api.start_tx()

        try:
            created_trigger = db_api.trigger_create(TRIGGERS[0])
            self.assertIsInstance(created_trigger, dict)

            fetched_trigger = db_api.trigger_get(created_trigger['id'])
            self.assertIsInstance(fetched_trigger, dict)
            self.assertDictEqual(created_trigger, fetched_trigger)

            created_workbook = db_api.workbook_create(WORKBOOKS[0])
            self.assertIsInstance(created_workbook, dict)

            fetched_workbook = db_api.workbook_get(created_workbook['name'])
            self.assertIsInstance(fetched_workbook, dict)
            self.assertDictEqual(created_workbook, fetched_workbook)

            self.assertTrue(self.is_db_session_open())

            db_api.commit_tx()
        finally:
            db_api.end_tx()

        self.assertFalse(self.is_db_session_open())

        fetched_trigger = db_api.trigger_get(created_trigger['id'])
        self.assertIsInstance(fetched_trigger, dict)
        self.assertDictEqual(created_trigger, fetched_trigger)

        fetched_workbook = db_api.workbook_get(created_workbook['name'])
        self.assertIsInstance(fetched_workbook, dict)
        self.assertDictEqual(created_workbook, fetched_workbook)

        self.assertFalse(self.is_db_session_open())
    def test_commit_multiple_objects(self):
        db_api.start_tx()

        try:
            created_trigger = db_api.trigger_create(TRIGGERS[0])
            self.assertIsInstance(created_trigger, dict)

            fetched_trigger = db_api.trigger_get(created_trigger['id'])
            self.assertIsInstance(fetched_trigger, dict)
            self.assertDictEqual(created_trigger, fetched_trigger)

            created_workbook = db_api.workbook_create(WORKBOOKS[0])
            self.assertIsInstance(created_workbook, dict)

            fetched_workbook = db_api.workbook_get(created_workbook['name'])
            self.assertIsInstance(fetched_workbook, dict)
            self.assertDictEqual(created_workbook, fetched_workbook)

            self.assertTrue(self.is_db_session_open())

            db_api.commit_tx()
        finally:
            db_api.end_tx()

        self.assertFalse(self.is_db_session_open())

        fetched_trigger = db_api.trigger_get(created_trigger['id'])
        self.assertIsInstance(fetched_trigger, dict)
        self.assertDictEqual(created_trigger, fetched_trigger)

        fetched_workbook = db_api.workbook_get(created_workbook['name'])
        self.assertIsInstance(fetched_workbook, dict)
        self.assertDictEqual(created_workbook, fetched_workbook)

        self.assertFalse(self.is_db_session_open())
    def test_trigger_create_and_get(self):
        created = db_api.trigger_create(TRIGGERS[0])
        self.assertIsInstance(created, dict)

        fetched = db_api.trigger_get(created['id'])
        self.assertIsInstance(fetched, dict)
        self.assertDictEqual(created, fetched)
    def test_rollback_multiple_objects(self):
        db_api.start_tx()

        try:
            created_trigger = db_api.trigger_create(TRIGGERS[0])
            self.assertIsInstance(created_trigger, dict)

            fetched_trigger = db_api.trigger_get(created_trigger['id'])
            self.assertIsInstance(fetched_trigger, dict)
            self.assertDictEqual(created_trigger, fetched_trigger)

            created_workbook = db_api.workbook_create(WORKBOOKS[0])
            self.assertIsInstance(created_workbook, dict)

            fetched_workbook = db_api.workbook_get(created_workbook['name'])
            self.assertIsInstance(fetched_workbook, dict)
            self.assertDictEqual(created_workbook, fetched_workbook)

            self.assertTrue(self.is_db_session_open())

            db_api.rollback_tx()
        finally:
            db_api.end_tx()

        self.assertFalse(self.is_db_session_open())

        fetched_trigger = db_api.trigger_get(created_trigger['id'])
        self.assertIsNone(fetched_trigger)

        self.assertRaises(exc.NotFoundException, db_api.workbook_get,
                          created_workbook['name'])

        self.assertFalse(self.is_db_session_open())
    def test_trigger_update(self):
        created = db_api.trigger_create(TRIGGERS[0])
        self.assertIsInstance(created, dict)

        updated = db_api.trigger_update(created['id'], {'pattern': '0 * *'})
        self.assertIsInstance(updated, dict)
        self.assertEqual('0 * *', updated['pattern'])

        fetched = db_api.trigger_get(created['id'])
        self.assertDictEqual(updated, fetched)
    def test_trigger_update(self):
        created = db_api.trigger_create(TRIGGERS[0])
        self.assertIsInstance(created, dict)

        updated = db_api.trigger_update(created['id'], {'pattern': '0 * *'})
        self.assertIsInstance(updated, dict)
        self.assertEqual('0 * *', updated['pattern'])

        fetched = db_api.trigger_get(created['id'])
        self.assertDictEqual(updated, fetched)
    def test_rollback(self):
        db_api.start_tx()

        try:
            created = db_api.trigger_create(TRIGGERS[0])
            self.assertIsInstance(created, dict)

            fetched = db_api.trigger_get(created['id'])
            self.assertIsInstance(fetched, dict)
            self.assertDictEqual(created, fetched)

            self.assertTrue(self.is_db_session_open())

            db_api.rollback_tx()
        finally:
            db_api.end_tx()

        self.assertFalse(self.is_db_session_open())

        fetched = db_api.trigger_get(created['id'])
        self.assertIsNone(fetched)

        self.assertFalse(self.is_db_session_open())
    def test_rollback(self):
        db_api.start_tx()

        try:
            created = db_api.trigger_create(TRIGGERS[0])
            self.assertIsInstance(created, dict)

            fetched = db_api.trigger_get(created['id'])
            self.assertIsInstance(fetched, dict)
            self.assertDictEqual(created, fetched)

            self.assertTrue(self.is_db_session_open())

            db_api.rollback_tx()
        finally:
            db_api.end_tx()

        self.assertFalse(self.is_db_session_open())

        fetched = db_api.trigger_get(created['id'])
        self.assertIsNone(fetched)

        self.assertFalse(self.is_db_session_open())
    def test_trigger_delete(self):
        created = db_api.trigger_create(TRIGGERS[0])
        db_api.trigger_delete(created['id'])

        self.assertRaises(exc.NotFoundException, db_api.trigger_get,
                          created['id'])