Skip to content

Commit e830836

Browse files
committed
cleanup tests, add instructions to readme
1 parent f3ee238 commit e830836

File tree

10 files changed

+35
-10
lines changed

10 files changed

+35
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ flake8.out
1313
pylint.out
1414
posthog-analytics
1515
.idea
16+
.python-version
17+
.coverage

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
test:
1+
lint:
22
pylint --rcfile=.pylintrc --reports=y --exit-zero analytics | tee pylint.out
33
flake8 --max-complexity=10 --statistics analytics > flake8.out || true
4-
coverage run --branch --include=analytics/\* --omit=*/test* setup.py test
4+
5+
test:
6+
coverage run -m pytest
7+
coverage report
58

69
release:
710
rm -rf dist/*
@@ -26,4 +29,4 @@ release_analytics:
2629
e2e_test:
2730
.buildscripts/e2e.sh
2831

29-
.PHONY: test release e2e_test
32+
.PHONY: test lint release e2e_test

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ Specifically, the [Python integration](https://posthog.com/docs/integrations/pyt
77
## Questions?
88

99
### [Join our Slack community.](https://join.slack.com/t/posthogusers/shared_invite/enQtOTY0MzU5NjAwMDY3LTc2MWQ0OTZlNjhkODk3ZDI3NDVjMDE1YjgxY2I4ZjI4MzJhZmVmNjJkN2NmMGJmMzc2N2U3Yjc3ZjI5NGFlZDQ)
10+
11+
# Running & Testing Locally
12+
13+
1. Run `python3 -m venv env` (creates virtual environment called "env")
14+
2. Run `source env/bin/activate` (activates the virtual environment)
15+
3. Run `python3 -m pip install -e ".[test]"` (installs the package in develop mode, along with test dependencies)
16+
4. Run `make test`
17+
18+
To run tests specific to a file, use

posthog/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def capture(
3232
3333
A `capture` call requires
3434
- `distinct id` which uniquely identifies your user
35-
- `event name` to make sure
35+
- `event name` to specify the event
3636
- We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on.
3737
3838
Optionally you can submit
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import time
22
import unittest
33
from datetime import date, datetime
4+
from uuid import uuid4
45

56
import mock
67
import six
78
from freezegun import freeze_time
89

910
from posthog.client import Client
1011
from posthog.request import APIError
11-
from posthog.test.utils import TEST_API_KEY
12+
from posthog.test.test_utils import TEST_API_KEY
1213
from posthog.version import VERSION
1314

1415

@@ -122,6 +123,16 @@ def test_basic_page(self):
122123
self.assertEqual(msg["distinct_id"], "distinct_id")
123124
self.assertEqual(msg["properties"]["$current_url"], "https://posthog.com/contact")
124125

126+
def test_basic_page_distinct_uuid(self):
127+
client = self.client
128+
distinct_id = uuid4()
129+
success, msg = client.page(distinct_id, url="https://posthog.com/contact")
130+
self.assertFalse(self.failed)
131+
client.flush()
132+
self.assertTrue(success)
133+
self.assertEqual(msg["distinct_id"], str(distinct_id))
134+
self.assertEqual(msg["properties"]["$current_url"], "https://posthog.com/contact")
135+
125136
def test_advanced_page(self):
126137
client = self.client
127138
success, msg = client.page(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from posthog.consumer import MAX_MSG_SIZE, Consumer
1313
from posthog.request import APIError
14-
from posthog.test.utils import TEST_API_KEY
14+
from posthog.test.test_utils import TEST_API_KEY
1515

1616

1717
class TestConsumer(unittest.TestCase):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import requests
66

77
from posthog.request import DatetimeSerializer, batch_post
8-
from posthog.test.utils import TEST_API_KEY
8+
from posthog.test.test_utils import TEST_API_KEY
99

1010

1111
class TestRequests(unittest.TestCase):

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
"black",
2222
"isort",
2323
"pre-commit",
24+
],
25+
"test": [
26+
"mock>=2.0.0", "freezegun==0.3.15", "pylint", "flake8", "coverage"
2427
]
2528
}
2629

27-
tests_require = ["mock>=2.0.0", "freezegun==0.3.15"]
28-
2930
setup(
3031
name="posthog",
3132
version=VERSION,
@@ -39,7 +40,6 @@
3940
license="MIT License",
4041
install_requires=install_requires,
4142
extras_require=extras_require,
42-
tests_require=tests_require,
4343
description="Integrate PostHog into any python application.",
4444
long_description=long_description,
4545
classifiers=[

0 commit comments

Comments
 (0)