コード例 #1
0
    def test_count(self):
        """
        Verifies that the correct number of queries is returned
        """
        logger = Logger()
        logger.start_logging()

        query = Query().from_table(Account)
        query.select()
        query.select()
        self.assertEqual(2, logger.count())
        query.select()
        self.assertEqual(3, logger.count())
コード例 #2
0
    def test_count(self):
        """
        Verifies that the correct number of queries is returned
        """
        logger = Logger()
        logger.start_logging()

        query = Query().from_table(Account)
        query.select()
        query.select()
        self.assertEqual(2, logger.count())
        query.select()
        self.assertEqual(3, logger.count())
コード例 #3
0
    def test_logger(self):
        logger_one = Logger('one')
        logger_two = Logger('two')

        logger_one.start_logging()
        query = Query().from_table(Account)
        query.select()

        self.assertEqual(logger_one.count(), 1, 'Incorrect number of queries')

        query.select()
        logger_two.start_logging()
        query.select()
        logger_one.stop_logging()
        query.select()

        self.assertEqual(logger_one.count(), 3, 'Incorrect number of queries')
        self.assertEqual(logger_two.count(), 2, 'Incorrect number of queries')

        query.select()
        logger_one.start_logging()
        query.select()

        self.assertEqual(logger_one.count(), 4, 'Incorrect number of queries')
        self.assertEqual(logger_two.count(), 4, 'Incorrect number of queries')

        query.select()
        logger_two.clear_log()
        query.select()

        self.assertEqual(logger_one.count(), 6, 'Incorrect number of queries')
        self.assertEqual(logger_two.count(), 1, 'Incorrect number of queries')
コード例 #4
0
    def test_logger(self):
        logger_one = Logger('one')
        logger_two = Logger('two')

        logger_one.start_logging()
        query = Query().from_table(Account)
        query.select()

        self.assertEqual(logger_one.count(), 1, 'Incorrect number of queries')

        query.select()
        logger_two.start_logging()
        query.select()
        logger_one.stop_logging()
        query.select()

        self.assertEqual(logger_one.count(), 3, 'Incorrect number of queries')
        self.assertEqual(logger_two.count(), 2, 'Incorrect number of queries')

        query.select()
        logger_one.start_logging()
        query.select()

        self.assertEqual(logger_one.count(), 4, 'Incorrect number of queries')
        self.assertEqual(logger_two.count(), 4, 'Incorrect number of queries')

        query.select()
        logger_two.clear_log()
        query.select()

        self.assertEqual(logger_one.count(), 6, 'Incorrect number of queries')
        self.assertEqual(logger_two.count(), 1, 'Incorrect number of queries')
コード例 #5
0
    def test_stop_logging(self):
        """
        Verifies that the logger stops caring about queries
        """
        logger = Logger()
        logger.start_logging()

        query = Query().from_table(Account)
        query.select()
        query.select()

        self.assertEqual(2, logger.count())

        logger.stop_logging()
        query.select()
        query.select()
        self.assertEqual(2, logger.count())

        logger.start_logging()
        query.select()
        self.assertEqual(3, logger.count())
コード例 #6
0
    def test_stop_logging(self):
        """
        Verifies that the logger stops caring about queries
        """
        logger = Logger()
        logger.start_logging()

        query = Query().from_table(Account)
        query.select()
        query.select()

        self.assertEqual(2, logger.count())

        logger.stop_logging()
        query.select()
        query.select()
        self.assertEqual(2, logger.count())

        logger.start_logging()
        query.select()
        self.assertEqual(3, logger.count())
コード例 #7
0
    def test_joined_model_foreign_reverse(self):
        query = Query().from_table(Order).join(right_table=Account, fields=["*"], prefix_fields=True)
        rows = query.select(True)

        self.assertGreater(len(rows), 0, "No records")

        logger = Logger()
        logger.start_logging()
        for row in rows:
            self.assertIsInstance(row, Order, "Record is not model instance")
            self.assertIs(hasattr(row, "account"), True, "Row does not have nested model")
            self.assertIsInstance(row.account, Account, "Nested record is not model instance")
        self.assertEqual(logger.count(), 0, "Queries were executed when none should")
コード例 #8
0
    def test_joined_model_foreign_reverse(self):
        query = Query().from_table(Order).join(right_table=Account,
                                               fields=['*'],
                                               prefix_fields=True)
        rows = query.select(True)

        self.assertGreater(len(rows), 0, 'No records')

        logger = Logger()
        logger.start_logging()
        for row in rows:
            self.assertIsInstance(row, Order, 'Record is not model instance')
            self.assertIs(hasattr(row, 'account'), True,
                          'Row does not have nested model')
            self.assertIsInstance(row.account, Account,
                                  'Nested record is not model instance')
        self.assertEqual(logger.count(), 0,
                         'Queries were executed when none should')
コード例 #9
0
    def test_joined_model_foreign(self):
        query = Query().from_table(
            Account
        ).join(
            right_table=Order,
            fields=[
                '*'
            ],
            prefix_fields=True
        )
        rows = query.select(True)

        self.assertGreater(len(rows), 0, 'No records')

        logger = Logger()
        logger.start_logging()
        for row in rows:
            self.assertIsInstance(row, Account, 'Record is not model instance')
            self.assertIs(hasattr(row, 'order'), True, 'Row does not have nested model')
            self.assertIsInstance(row.order, Order, 'Nested record is not model instance')
        self.assertEqual(logger.count(), 0, 'Queries were executed when none should')
コード例 #10
0
    def test_clear_log(self):
        """
        Makes sure queries are cleared
        """
        logger_one = Logger('one')
        logger_one.start_logging()
        query = Query().from_table(Account)

        # run a query and update the logger's query list
        query.select()
        logger_one.update_log()

        # there should be one query
        self.assertEqual(logger_one.count(), 1)

        # increment the connection query count
        query.select()

        # clear the log
        logger_one.clear_log()

        # make sure no queries
        self.assertEqual(0, len(logger_one.queries))
コード例 #11
0
    def test_clear_log(self):
        """
        Makes sure queries are cleared
        """
        logger_one = Logger('one')
        logger_one.start_logging()
        query = Query().from_table(Account)

        # run a query and update the logger's query list
        query.select()
        logger_one.update_log()

        # there should be one query
        self.assertEqual(logger_one.count(), 1)

        # increment the connection query count
        query.select()

        # clear the log
        logger_one.clear_log()

        # make sure no queries
        self.assertEqual(0, len(logger_one.queries))