def test_monthly_restore(self): """Monthly restore""" ent = OrganizationEntitlementFactory() organization = OrganizationFactory( entitlement=ent, date_update=date(2019, 2, 21), requests_per_month=50, monthly_requests=33, ) organization.update_data({ "name": organization.name, "slug": organization.slug, "individual": False, "private": False, "entitlements": [ent_json(ent, date(2019, 3, 21))], "max_users": 5, "card": "", }) organization.refresh_from_db() eq_(organization.requests_per_month, 50) eq_(organization.monthly_requests, 50)
def test_decrease_max_users(self): """Decrease max users""" ent = OrganizationEntitlementFactory() organization = OrganizationFactory( entitlement=ent, date_update=date(2019, 2, 21), requests_per_month=75, monthly_requests=33, ) organization.update_data({ "name": organization.name, "slug": organization.slug, "individual": False, "private": False, "entitlements": [ent_json(ent, date(2019, 2, 21))], "max_users": 7, "card": "", }) organization.refresh_from_db() eq_(organization.requests_per_month, 60) eq_(organization.monthly_requests, 33)
def test_downgrade_subscription(self): """Downgrade a subscription""" # Downgrades only happen at monthly restore ent = OrganizationEntitlementFactory() plus = EntitlementFactory(name="Plus", resources=dict(minimum_users=5, base_requests=100)) organization = OrganizationFactory( entitlement=plus, date_update=date(2019, 2, 21), requests_per_month=100, monthly_requests=83, ) organization.update_data({ "name": organization.name, "slug": organization.slug, "individual": False, "private": False, "entitlements": [ent_json(ent, date(2019, 3, 21))], "max_users": 5, "card": "", }) organization.refresh_from_db() eq_(organization.requests_per_month, 50) eq_(organization.monthly_requests, 50)
def test_feature_level(self): """Test getting a users max feature level from their entitlements""" free = ProfileFactory( user__membership__organization__entitlement=FreeEntitlementFactory() ) pro = ProfileFactory( user__membership__organization__entitlement=ProfessionalEntitlementFactory() ) org = ProfileFactory( user__membership__organization__entitlement=OrganizationEntitlementFactory() ) eq_(free.feature_level, 0) eq_(pro.feature_level, 1) eq_(org.feature_level, 2) MembershipFactory( user=free.user, organization__entitlement__name="Organization" ) # refresh from db because feature level is cached free = Profile.objects.get(pk=free.pk) # if in free entitlement and org entitlement, take the larger one eq_(free.feature_level, 2)
def test_is_advanced(self): """Test whether the users are marked as advanced.""" pro = ProfileFactory( user__membership__organization__entitlement=ProfessionalEntitlementFactory() ) org = ProfileFactory( user__membership__organization__entitlement=OrganizationEntitlementFactory() ) free = ProfileFactory( user__membership__organization__entitlement=FreeEntitlementFactory() ) assert_true(pro.is_advanced()) assert_true(org.is_advanced()) assert_false(free.is_advanced())
def test_cancel_subscription(self): """Cancel a subscription""" ent = FreeEntitlementFactory() organization = OrganizationFactory( entitlement=OrganizationEntitlementFactory(), date_update=date(2019, 2, 21), requests_per_month=50, monthly_requests=33, ) organization.update_data({ "name": organization.name, "slug": organization.slug, "individual": False, "private": False, "entitlements": [ent_json(ent, None)], "max_users": 5, "card": "", }) organization.refresh_from_db() eq_(organization.requests_per_month, 0) eq_(organization.monthly_requests, 0)
def test_create_subscription(self): """Create a new subscription""" ent = OrganizationEntitlementFactory() organization = OrganizationFactory() organization.update_data({ "name": organization.name, "slug": organization.slug, "individual": False, "private": False, "entitlements": [ent_json(ent, date(2019, 2, 21))], "max_users": 5, "card": "", }) organization.refresh_from_db() eq_(organization.requests_per_month, 50) eq_(organization.monthly_requests, 50)