def test_updates_optimization_tables(self, cursor):
        self.override_recent_date()
        # Call the command line script.
        args = ['--log-format', 'plain', testing.config_uri(),
                TEST_VARNISH_LOG]
        from cnxarchive.scripts.hits_counter import main
        main(args)

        # Check the optimization tables for content.
        cursor.execute("SELECT count(*) from recent_hit_ranks;")
        recent_count = cursor.fetchone()[0]
        cursor.execute("SELECT count(*) from overall_hit_ranks;")
        overall_count = cursor.fetchone()[0]
        self.assertTrue(recent_count > 0)
        self.assertTrue(overall_count > 0)
    def test_updates_optimization_tables(self, cursor):
        self.override_recent_date()
        # Call the command line script.
        args = [
            '--log-format', 'plain',
            testing.config_uri(), TEST_VARNISH_LOG
        ]
        from cnxarchive.scripts.hits_counter import main
        main(args)

        # Check the optimization tables for content.
        cursor.execute("SELECT count(*) from recent_hit_ranks;")
        recent_count = cursor.fetchone()[0]
        cursor.execute("SELECT count(*) from overall_hit_ranks;")
        overall_count = cursor.fetchone()[0]
        self.assertTrue(recent_count > 0)
        self.assertTrue(overall_count > 0)
    def test_insertion(self, cursor):
        # Call the command line script.
        args = ['--log-format', 'plain', testing.config_uri(),
                TEST_VARNISH_LOG]
        from cnxarchive.scripts.hits_counter import main
        return_code = main(args)
        self.assertEqual(return_code, 0)

        expectations = [[1, 3], [2, 1], [3, 4], [4, 1]]
        # Check for the insertion of data.
        cursor.execute("SELECT documentid, hits "
                       "  FROM document_hits;")
        hits = cursor.fetchall()
        hits = sorted(hits)
        self.assertEqual(hits, expectations)
    def test_insertion(self, cursor):
        # Call the command line script.
        args = [
            '--log-format', 'plain',
            testing.config_uri(), TEST_VARNISH_LOG
        ]
        from cnxarchive.scripts.hits_counter import main
        return_code = main(args)
        self.assertEqual(return_code, 0)

        expectations = [(1, 3), (2, 1), (3, 4), (4, 1)]
        # Check for the insertion of data.
        cursor.execute("SELECT documentid, hits " "  FROM document_hits;")
        hits = cursor.fetchall()
        hits = sorted(hits)
        self.assertEqual(hits, expectations)