<commit_before>import json

from tracking import TrackerBaseTestCase
from analytics import AnalyticsLiveBaseTestCase

from piwikapi.analytics import PiwikAnalytics


class TrackerVerifyBaseTestCase(TrackerBaseTestCase, AnalyticsLiveBaseTestCase):
    def setUp(self):
        super(TrackerVerifyBaseTestCase, self).setUp()
        self.segment = self.get_random_string()
        self.pt.set_custom_variable(
            5,
            'testsegment',
            self.segment,
        )

        # Set up the analytics query
        super(AnalyticsLiveBaseTestCase, self).setUp()
        self.a.set_method('Live.getLastVisitsDetails')
        # Assume no test takes more than one minute
        self.a.set_parameter('lastMinutes', 1)
        self.a.set_segment("customVariableName5==testsegment;"
            "customVariableValue5==%s" % self.segment)

    def get_v(self, key):
        data = json.loads(self.a.send_request())[0]
        try:
            return data[key]
        except KeyError:
            self.debug(data)
            raise

    def get_av(self, key):
        data = json.loads(self.a.send_request())[0]['actionDetails'][0]
        try:
            return data[key]
        except KeyError:
            self.debug(data)
            raise


class TrackerVerifyTestCase(TrackerVerifyBaseTestCase):
    """
    Here are test we don't verify programmatically yet. I guess we'd have to
    access the Piwik API to fetch data to verify the tracking requests were
    processed properly. At the moment I only check this manually in my Piwik<commit_msg>Use different IP for each verify test case<commit_after>import json

from tracking import TrackerBaseTestCase
from analytics import AnalyticsLiveBaseTestCase

from piwikapi.analytics import PiwikAnalytics


class TrackerVerifyBaseTestCase(TrackerBaseTestCase, AnalyticsLiveBaseTestCase):
    def setUp(self):
        super(TrackerVerifyBaseTestCase, self).setUp()
        self.segment = self.get_random_string()
        self.pt.set_custom_variable(
            5,
            'testsegment',
            self.segment,
        )
        self.pt.set_token_auth(self.settings.PIWIK_TOKEN_AUTH) # verify hack
        self.pt.set_ip(self.get_random_ip())

        # Set up the analytics query
        super(AnalyticsLiveBaseTestCase, self).setUp()
        self.a.set_method('Live.getLastVisitsDetails')
        # Assume no test takes more than one minute
        self.a.set_parameter('lastMinutes', 1)
        self.a.set_segment("customVariableName5==testsegment;"
            "customVariableValue5==%s" % self.segment)

    def get_v(self, key):
        data = json.loads(self.a.send_request())[0]
        try:
            return data[key]
        except KeyError:
            self.debug(data)
            raise

    def get_av(self, key):
        data = json.loads(self.a.send_request())[0]['actionDetails'][0]
        try:
            return data[key]
        except KeyError:
            self.debug(data)
            raise


class TrackerVerifyTestCase(TrackerVerifyBaseTestCase):
    """
    Here are test we don't verify programmatically yet. I guess we'd have to
    access the Piwik API to fetch data to verify the tracking requests were
    processed properly. At the moment I only check this manually in my Piwik
{'fraction_non_alphanumeric': 0.08229198415117342, 'fraction_numerical': 0.004266991770801585, 'mean_word_length': 2.6547884187082404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1866320', 'n_tokens_mistral': 915, 'n_tokens_neox': 901, 'n_words': 236}