Exemplo n.º 1
0
    def setUp(self):
        """Setup function for each unit test."""

        super(GoogleAnalyticsV4HookTest, self).setUp()

        self.test_api_secret = 'abcdABCDefghEFGH123456'
        self.test_payload_type_gtag = 'gtag'
        self.test_payload_type_firebase = 'firebase'
        self.test_measurement_id = 'G-02ABCDEFGH'
        self.test_firebase_app_id = '1:12345678901:android:1234567890abcdef'

        self.test_gtag_hook = ga4_hook.GoogleAnalyticsV4Hook(
            self.test_api_secret,
            self.test_payload_type_gtag,
            measurement_id=self.test_measurement_id)

        self.test_firebase_hook = ga4_hook.GoogleAnalyticsV4Hook(
            self.test_api_secret,
            self.test_payload_type_firebase,
            firebase_app_id=self.test_firebase_app_id)

        self.gtag_full_url = (f'https://www.google-analytics.com/mp/collect?'
                              f'api_secret={self.test_api_secret}&'
                              f'measurement_id={self.test_measurement_id}')
        self.firebase_full_url = (
            f'https://www.google-analytics.com/mp/collect?'
            f'api_secret={self.test_api_secret}&'
            f'firebase_app_id={self.test_firebase_app_id}')
        self.test_client_id = 'test_client_id'
        self.test_app_instance_id = 'test_app_instance_id'
        self.test_ga4_payload = {
            'client_id':
            'cid',
            'events': [{
                'name': 'add_to_cart',
                'params': {
                    'quantity': 1,
                    'item_name': 'good shoes',
                    'item_id': 'shoe_id_1',
                    'price': 5999,
                    'currency': 'JPY'
                }
            }]
        }
        self.test_event = {
            'id': 1,
            'payload': json.dumps(self.test_ga4_payload)
        }
Exemplo n.º 2
0
 def test_ga4_hook_init_with_unsupport_payload_type(self):
     with self.assertRaises(errors.DataOutConnectorError):
         self.test_hook = ga4_hook.GoogleAnalyticsV4Hook(
             self.test_api_secret, 'unsupported_type')
Exemplo n.º 3
0
 def test_ga4_hook_init_with_firebase_payload_type_and_measurement_id(self):
     with self.assertRaises(errors.DataOutConnectorError):
         self.test_hook = ga4_hook.GoogleAnalyticsV4Hook(
             self.test_api_secret,
             'firebase',
             measurement_id=self.test_measurement_id)
Exemplo n.º 4
0
 def test_ga4_hook_init_with_gtag_payload_type_and_firebase_app_id(self):
     with self.assertRaises(errors.DataOutConnectorError):
         self.test_hook = ga4_hook.GoogleAnalyticsV4Hook(
             self.test_api_secret,
             'gtag',
             firebase_app_id=self.test_firebase_app_id)
Exemplo n.º 5
0
 def test_ga4_hook_init_with_no_api_secret(self):
     with self.assertRaises(errors.DataOutConnectorError):
         self.test_hook = ga4_hook.GoogleAnalyticsV4Hook(
             None, 'gtag', measurement_id=self.test_measurement_id)