Moved unit tests to folder
This commit is contained in:
parent
6cefb7ed03
commit
bc524358ff
2 changed files with 0 additions and 0 deletions
110
tests/test_unit/test_lolaconfig.py
Normal file
110
tests/test_unit/test_lolaconfig.py
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
from types import SimpleNamespace
|
||||
|
||||
from lolafect.lolaconfig import LolaConfig
|
||||
|
||||
|
||||
def test_lolaconfig_instantiates_with_defaults_properly():
|
||||
lolaconfig = LolaConfig(flow_name="some-flow")
|
||||
|
||||
|
||||
def test_lolaconfig_instantiates_without_defaults_proplery():
|
||||
lolaconfig = LolaConfig(
|
||||
flow_name="some-flow",
|
||||
env_s3_bucket="bucket",
|
||||
kubernetes_labels=["some_label"],
|
||||
kubernetes_image="loliloli:latest",
|
||||
slack_webhooks_file="the_file/is/here.json",
|
||||
)
|
||||
|
||||
|
||||
def test_lolaconfig_fetches_webhooks_properly():
|
||||
lolaconfig = LolaConfig(flow_name="some-flow")
|
||||
|
||||
fake_s3_reader = SimpleNamespace()
|
||||
|
||||
def mock_read_json_from_s3_file(bucket, key):
|
||||
return {"a-channel-name": "a-channel-url.com"}
|
||||
|
||||
fake_s3_reader.read_json_from_s3_file = mock_read_json_from_s3_file
|
||||
|
||||
lolaconfig.fetch_slack_webhooks(s3_reader=fake_s3_reader)
|
||||
|
||||
assert type(lolaconfig.SLACK_WEBHOOKS) is dict
|
||||
|
||||
|
||||
def test_lolaconfig_fetches_trino_creds_properly():
|
||||
lolaconfig = LolaConfig(flow_name="some-flow")
|
||||
|
||||
fake_s3_reader = SimpleNamespace()
|
||||
|
||||
def mock_read_json_from_s3_file(bucket, key):
|
||||
return {
|
||||
"trino_host": "some_host",
|
||||
"trino_user": "some_user",
|
||||
"trino_pass": "some_password",
|
||||
"trino_port": "some_port",
|
||||
}
|
||||
|
||||
fake_s3_reader.read_json_from_s3_file = mock_read_json_from_s3_file
|
||||
|
||||
lolaconfig.fetch_trino_credentials(s3_reader=fake_s3_reader)
|
||||
|
||||
assert type(lolaconfig.TRINO_CREDENTIALS) is dict
|
||||
|
||||
|
||||
def test_lolaconfig_fetches_ssh_tunnel_creds_properly():
|
||||
lolaconfig = LolaConfig(flow_name="some-flow")
|
||||
|
||||
fake_s3_reader = SimpleNamespace()
|
||||
|
||||
def mock_read_json_from_s3_file(bucket, key):
|
||||
return {
|
||||
"pt_ssh_pkey_path": "some-path",
|
||||
"pt_ssh_pkey_passphrase": "some-password",
|
||||
"pt_ssh_username": "some-username",
|
||||
"pt_ssh_jumphost_port": "some-port",
|
||||
"pt_ssh_jumphost": "some-jumphost",
|
||||
}
|
||||
|
||||
fake_s3_reader.read_json_from_s3_file = mock_read_json_from_s3_file
|
||||
|
||||
lolaconfig.fetch_ssh_tunnel_credentials(s3_reader=fake_s3_reader)
|
||||
|
||||
assert type(lolaconfig.SSH_TUNNEL_CREDENTIALS) is dict
|
||||
|
||||
|
||||
def test_lolaconfig_fetches_dw_creds_properly():
|
||||
lolaconfig = LolaConfig(flow_name="some-flow")
|
||||
|
||||
fake_s3_reader = SimpleNamespace()
|
||||
|
||||
def mock_read_json_from_s3_file(bucket, key):
|
||||
return {
|
||||
"datadw_host": "some_host",
|
||||
"datadw_user": "some_user",
|
||||
"datadw_pass": "some_password",
|
||||
"datadw_port": "some_port",
|
||||
}
|
||||
|
||||
fake_s3_reader.read_json_from_s3_file = mock_read_json_from_s3_file
|
||||
|
||||
lolaconfig.fetch_dw_credentials(s3_reader=fake_s3_reader)
|
||||
|
||||
assert type(lolaconfig.DW_CREDENTIALS) is dict
|
||||
|
||||
|
||||
def test_lolaconfig_fetches_prefect_host_properly():
|
||||
lolaconfig = LolaConfig(flow_name="some-flow")
|
||||
|
||||
fake_s3_reader = SimpleNamespace()
|
||||
|
||||
def mock_read_json_from_s3_file(bucket, key):
|
||||
return {
|
||||
"prefect_host": "some_host",
|
||||
}
|
||||
|
||||
fake_s3_reader.read_json_from_s3_file = mock_read_json_from_s3_file
|
||||
|
||||
lolaconfig.fetch_prefect_host(s3_reader=fake_s3_reader)
|
||||
|
||||
assert type(lolaconfig.PREFECT_HOST) is str
|
||||
65
tests/test_unit/test_slack.py
Normal file
65
tests/test_unit/test_slack.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import json
|
||||
|
||||
import httpretty
|
||||
import pytest
|
||||
|
||||
from lolafect.slack import send_message_to_slack_channel, SendSlackMessageTask
|
||||
|
||||
|
||||
@httpretty.activate(allow_net_connect=False, verbose=True)
|
||||
def test_send_message_to_slack_channel_works_properly():
|
||||
mock_webhook_url = "http://the-webhook-url.com"
|
||||
mock_message_to_channel = "Hi there!"
|
||||
httpretty.register_uri(method=httpretty.POST, uri=mock_webhook_url, status=200)
|
||||
|
||||
send_message_to_slack_channel(
|
||||
webhook_url=mock_webhook_url, text_to_send=mock_message_to_channel
|
||||
)
|
||||
|
||||
request_observed_by_server = httpretty.last_request()
|
||||
|
||||
assert (request_observed_by_server.method == "POST") and (
|
||||
json.loads(request_observed_by_server.body.decode("UTF-8"))
|
||||
== {"text": mock_message_to_channel}
|
||||
)
|
||||
|
||||
|
||||
@httpretty.activate(allow_net_connect=False, verbose=True)
|
||||
def test_send_message_to_slack_channel_response_400_raises_exception():
|
||||
mock_webhook_url = "http://the-webhook-url.com"
|
||||
mock_message_to_channel = "Hi there!"
|
||||
httpretty.register_uri(method=httpretty.POST, uri=mock_webhook_url, status=400)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
send_message_to_slack_channel(
|
||||
webhook_url=mock_webhook_url, text_to_send=mock_message_to_channel
|
||||
)
|
||||
|
||||
|
||||
@httpretty.activate(allow_net_connect=False, verbose=True)
|
||||
def test_slack_task_reaches_server_successfully():
|
||||
mock_webhook_url = "http://the-webhook-url.com"
|
||||
mock_message_to_channel = "Hi there!"
|
||||
httpretty.register_uri(method=httpretty.POST, uri=mock_webhook_url, status=200)
|
||||
|
||||
slack_task = SendSlackMessageTask()
|
||||
slack_task.run(webhook_url=mock_webhook_url, text_to_send=mock_message_to_channel)
|
||||
|
||||
request_observed_by_server = httpretty.last_request()
|
||||
assert (request_observed_by_server.method == "POST") and (
|
||||
json.loads(request_observed_by_server.body.decode("UTF-8"))
|
||||
== {"text": mock_message_to_channel}
|
||||
)
|
||||
|
||||
|
||||
@httpretty.activate(allow_net_connect=False, verbose=True)
|
||||
def test_slack_task_raises_value_error():
|
||||
mock_webhook_url = "http://the-webhook-url.com"
|
||||
mock_message_to_channel = "Hi there!"
|
||||
httpretty.register_uri(method=httpretty.POST, uri=mock_webhook_url, status=400)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
slack_task = SendSlackMessageTask()
|
||||
slack_task.run(
|
||||
webhook_url=mock_webhook_url, text_to_send=mock_message_to_channel
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue