aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_coin_api.py
diff options
context:
space:
mode:
authorDaniel Smith <daniel.smith@qt.io>2024-07-24 11:03:06 +0200
committerDaniel Smith <daniel.smith@qt.io>2024-07-24 11:04:35 +0200
commitd6752d1912619a52b44dbbe9ef3714386c98a01c (patch)
tree0b2400252230dfd6707db2738ebbf83c0b699696 /tests/test_coin_api.py
Initial Commit of Qt Binary Size Bot
Diffstat (limited to 'tests/test_coin_api.py')
-rw-r--r--tests/test_coin_api.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test_coin_api.py b/tests/test_coin_api.py
new file mode 100644
index 0000000..f99cb18
--- /dev/null
+++ b/tests/test_coin_api.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+import unittest
+import coin_api
+import datetime
+import requests_mock
+
+
+class TestCoinApi(unittest.TestCase):
+ @requests_mock.Mocker()
+ def test_task_details_ok_case(self, m):
+ m.get('https://coin.ci.qt.io/coin/api/taskDetail',
+ text='{"tasks": \
+ [{"state":"Passed", \
+ "completed_on":"2024-03-28 11:40:49 +0000 UTC", \
+ "id":"test_id", \
+ "sha":"sha1", \
+ "tested_changes": [ { \
+ "sha": "sha2", \
+ "project": "project" \
+ },{ \
+ "sha": "sha3", \
+ "project": "project" \
+ }] \
+ }]}')
+
+ dictionary = coin_api.get_coin_task_details("test_id")
+ self.assertEqual(dictionary['coin_update_ongoing'], False)
+ self.assertEqual(dictionary['last_timestamp'], datetime.datetime.fromisoformat("2024-03-28 11:40:49").replace(tzinfo=datetime.timezone.utc))
+ self.assertEqual(dictionary['git_shas'], ["sha2", "sha3"])
+
+ @requests_mock.Mocker()
+ def test_artifacts_url_ok_case(self, m):
+ m.get('https://coin.ci.qt.io/coin/api/taskWorkItems',
+ text='{"tasks_with_workitems": \
+ [{"workitems":[{ \
+ "project":"project", \
+ "branch":"branch", \
+ "identifier":"task_identifier", \
+ "storage_paths": {"log_raw":"/log.txt.gz"}, \
+ "state":"Done" \
+ }]}]}')
+
+ self.assertEqual(coin_api.get_artifacts_url("test_id", "project", "branch", "task_identifier"), "https://coin.intra.qt.io/artifacts.tar.gz")