Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Move organisation tests to proper location #3041

Merged
merged 5 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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
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