Skip to content

Commit ab4166b

Browse files
Ace NassriTakashi Matsuo
andauthored
functions: fix slack + pubsub tests (GoogleCloudPlatform#3808)
* 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>
1 parent d8d9cc2 commit ab4166b

File tree

6 files changed

+6
-58
lines changed

6 files changed

+6
-58
lines changed

.kokoro/tests/run_tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ gcloud auth activate-service-account \
5050

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

5554
# For Datalabeling samples to hit the testing endpoint
5655
export DATALABELING_ENDPOINT="test-datalabeling.sandbox.googleapis.com:443"

functions/pubsub/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def publish(request):
4646
'data': {'message': message},
4747
})
4848
message_bytes = message_json.encode('utf-8')
49-
print(message_bytes)
5049

5150
# Publishes a message
5251
try:

functions/pubsub/main_test.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,36 @@
1616
import os
1717

1818
from mock import MagicMock
19-
import pytest
2019

2120
import main
2221

2322

2423
FUNCTIONS_TOPIC = os.getenv("FUNCTIONS_TOPIC")
2524

2625

27-
@pytest.mark.skip("broken")
2826
def test_functions_pubsub_publish_should_fail_without_params():
2927
request = MagicMock()
30-
request.body.topic = None
28+
request.get_json.return_value = {}
3129
response = main.publish(request)
3230

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

3533

36-
@pytest.mark.skip("broken")
3734
def test_functions_pubsub_publish_should_publish_message():
3835
request = MagicMock()
39-
request.body.topic = FUNCTIONS_TOPIC
40-
request.body.message = "my_message"
36+
request.get_json.return_value = {
37+
"topic": FUNCTIONS_TOPIC, "message": "my_message"
38+
}
4139

4240
response = main.publish(request)
4341

4442
assert response == "Message published."
4543

4644

47-
@pytest.mark.skip("broken")
4845
def test_functions_pubsub_subscribe_should_print_message(capsys):
49-
pubsub_message = MagicMock()
50-
pubsub_message.data = base64.b64encode(b"Hello, world!")
46+
pubsub_message = {"data": base64.b64encode(b"Hello, world!")}
5147

52-
main.subscribe(pubsub_message)
48+
main.subscribe(pubsub_message, None)
5349

5450
out, _ = capsys.readouterr()
5551
assert "Hello, world!" in out

functions/slack/main_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def test_verify_signature_token_incorrect(self):
4848
request.headers = {'X-Slack-Signature': '12345'}
4949
main.verify_signature(request)
5050

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

77-
@pytest.mark.skip("broken")
7876
def test_kg_search(self):
7977
with mock.patch.object(main, 'kgsearch'):
8078
entities = main.kgsearch.entities.return_value

functions/slack/noxfile_config.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

testing/secrets.tar.enc

1 KB
Binary file not shown.

0 commit comments

Comments
 (0)