From d6752d1912619a52b44dbbe9ef3714386c98a01c Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Wed, 24 Jul 2024 11:03:06 +0200 Subject: Initial Commit of Qt Binary Size Bot Task-number: QTQAINFRA-6459 Change-Id: I50887b05bd7f11119092ba284082aacc3062ee19 --- tests/test_coin_api.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/test_coin_api.py (limited to 'tests/test_coin_api.py') 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") -- cgit v1.2.3