Skip to content

Commit

Permalink
fix: Move organisation tests to proper location (#3041)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaysan authored Nov 27, 2023
1 parent 6aadec1 commit 34c6d07
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 118 deletions.
Empty file.
52 changes: 0 additions & 52 deletions api/organisations/invites/tests/test_models.py

This file was deleted.

Empty file.
Empty file.
65 changes: 0 additions & 65 deletions api/organisations/tests/test_tasks.py

This file was deleted.

File renamed without changes.
47 changes: 47 additions & 0 deletions api/tests/unit/organisations/invites/test_unit_invites_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import typing
from datetime import timedelta
from unittest import TestCase

import pytest
from django.db.utils import IntegrityError
from django.utils import timezone

from organisations.invites.exceptions import InviteLinksDisabledError
from organisations.invites.models import Invite, InviteLink
Expand All @@ -12,6 +15,50 @@
from pytest_django.fixtures import SettingsWrapper


@pytest.mark.django_db
class InviteLinkTestCase(TestCase):
def setUp(self) -> None:
self.organisation = Organisation.objects.create(name="Test organisation")

def test_is_expired_expiry_date_in_past(self):
# Given
yesterday = timezone.now() - timedelta(days=1)
expired_link = InviteLink.objects.create(
organisation=self.organisation, expires_at=yesterday
)

# When
is_expired = expired_link.is_expired

# Then
assert is_expired

def test_is_expired_expiry_date_in_future(self):
# Given
tomorrow = timezone.now() + timedelta(days=1)
expired_link = InviteLink.objects.create(
organisation=self.organisation, expires_at=tomorrow
)

# When
is_expired = expired_link.is_expired

# Then
assert not is_expired

def test_is_expired_no_expiry_date(self):
# Given
expired_link = InviteLink.objects.create(
organisation=self.organisation, expires_at=None
)

# When
is_expired = expired_link.is_expired

# Then
assert not is_expired


@pytest.mark.django_db
def test_cannot_create_invite_link_if_disabled(settings: "SettingsWrapper") -> None:
# Given
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,17 +1,81 @@
import uuid
from datetime import timedelta

import pytest
from django.utils import timezone

from organisations.chargebee.metadata import ChargebeeObjMetadata
from organisations.models import (
Organisation,
OrganisationRole,
UserOrganisation,
)
from organisations.tasks import finish_subscription_cancellation
from organisations.subscriptions.constants import (
FREE_PLAN_ID,
MAX_SEATS_IN_FREE_PLAN,
)
from organisations.subscriptions.xero.metadata import XeroSubscriptionMetadata
from organisations.tasks import (
ALERT_EMAIL_MESSAGE,
ALERT_EMAIL_SUBJECT,
finish_subscription_cancellation,
send_org_over_limit_alert,
)
from users.models import FFAdminUser


def test_send_org_over_limit_alert_for_organisation_with_free_subscription(
organisation, mocker
):
# Given
mocked_ffadmin_user = mocker.patch("organisations.tasks.FFAdminUser")

# When
send_org_over_limit_alert(organisation.id)

# Then
args, kwargs = mocked_ffadmin_user.send_alert_to_admin_users.call_args
assert len(args) == 0
assert len(kwargs) == 2
assert kwargs["message"] == ALERT_EMAIL_MESSAGE % (
organisation.name,
organisation.num_seats,
MAX_SEATS_IN_FREE_PLAN,
FREE_PLAN_ID,
)
assert kwargs["subject"] == ALERT_EMAIL_SUBJECT


@pytest.mark.parametrize(
"SubscriptionMetadata", [ChargebeeObjMetadata, XeroSubscriptionMetadata]
)
def test_send_org_over_limit_alert_for_organisation_with_subscription(
organisation, subscription, mocker, SubscriptionMetadata
):
# Given
mocked_ffadmin_user = mocker.patch("organisations.tasks.FFAdminUser")
max_seats = 10
mocker.patch(
"organisations.tasks.get_subscription_metadata",
return_value=SubscriptionMetadata(seats=max_seats),
)

# When
send_org_over_limit_alert(organisation.id)

# Then
args, kwargs = mocked_ffadmin_user.send_alert_to_admin_users.call_args
assert len(args) == 0
assert len(kwargs) == 2
assert kwargs["message"] == ALERT_EMAIL_MESSAGE % (
organisation.name,
organisation.num_seats,
max_seats,
subscription.plan,
)
assert kwargs["subject"] == ALERT_EMAIL_SUBJECT


def test_finish_subscription_cancellation(db: None):
organisation1 = Organisation.objects.create()
organisation2 = Organisation.objects.create()
Expand Down

3 comments on commit 34c6d07

@vercel
Copy link

@vercel vercel bot commented on 34c6d07 Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-git-main-flagsmith.vercel.app
docs.flagsmith.com
docs-flagsmith.vercel.app
docs.bullet-train.io

@vercel
Copy link

@vercel vercel bot commented on 34c6d07 Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 34c6d07 Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.