mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 14:31:57 -05:00
Support testing commands and add first test
We have a lot of commands and it's important we test the ones that are meant to be used in the future to ensure they work when they're needed. Testing Flask commands is usually easy as written in their docs [1], but I had to make some changes to the way we decorate the command functions so they can work with test DB objects - I couldn't find any example of someone else encountering the same problem. [1]: https://flask.palletsprojects.com/en/2.0.x/testing/#testing-cli-commands
This commit is contained in:
26
tests/app/test_commands.py
Normal file
26
tests/app/test_commands.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import uuid
|
||||
|
||||
from app.commands import local_dev_broadcast_permissions
|
||||
from app.dao.services_dao import dao_add_user_to_service
|
||||
from tests.app.db import create_user
|
||||
|
||||
|
||||
def test_local_dev_broadcast_permissions(
|
||||
sample_service,
|
||||
sample_broadcast_service,
|
||||
notify_api,
|
||||
):
|
||||
# create_user will pull existing unless email is unique
|
||||
user = create_user(email=f'{uuid.uuid4()}@example.com')
|
||||
dao_add_user_to_service(sample_service, user)
|
||||
dao_add_user_to_service(sample_broadcast_service, user)
|
||||
|
||||
assert len(user.get_permissions(sample_service.id)) == 0
|
||||
assert len(user.get_permissions(sample_broadcast_service.id)) == 0
|
||||
|
||||
notify_api.test_cli_runner().invoke(
|
||||
local_dev_broadcast_permissions, ['-u', user.id]
|
||||
)
|
||||
|
||||
assert len(user.get_permissions(sample_service.id)) == 0
|
||||
assert len(user.get_permissions(sample_broadcast_service.id)) > 0
|
||||
Reference in New Issue
Block a user