2016-05-10 20:27:57 +02:00
|
|
|
import pytest
|
2015-07-30 02:13:06 +02:00
|
|
|
|
2016-05-10 20:27:57 +02:00
|
|
|
from lemur.notifications.views import * # noqa
|
2015-07-30 02:13:06 +02:00
|
|
|
|
|
|
|
|
2019-05-16 16:57:02 +02:00
|
|
|
from .vectors import (
|
|
|
|
VALID_ADMIN_API_TOKEN,
|
|
|
|
VALID_ADMIN_HEADER_TOKEN,
|
|
|
|
VALID_USER_HEADER_TOKEN,
|
|
|
|
)
|
2015-07-30 02:13:06 +02:00
|
|
|
|
|
|
|
|
2016-10-09 09:06:53 +02:00
|
|
|
def test_notification_input_schema(client, notification_plugin, notification):
|
2016-05-10 20:27:57 +02:00
|
|
|
from lemur.notifications.schemas import NotificationInputSchema
|
2015-07-30 02:13:06 +02:00
|
|
|
|
2016-05-10 20:27:57 +02:00
|
|
|
input_data = {
|
2019-05-16 16:57:02 +02:00
|
|
|
"label": "notification1",
|
|
|
|
"options": {},
|
|
|
|
"description": "my notification",
|
|
|
|
"active": True,
|
|
|
|
"plugin": {"slug": "test-notification"},
|
2016-05-10 20:27:57 +02:00
|
|
|
}
|
2015-07-30 02:13:06 +02:00
|
|
|
|
2016-05-10 20:27:57 +02:00
|
|
|
data, errors = NotificationInputSchema().load(input_data)
|
2015-07-30 02:13:06 +02:00
|
|
|
|
2016-05-10 20:27:57 +02:00
|
|
|
assert not errors
|
2015-07-30 02:13:06 +02:00
|
|
|
|
|
|
|
|
2019-05-16 16:57:02 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"token,status",
|
|
|
|
[
|
|
|
|
(VALID_USER_HEADER_TOKEN, 200),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 200),
|
|
|
|
(VALID_ADMIN_API_TOKEN, 200),
|
|
|
|
("", 401),
|
|
|
|
],
|
|
|
|
)
|
2016-10-09 09:06:53 +02:00
|
|
|
def test_notification_get(client, notification_plugin, notification, token, status):
|
2019-05-16 16:57:02 +02:00
|
|
|
assert (
|
|
|
|
client.get(
|
|
|
|
api.url_for(Notifications, notification_id=notification.id), headers=token
|
|
|
|
).status_code
|
|
|
|
== status
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"token,status",
|
|
|
|
[
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_API_TOKEN, 405),
|
|
|
|
("", 405),
|
|
|
|
],
|
|
|
|
)
|
2016-05-10 20:27:57 +02:00
|
|
|
def test_notification_post_(client, token, status):
|
2019-05-16 16:57:02 +02:00
|
|
|
assert (
|
|
|
|
client.post(
|
|
|
|
api.url_for(Notifications, notification_id=1), data={}, headers=token
|
|
|
|
).status_code
|
|
|
|
== status
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"token,status",
|
|
|
|
[
|
|
|
|
(VALID_USER_HEADER_TOKEN, 400),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 400),
|
|
|
|
(VALID_ADMIN_API_TOKEN, 400),
|
|
|
|
("", 401),
|
|
|
|
],
|
|
|
|
)
|
2016-05-10 20:27:57 +02:00
|
|
|
def test_notification_put(client, token, status):
|
2019-05-16 16:57:02 +02:00
|
|
|
assert (
|
|
|
|
client.put(
|
|
|
|
api.url_for(Notifications, notification_id=1), data={}, headers=token
|
|
|
|
).status_code
|
|
|
|
== status
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"token,status",
|
|
|
|
[
|
|
|
|
(VALID_USER_HEADER_TOKEN, 200),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 200),
|
|
|
|
(VALID_ADMIN_API_TOKEN, 200),
|
|
|
|
("", 401),
|
|
|
|
],
|
|
|
|
)
|
2016-05-10 20:27:57 +02:00
|
|
|
def test_notification_delete(client, token, status):
|
2019-05-16 16:57:02 +02:00
|
|
|
assert (
|
|
|
|
client.delete(
|
|
|
|
api.url_for(Notifications, notification_id=1), headers=token
|
|
|
|
).status_code
|
|
|
|
== status
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"token,status",
|
|
|
|
[
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_API_TOKEN, 405),
|
|
|
|
("", 405),
|
|
|
|
],
|
|
|
|
)
|
2016-05-10 20:27:57 +02:00
|
|
|
def test_notification_patch(client, token, status):
|
2019-05-16 16:57:02 +02:00
|
|
|
assert (
|
|
|
|
client.patch(
|
|
|
|
api.url_for(Notifications, notification_id=1), data={}, headers=token
|
|
|
|
).status_code
|
|
|
|
== status
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"token,status",
|
|
|
|
[
|
|
|
|
(VALID_USER_HEADER_TOKEN, 400),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 400),
|
|
|
|
(VALID_ADMIN_API_TOKEN, 400),
|
|
|
|
("", 401),
|
|
|
|
],
|
|
|
|
)
|
2016-05-10 20:27:57 +02:00
|
|
|
def test_notification_list_post_(client, token, status):
|
2019-05-16 16:57:02 +02:00
|
|
|
assert (
|
|
|
|
client.post(api.url_for(NotificationsList), data={}, headers=token).status_code
|
|
|
|
== status
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"token,status",
|
|
|
|
[
|
|
|
|
(VALID_USER_HEADER_TOKEN, 200),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 200),
|
|
|
|
(VALID_ADMIN_API_TOKEN, 200),
|
|
|
|
("", 401),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_notification_list_get(
|
|
|
|
client, notification_plugin, notification, token, status
|
|
|
|
):
|
|
|
|
assert (
|
|
|
|
client.get(api.url_for(NotificationsList), headers=token).status_code == status
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"token,status",
|
|
|
|
[
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_API_TOKEN, 405),
|
|
|
|
("", 405),
|
|
|
|
],
|
|
|
|
)
|
2016-05-10 20:27:57 +02:00
|
|
|
def test_notification_list_delete(client, token, status):
|
2019-05-16 16:57:02 +02:00
|
|
|
assert (
|
|
|
|
client.delete(api.url_for(NotificationsList), headers=token).status_code
|
|
|
|
== status
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"token,status",
|
|
|
|
[
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_API_TOKEN, 405),
|
|
|
|
("", 405),
|
|
|
|
],
|
|
|
|
)
|
2016-05-10 20:27:57 +02:00
|
|
|
def test_notification_list_patch(client, token, status):
|
2019-05-16 16:57:02 +02:00
|
|
|
assert (
|
|
|
|
client.patch(api.url_for(NotificationsList), data={}, headers=token).status_code
|
|
|
|
== status
|
|
|
|
)
|