mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-28 09:16:49 +01:00
4e53dc74b7
* update billing distinct IDs on user join/leave org * temporarily update on usage report send to update existing orgs * abstract a bit more * update existing tests * add billing_manager test for the method * Update query snapshots * specify date * move outside the transaction * cache the instance license * use new instance license method in other places * fix mypy and some tests * Update query snapshots * Update query snapshots * fix caching in tests * constrain try/except * Update query snapshots * make sure we hae license before update billing * Update query snapshots * Update query snapshots * set to false if no instance license * fix date * Update query snapshots * use correct var * Update UI snapshots for `chromium` (1) * clear license cache before running tests * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * fix tests --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
from typing import cast
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from django.utils import timezone
|
|
|
|
from ee.billing.billing_manager import BillingManager
|
|
from ee.models.license import License, LicenseManager
|
|
from posthog.models.organization import OrganizationMembership
|
|
from posthog.models.user import User
|
|
from posthog.test.base import BaseTest
|
|
|
|
|
|
class TestBillingManager(BaseTest):
|
|
@patch(
|
|
"ee.billing.billing_manager.requests.patch",
|
|
return_value=MagicMock(status_code=200, json=MagicMock(return_value={"text": "ok"})),
|
|
)
|
|
def test_update_billing_distinct_ids(self, billing_patch_request_mock: MagicMock):
|
|
organization = self.organization
|
|
license = super(LicenseManager, cast(LicenseManager, License.objects)).create(
|
|
key="key123::key123", plan="enterprise", valid_until=timezone.datetime(2038, 1, 19, 3, 14, 7)
|
|
)
|
|
User.objects.create_and_join(
|
|
organization=organization,
|
|
email="y@x.com",
|
|
password=None,
|
|
level=OrganizationMembership.Level.ADMIN,
|
|
)
|
|
organization.refresh_from_db()
|
|
assert len(organization.members.values_list("distinct_id", flat=True)) == 2 # one exists in the test base
|
|
BillingManager(license).update_billing_distinct_ids(organization)
|
|
assert billing_patch_request_mock.call_count == 1
|
|
assert len(billing_patch_request_mock.call_args[1]["json"]["distinct_ids"]) == 2
|