Skip to content

Commit 9cdf76a

Browse files
committed
chore: Added basic integration tests for task enqueue and delete
1 parent 9740962 commit 9cdf76a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ to ensure that exported user records contain the password hashes of the user acc
252252
3. Click **ADD ANOTHER ROLE** and choose **Firebase Authentication Admin**.
253253
4. Click **SAVE**.
254254

255+
9. Enable Cloud Tasks:
256+
1. Search for and enable **Cloud Run**.
257+
2. Search for and enable **Cloud Tasks**.
258+
3. Go to [Google Cloud console | IAM & admin](https://console.cloud.google.com/iam-admin)
259+
and make sure your Firebase project is selected.
260+
4. Ensure your service account has the following required roles:
261+
* **Cloud Tasks Enqueuer** - `cloudtasks.taskEnqueuer`
262+
* **Cloud Tasks Task Deleter** - `cloudtasks.taskDeleter`
263+
* **Cloud Run Invoker** - `run.invoker`
264+
* **Service Account User** - `iam.serviceAccountUser`
265+
255266

256267
Now you can invoke the integration test suite as follows:
257268

integration/test_functions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from integration import conftest
2222

2323

24+
_DEFAULT_DATA = {'data': {'city': 'Seattle'}}
25+
2426
@pytest.fixture(scope='module')
2527
def app(request):
2628
cred, _ = conftest.integration_conf(request)
@@ -54,3 +56,21 @@ def test_task_queue_app(self, task_queue_params, app):
5456
assert queue is not None
5557
assert callable(queue.enqueue)
5658
assert callable(queue.delete)
59+
60+
def test_task_enqueue(self, app):
61+
queue = functions.task_queue('testTaskQueue', app=app)
62+
task_id = queue.enqueue(_DEFAULT_DATA)
63+
assert task_id is not None
64+
65+
def test_task_delete(self, app):
66+
# Skip this test against the emulator since tasks can't be delayed there to verify deletion
67+
# See: https://github.com/firebase/firebase-tools/issues/8254
68+
task_options = functions.TaskOptions(schedule_delay_seconds=60)
69+
queue = functions.task_queue('testTaskQueue', app=app)
70+
task_id = queue.enqueue(_DEFAULT_DATA, task_options)
71+
assert task_id is not None
72+
queue.delete(task_id)
73+
# We don't have a way to check the contents of the queue so we check that the deleted
74+
# task is not found using the delete method again.
75+
with pytest.raises(firebase_admin.exceptions.NotFoundError):
76+
queue.delete(task_id)

0 commit comments

Comments
 (0)