Skip to content

Commit

Permalink
feat: Create staff fixture (#2928)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaysan authored Nov 6, 2023
1 parent 2788ad5 commit a09436d
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,29 @@ def test_user_client(api_client, test_user):


@pytest.fixture()
def organisation(db, admin_user):
def staff_user(django_user_model):
"""
A non-admin user fixture.
To add to an environment with permissions use the fixture
with_environment_permissions.
This fixture is attached to the organisation fixture.
"""
return django_user_model.objects.create(email="[email protected]")


@pytest.fixture()
def staff_client(staff_user):
client = APIClient()
client.force_authenticate(user=staff_user)
return client


@pytest.fixture()
def organisation(db, admin_user, staff_user):
org = Organisation.objects.create(name="Test Org")
admin_user.add_organisation(org, role=OrganisationRole.ADMIN)
staff_user.add_organisation(org, role=OrganisationRole.USER)
return org


Expand Down Expand Up @@ -156,6 +176,29 @@ def environment(project):
return Environment.objects.create(name="Test Environment", project=project)


@pytest.fixture()
def with_environment_permissions(
environment: Environment, staff_user: FFAdminUser
) -> typing.Callable:
"""
Add environment permissions to the staff_user fixture.
Defaults to associating to the environment fixture.
"""

def _with_environment_permissions(
permission_keys: list[str], environment_id: typing.Optional[int] = None
) -> UserEnvironmentPermission:
environment_id = environment_id or environment.id
uep, __ = UserEnvironmentPermission.objects.get_or_create(
environment_id=environment_id, user=staff_user
)
uep.permissions.add(*permission_keys)

return uep

return _with_environment_permissions


@pytest.fixture()
def identity(environment):
return Identity.objects.create(identifier="test_identity", environment=environment)
Expand Down

3 comments on commit a09436d

@vercel
Copy link

@vercel vercel bot commented on a09436d Nov 6, 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-flagsmith.vercel.app
docs.bullet-train.io
docs.flagsmith.com
docs-git-main-flagsmith.vercel.app

@vercel
Copy link

@vercel vercel bot commented on a09436d Nov 6, 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 a09436d Nov 6, 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.