예제 #1
0
    def assert_loid(self, create=True, new=True):
        loid = LoId.load(self.request, self.context, create=create)
        self.assertIsNotNone(loid.loid)
        self.assertIsNotNone(loid.created)
        self.assertIs(loid.new, new)

        loid.save()

        if not new:
            self.assertFalse(bool(self.context.cookies.add.called))
            g.events.queue_production.assert_item_count(0)
        else:
            self.context.cookies.add.assert_has_calls(
                [
                    call(LOID_COOKIE, quote(loid.loid), expires=ANY),
                    call(LOID_CREATED_COOKIE, to_isodate(loid.created), expires=ANY),
                ]
            )
            payload = self.make_event_payload()
            payload.update(
                {
                    "loid_new": True,
                    "loid": loid.loid,
                    "loid_created": to_epoch_milliseconds(loid.created),
                    "loid_version": 0,
                }
            )
            g.events.queue_production.assert_event_item(
                dict(event_topic="loid_events", event_type="ss.create_loid", payload=payload)
            )
예제 #2
0
 def test_ftue_nocreate(self):
     request = MagicMock()
     context = MagicMock()
     request.cookies = {}
     loid = LoId.load(request, context, create=False)
     self.assertFalse(loid.new)
     self.assertFalse(loid.serializable)
     loid.save()
     self.assertFalse(bool(context.cookies.add.called))
예제 #3
0
 def test_ftue_nocreate(self):
     request = MagicMock()
     context = MagicMock()
     request.cookies = {}
     loid = LoId.load(request, context, create=False)
     self.assertFalse(loid.new)
     self.assertFalse(loid.serializable)
     loid.save()
     self.assertFalse(bool(context.cookies.add.called))
예제 #4
0
 def test_returning(self):
     request = MagicMock()
     context = MagicMock()
     request.cookies = {LOID_COOKIE: "foo", LOID_CREATED_COOKIE: "bar"}
     loid = LoId.load(request, create=False)
     self.assertEqual(loid.loid, "foo")
     self.assertEqual(loid.created, "bar")
     self.assertFalse(loid._new)
     loid.save(context)
     self.assertFalse(bool(context.cookies.add.called))
예제 #5
0
 def test_ftue_nocreate(self):
     request = MagicMock()
     context = MagicMock()
     request.cookies = {}
     loid = LoId.load(request, create=False)
     self.assertIsNone(loid.loid)
     self.assertIsNone(loid.created)
     self.assertFalse(loid._new)
     loid.save(context)
     self.assertFalse(bool(context.cookies.add.called))
예제 #6
0
 def test_returning(self):
     request = MagicMock()
     context = MagicMock()
     request.cookies = {LOID_COOKIE: "foo", LOID_CREATED_COOKIE: "bar"}
     loid = LoId.load(request, create=False)
     self.assertEqual(loid.loid, "foo")
     self.assertEqual(loid.created, "bar")
     self.assertFalse(loid._new)
     loid.save(context)
     self.assertFalse(bool(context.cookies.add.called))
예제 #7
0
 def test_ftue_nocreate(self):
     request = MagicMock()
     context = MagicMock()
     request.cookies = {}
     loid = LoId.load(request, create=False)
     self.assertIsNone(loid.loid)
     self.assertIsNone(loid.created)
     self.assertFalse(loid._new)
     loid.save(context)
     self.assertFalse(bool(context.cookies.add.called))
예제 #8
0
 def assert_no_loid(self, create=True, kind="ineligible_loid"):
     loid = LoId.load(self.request, self.context, create=create)
     self.assertFalse(loid.new)
     self.assertFalse(loid.serializable)
     loid.save()
     self.assertFalse(bool(self.context.cookies.add.called))
     payload = self.make_event_payload()
     g.events.queue_production.assert_event_item(
         dict(event_topic="loid_events", event_type="ss.%s" % kind, payload=payload)
     )
예제 #9
0
    def test_ftue_autocreate(self):
        request = MagicMock()
        context = MagicMock()
        request.cookies = {}
        loid = LoId.load(request, create=True)
        self.assertIsNotNone(loid.loid)
        self.assertIsNotNone(loid.created)
        self.assertTrue(loid.new)

        loid.save()

        context.cookies.add.assert_has_calls([
            call(
                LOID_COOKIE,
                quote(loid.loid),
                expires=ANY,
            ),
            call(
                LOID_CREATED_COOKIE,
                isodate(loid.created),
                expires=ANY,
            )
        ])
        self.amqp.assert_event_item(
            dict(
                event_topic="loid_events",
                event_type="ss.create_loid",
                payload={
                    'loid_new': True,
                    'loid': loid.loid,
                    'loid_created': to_epoch_milliseconds(loid.created),
                    'loid_version': 0,

                    'user_id': context.user._id,
                    'user_name': context.user.name,
                    'user_features': context.user.user_features,

                    'request_url': request.fullpath,
                    'domain': request.host,
                    'geoip_country': context.location,
                    'oauth2_client_id': context.oauth2_client._id,
                    'oauth2_client_app_type': context.oauth2_client.app_type,
                    'oauth2_client_name': context.oauth2_client.name,
                    'referrer_domain': self.domain_mock(),
                    'referrer_url': request.headers.get(),
                    'user_agent': request.user_agent,
                    'user_agent_parsed': request.parsed_agent.to_dict(),
                    'obfuscated_data': {
                        'client_ip': request.ip,
                    }
                },
            )
        )
예제 #10
0
    def test_ftue_autocreate(self):
        request = MagicMock()
        context = MagicMock()
        request.cookies = {}
        loid = LoId.load(request, create=True)
        self.assertIsNotNone(loid.loid)
        self.assertIsNotNone(loid.created)
        self.assertTrue(loid.new)

        loid.save()

        context.cookies.add.assert_has_calls([
            call(
                LOID_COOKIE,
                quote(loid.loid),
                expires=ANY,
            ),
            call(
                LOID_CREATED_COOKIE,
                isodate(loid.created),
                expires=ANY,
            )
        ])
        self.amqp.assert_event_item(
            dict(
                event_topic="loid_events",
                event_type="ss.create_loid",
                payload={
                    'loid_new': True,
                    'loid': loid.loid,
                    'loid_created': to_epoch_milliseconds(loid.created),
                    'loid_version': 0,
                    'user_id': context.user._id,
                    'user_name': context.user.name,
                    'user_features': context.user.user_features,
                    'request_url': request.fullpath,
                    'domain': request.host,
                    'geoip_country': context.location,
                    'oauth2_client_id': context.oauth2_client._id,
                    'oauth2_client_app_type': context.oauth2_client.app_type,
                    'oauth2_client_name': context.oauth2_client.name,
                    'referrer_domain': self.domain_mock(),
                    'referrer_url': request.headers.get(),
                    'user_agent': request.user_agent,
                    'user_agent_parsed': request.parsed_agent.to_dict(),
                    'obfuscated_data': {
                        'client_ip': request.ip,
                    }
                },
            ))
예제 #11
0
    def test_ftue_autocreate(self):
        request = MagicMock()
        context = MagicMock()
        request.cookies = {}
        loid = LoId.load(request, create=True)
        self.assertIsNotNone(loid.loid)
        self.assertIsNotNone(loid.created)
        self.assertTrue(loid._new)

        loid.save(context)

        context.cookies.add.assert_has_calls([
            call(
                LOID_COOKIE,
                quote(loid.loid),
                expires=ANY,
            ),
            call(
                LOID_CREATED_COOKIE,
                loid.created,
                expires=ANY,
            )
        ])
예제 #12
0
    def test_ftue_autocreate(self):
        request = MagicMock()
        context = MagicMock()
        request.cookies = {}
        loid = LoId.load(request, create=True)
        self.assertIsNotNone(loid.loid)
        self.assertIsNotNone(loid.created)
        self.assertTrue(loid._new)

        loid.save(context)

        context.cookies.add.assert_has_calls([
            call(
                LOID_COOKIE,
                quote(loid.loid),
                expires=ANY,
            ),
            call(
                LOID_CREATED_COOKIE,
                loid.created,
                expires=ANY,
            )
        ])