Skip to content

Commit

Permalink
functions: fix slack + pubsub tests (#3808)
Browse files Browse the repository at this point in the history
* functions/slack: fix + re-enable tests

* Fix pub/sub tests

* Remove Slack config file

* Remove noxfile cfg

* Add pubsub topic to secrets file

* Fix lint

* Remove unused context param

* Add placeholder for context arg, since it's required

* Add context param back

Co-authored-by: Takashi Matsuo <tmatsuo@google.com>
  • Loading branch information
Ace Nassri and Takashi Matsuo authored May 19, 2020
1 parent d8d9cc2 commit ab4166b
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 58 deletions.
1 change: 0 additions & 1 deletion .kokoro/tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ gcloud auth activate-service-account \

export GOOGLE_CLIENT_SECRETS=$(pwd)/testing/client-secrets.json
source "${KOKORO_GFILE_DIR}/automl_secrets.txt"
cp "${KOKORO_GFILE_DIR}/functions-slack-config.json" "functions/slack/config.json"

# For Datalabeling samples to hit the testing endpoint
export DATALABELING_ENDPOINT="test-datalabeling.sandbox.googleapis.com:443"
Expand Down
1 change: 0 additions & 1 deletion functions/pubsub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def publish(request):
'data': {'message': message},
})
message_bytes = message_json.encode('utf-8')
print(message_bytes)

# Publishes a message
try:
Expand Down
16 changes: 6 additions & 10 deletions functions/pubsub/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,36 @@
import os

from mock import MagicMock
import pytest

import main


FUNCTIONS_TOPIC = os.getenv("FUNCTIONS_TOPIC")


@pytest.mark.skip("broken")
def test_functions_pubsub_publish_should_fail_without_params():
request = MagicMock()
request.body.topic = None
request.get_json.return_value = {}
response = main.publish(request)

assert 'Missing "topic" and/or "subscription" parameter.' in response


@pytest.mark.skip("broken")
def test_functions_pubsub_publish_should_publish_message():
request = MagicMock()
request.body.topic = FUNCTIONS_TOPIC
request.body.message = "my_message"
request.get_json.return_value = {
"topic": FUNCTIONS_TOPIC, "message": "my_message"
}

response = main.publish(request)

assert response == "Message published."


@pytest.mark.skip("broken")
def test_functions_pubsub_subscribe_should_print_message(capsys):
pubsub_message = MagicMock()
pubsub_message.data = base64.b64encode(b"Hello, world!")
pubsub_message = {"data": base64.b64encode(b"Hello, world!")}

main.subscribe(pubsub_message)
main.subscribe(pubsub_message, None)

out, _ = capsys.readouterr()
assert "Hello, world!" in out
2 changes: 0 additions & 2 deletions functions/slack/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def test_verify_signature_token_incorrect(self):
request.headers = {'X-Slack-Signature': '12345'}
main.verify_signature(request)

@pytest.mark.skip("broken")
def test_verify_web_hook_valid_request(self):
request = Request()
request.headers = {
Expand All @@ -74,7 +73,6 @@ def test_make_search_request(self):
assert 'lion' in message['attachments'][0]['title'].lower()
assert message['attachments'][0]['color'] == '#3367d6'

@pytest.mark.skip("broken")
def test_kg_search(self):
with mock.patch.object(main, 'kgsearch'):
entities = main.kgsearch.entities.return_value
Expand Down
44 changes: 0 additions & 44 deletions functions/slack/noxfile_config.py

This file was deleted.

Binary file modified testing/secrets.tar.enc
Binary file not shown.

0 comments on commit ab4166b

Please sign in to comment.