Beispiel #1
0
    def test_run_raises_fail(self):
        url = "https://data.mixpanel.com/api/2.0/export?from_date=abc&to_date=abc"
        responses.add(responses.GET, url, status=123, body="mixpanel error")

        mx_export_task = MixpanelExportTask()

        with pytest.raises(FAIL, match="Mixpanel export API error."):
            mx_export_task.run(api_secret="foo",
                               from_date="abc",
                               to_date="abc")
Beispiel #2
0
    def test_run_secret_from_api_secret(self, caplog):
        today = date.today().strftime("%Y-%m-%d")
        url = f"https://data.mixpanel.com/api/2.0/export?from_date=2011-07-10&to_date={today}"
        responses.add(responses.GET, url, status=200)

        mx_export_task = MixpanelExportTask()

        secret = "foo"
        mx_export_task.run(api_secret=secret)

        secret_bytes = f"{secret}:".encode("ascii")
        secret_b64_bytes = base64.b64encode(secret_bytes)
        secret_message = secret_b64_bytes.decode("ascii")
        authorization = f"Basic {secret_message}"

        assert responses.calls[0].request.headers[
            "Authorization"] == authorization
Beispiel #3
0
    def test_run_empty_result_with_parse(self):
        today = date.today().strftime("%Y-%m-%d")
        url = f"https://data.mixpanel.com/api/2.0/export?from_date=2011-07-10&to_date={today}"
        responses.add(responses.GET, url, status=200, body="")

        mx_export_task = MixpanelExportTask()
        ret = mx_export_task.run(api_secret="foo", parse_response=True)

        assert ret is None
Beispiel #4
0
    def test_run_with_parse(self):
        today = date.today().strftime("%Y-%m-%d")
        url = f"https://data.mixpanel.com/api/2.0/export?from_date=2011-07-10&to_date={today}"
        responses.add(responses.GET,
                      url,
                      status=200,
                      body='{"foo": "bar"}\n{"alice": "bob"}')

        mx_export_task = MixpanelExportTask()
        ret = mx_export_task.run(api_secret="foo", parse_response=True)

        assert ret == [{"foo": "bar"}, {"alice": "bob"}]
Beispiel #5
0
    def test_run_with_parse_and_group(self):
        today = date.today().strftime("%Y-%m-%d")
        url = f"https://data.mixpanel.com/api/2.0/export?from_date=2011-07-10&to_date={today}"
        event1 = '{"event": "alice", "properties": {"p1": "v1"}}'
        event2 = '{"event": "bob", "properties": {"p1": "v1"}}'
        event3 = '{"event": "bob", "properties": {"p2": "v2"}}'
        body = "\n".join([event1, event2, event3])
        responses.add(responses.GET, url, status=200, body=body)

        mx_export_task = MixpanelExportTask()
        ret = mx_export_task.run(api_secret="foo",
                                 parse_response=True,
                                 group_events=True)

        assert ret == {
            "alice": [{
                "p1": "v1"
            }],
            "bob": [{
                "p1": "v1"
            }, {
                "p2": "v2"
            }]
        }