import requests import pytest @pytest.mark.skip( reason="Test currently failing within Docker image; this is being looked at" ) def test_create_template(): expected_result = "Template new_template created." url = 'http://localhost:3458/notify/create/' headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'subject': 'testing'} json_packet = {"name": "new_template", "description": "a test template", "template": "Subject: {{foo}}\n\n{{bar}}"} r = requests.post(url, headers=headers, json=json_packet) actual_result = r.text assert actual_result == expected_result @pytest.mark.skip( reason="Test currently failing within Docker image; this is being looked at" ) def test_get_templates(): """POST /notify/ should return "The notification service will go here." """ expected_result = "Available notification templates:\nemail\nnew_template\n" url = 'http://localhost:3458/notify/' headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'} r = requests.post(url, headers=headers) print(r) actual_result = r.text assert actual_result == expected_result @pytest.mark.skip( reason="Test currently failing within Docker image; this is being looked at" ) @pytest.mark.skip( reason="Test currently failing within Docker image; this is being looked at" ) def test_send_email(): """check that calling the send email function returns without error""" expected_result = """Email sent.\nSubject: first thing\n\nsecond thing""" url = 'http://localhost:3458/notify/email/send' headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'subject': 'testing'} json_packet = {"destination_email": "your-email@nrao.edu", "subject": "first thing", "message": "second thing"} r = requests.post(url, headers=headers, json=json_packet) print(r) actual_result = r.text assert actual_result == expected_result @pytest.mark.skip( reason="Test currently failing within Docker image; this is being looked at" ) def test_bad_template_name(): """check that calling with a non-existant template name gives an error message""" expected_result = """No template 'nonsense' found.""" url = 'http://localhost:3458/notify/nonsense/send' headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'subject': 'testing'} json_packet = {"destination_email": "your-email@nrao.edu", "stuff": "first thing", "more": "second thing"} r = requests.post(url, headers=headers, json=json_packet) print(r) actual_result = r.text assert actual_result == expected_result @pytest.mark.skip( reason="Test currently failing within Docker image; this is being looked at" ) def test_delete_tamplate(): expected_result = "Template new_template deleted." url = 'http://localhost:3458/notify/new_template/delete' headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'subject': 'testing'} r = requests.post(url, headers=headers) actual_result = r.text assert actual_result == expected_result