Esempio n. 1
0
    def test_track_remove_from_cart(self, mok_track_unstruct):
        mokEmitter = self.create_patch('snowplow_tracker.Emitter')
        e = mokEmitter()

        with ContractsDisabled():
            mok_track_unstruct.side_effect = mocked_track_unstruct

            t = Tracker(e)
            ctx = SelfDescribingJson("test.context.schema", {"user": "******"})
            evTstamp = 1399021242030

            t.track_remove_from_cart("sku1234",
                                     3,
                                     "testName",
                                     "testCategory",
                                     3.14,
                                     "testCurrency",
                                     context=[ctx],
                                     tstamp=evTstamp)

            expected = {
                "schema": REMOVE_FROM_CART_SCHEMA,
                "data": {
                    "sku": "sku1234",
                    "quantity": 3,
                    "name": "testName",
                    "category": "testCategory",
                    "unitPrice": 3.14,
                    "currency": "testCurrency"
                }
            }

            callArgs = mok_track_unstruct.call_args_list[0][0]
            self.assertEqual(len(callArgs), 4)
            self.assertDictEqual(callArgs[0].to_json(), expected)
            self.assertIs(callArgs[1][0], ctx)
            self.assertEqual(callArgs[2], evTstamp)
Esempio n. 2
0
    def test_track_remove_from_cart_optional_none(self, mok_track_unstruct):
        mokEmitter = self.create_patch('snowplow_tracker.Emitter')
        e = mokEmitter()

        with ContractsDisabled():
            mok_track_unstruct.side_effect = mocked_track_unstruct

            t = Tracker(e)

            t.track_remove_from_cart("sku1234", 1)

            expected = {
                "schema": REMOVE_FROM_CART_SCHEMA,
                "data": {
                    "sku": "sku1234",
                    "quantity": 1
                }
            }

            callArgs = mok_track_unstruct.call_args_list[0][0]
            self.assertEqual(len(callArgs), 4)
            self.assertDictEqual(callArgs[0].to_json(), expected)
            self.assertTrue(callArgs[1] is None)
            self.assertTrue(callArgs[2] is None)