mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-14 23:07:49 -04:00
notify-api-59 make command to create new service
This commit is contained in:
2
Makefile
2
Makefile
@@ -76,7 +76,7 @@ test: ## Run tests and create coverage report
|
|||||||
pipenv run black .
|
pipenv run black .
|
||||||
pipenv run flake8 .
|
pipenv run flake8 .
|
||||||
pipenv run isort --check-only ./app ./tests
|
pipenv run isort --check-only ./app ./tests
|
||||||
pipenv run coverage run -m pytest -vv --maxfail=10
|
pipenv run coverage run -m pytest --maxfail=10
|
||||||
pipenv run coverage report -m --fail-under=95
|
pipenv run coverage report -m --fail-under=95
|
||||||
pipenv run coverage html -d .coverage_cache
|
pipenv run coverage html -d .coverage_cache
|
||||||
|
|
||||||
|
|||||||
@@ -792,3 +792,27 @@ def update_templates():
|
|||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
for d in data:
|
for d in data:
|
||||||
_update_template(d["id"], d["name"], d["type"], d["content"], d["subject"])
|
_update_template(d["id"], d["name"], d["type"], d["content"], d["subject"])
|
||||||
|
|
||||||
|
|
||||||
|
@notify_command(name="create-new-service")
|
||||||
|
@click.option("-n", "--name", required=True, prompt=True)
|
||||||
|
@click.option("-l", "--message_limit", required=False, default=40000)
|
||||||
|
@click.option("-r", "--restricted", required=False, default=False)
|
||||||
|
@click.option("-e", "--email_from", required=True)
|
||||||
|
@click.option("-c", "--created_by_id", required=True)
|
||||||
|
def create_new_service(name, message_limit, restricted, email_from, created_by_id):
|
||||||
|
data = {
|
||||||
|
"name": name,
|
||||||
|
"message_limit": message_limit,
|
||||||
|
"restricted": restricted,
|
||||||
|
"email_from": email_from,
|
||||||
|
"created_by_id": created_by_id,
|
||||||
|
}
|
||||||
|
|
||||||
|
service = Service(**data)
|
||||||
|
try:
|
||||||
|
db.session.add(service)
|
||||||
|
db.session.commit()
|
||||||
|
except IntegrityError:
|
||||||
|
print("duplicate service", service.name)
|
||||||
|
db.session.rollback()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import pytest
|
|||||||
|
|
||||||
from app.commands import (
|
from app.commands import (
|
||||||
_update_template,
|
_update_template,
|
||||||
|
create_new_service,
|
||||||
create_test_user,
|
create_test_user,
|
||||||
fix_billable_units,
|
fix_billable_units,
|
||||||
insert_inbound_numbers_from_file,
|
insert_inbound_numbers_from_file,
|
||||||
@@ -24,6 +25,7 @@ from app.models import (
|
|||||||
Job,
|
Job,
|
||||||
Notification,
|
Notification,
|
||||||
Organization,
|
Organization,
|
||||||
|
Service,
|
||||||
Template,
|
Template,
|
||||||
User,
|
User,
|
||||||
)
|
)
|
||||||
@@ -324,3 +326,39 @@ def test_update_template(notify_db_session, email_2fa_code_template):
|
|||||||
t = Template.query.all()
|
t = Template.query.all()
|
||||||
|
|
||||||
assert t[0].name == "Example text message template!"
|
assert t[0].name == "Example text message template!"
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_service_command(notify_db_session, notify_api):
|
||||||
|
notify_api.test_cli_runner().invoke(
|
||||||
|
create_test_user,
|
||||||
|
[
|
||||||
|
"--email",
|
||||||
|
"somebody@fake.gov",
|
||||||
|
"--mobile_number",
|
||||||
|
"202-555-5555",
|
||||||
|
"--password",
|
||||||
|
"correct horse battery staple",
|
||||||
|
"--name",
|
||||||
|
"Fake Personson",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
user = User.query.first()
|
||||||
|
|
||||||
|
service_count = Service.query.count()
|
||||||
|
|
||||||
|
# run the command
|
||||||
|
result = notify_api.test_cli_runner().invoke(
|
||||||
|
create_new_service,
|
||||||
|
["-e", "somebody@fake.gov", "-n", "Fake Service", "-c", user.id],
|
||||||
|
)
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
# there should be one more service
|
||||||
|
assert Service.query.count() == service_count + 1
|
||||||
|
|
||||||
|
# that service should be the one we added
|
||||||
|
service = Service.query.filter_by(name="Fake Service").first()
|
||||||
|
assert service.email_from == "somebody@fake.gov"
|
||||||
|
assert service.restricted is False
|
||||||
|
assert service.message_limit == 40000
|
||||||
|
|||||||
Reference in New Issue
Block a user