tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_taskcluster_yml.py (5079B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 import pprint
      6 import unittest
      7 
      8 import jsone
      9 import slugid
     10 from mozunit import main
     11 from taskgraph.util.time import current_json_time
     12 from taskgraph.util.yaml import load_yaml
     13 
     14 from gecko_taskgraph import GECKO
     15 
     16 
     17 class TestTaskclusterYml(unittest.TestCase):
     18    @property
     19    def taskcluster_yml(self):
     20        return load_yaml(GECKO, ".taskcluster.yml")
     21 
     22    def test_push(self):
     23        context = {
     24            "tasks_for": "hg-push",
     25            "push": {
     26                "revision": "e8d2d9aff5026ef1f1777b781b47fdcbdb9d8f20",
     27                "base_revision": "e8aebe488b2f2e567940577de25013d00e818f7c",
     28                "owner": "dustin@mozilla.com",
     29                "pushlog_id": 1556565286,
     30                "pushdate": 112957,
     31            },
     32            "repository": {
     33                "url": "https://hg.mozilla.org/mozilla-central",
     34                "project": "mozilla-central",
     35                "level": "3",
     36            },
     37            "ownTaskId": slugid.nice(),
     38        }
     39        rendered = jsone.render(self.taskcluster_yml, context)
     40        pprint.pprint(rendered)
     41        self.assertEqual(
     42            rendered["tasks"][0]["metadata"]["name"], "Gecko Decision Task"
     43        )
     44        self.assertIn("matrixBody", rendered["tasks"][0]["extra"]["notify"])
     45 
     46    def test_push_non_mc(self):
     47        context = {
     48            "tasks_for": "hg-push",
     49            "push": {
     50                "revision": "e8d2d9aff5026ef1f1777b781b47fdcbdb9d8f20",
     51                "base_revision": "e8aebe488b2f2e567940577de25013d00e818f7c",
     52                "owner": "dustin@mozilla.com",
     53                "pushlog_id": 1556565286,
     54                "pushdate": 112957,
     55            },
     56            "repository": {
     57                "url": "https://hg.mozilla.org/releases/mozilla-beta",
     58                "project": "mozilla-beta",
     59                "level": "3",
     60            },
     61            "ownTaskId": slugid.nice(),
     62        }
     63        rendered = jsone.render(self.taskcluster_yml, context)
     64        pprint.pprint(rendered)
     65        self.assertEqual(
     66            rendered["tasks"][0]["metadata"]["name"], "Gecko Decision Task"
     67        )
     68        self.assertNotIn("matrixBody", rendered["tasks"][0]["extra"]["notify"])
     69 
     70    def test_cron(self):
     71        context = {
     72            "tasks_for": "cron",
     73            "repository": {
     74                "url": "https://hg.mozilla.org/mozilla-central",
     75                "project": "mozilla-central",
     76                "level": 3,
     77            },
     78            "push": {
     79                "revision": "e8aebe488b2f2e567940577de25013d00e818f7c",
     80                "base_revision": "54cbb3745cdb9a8aa0a4428d405b3b2e1c7d13c2",
     81                "pushlog_id": -1,
     82                "pushdate": 0,
     83                "owner": "cron",
     84            },
     85            "cron": {
     86                "task_id": "<cron task id>",
     87                "job_name": "test",
     88                "job_symbol": "T",
     89                "quoted_args": "abc def",
     90            },
     91            "now": current_json_time(),
     92            "ownTaskId": slugid.nice(),
     93        }
     94        rendered = jsone.render(self.taskcluster_yml, context)
     95        pprint.pprint(rendered)
     96        self.assertEqual(
     97            rendered["tasks"][0]["metadata"]["name"], "Decision Task for cron job test"
     98        )
     99 
    100    def test_action(self):
    101        context = {
    102            "tasks_for": "action",
    103            "repository": {
    104                "url": "https://hg.mozilla.org/mozilla-central",
    105                "project": "mozilla-central",
    106                "level": 3,
    107            },
    108            "push": {
    109                "revision": "e8d2d9aff5026ef1f1777b781b47fdcbdb9d8f20",
    110                "base_revision": "e8aebe488b2f2e567940577de25013d00e818f7c",
    111                "owner": "dustin@mozilla.com",
    112                "pushlog_id": 1556565286,
    113                "pushdate": 112957,
    114            },
    115            "action": {
    116                "name": "test-action",
    117                "title": "Test Action",
    118                "description": "Just testing",
    119                "taskGroupId": slugid.nice(),
    120                "symbol": "t",
    121                "repo_scope": "assume:repo:hg.mozilla.org/try:action:generic",
    122                "cb_name": "test_action",
    123            },
    124            "input": {},
    125            "parameters": {},
    126            "now": current_json_time(),
    127            "taskId": slugid.nice(),
    128            "ownTaskId": slugid.nice(),
    129            "clientId": "testing/testing/testing",
    130        }
    131        rendered = jsone.render(self.taskcluster_yml, context)
    132        pprint.pprint(rendered)
    133        self.assertEqual(
    134            rendered["tasks"][0]["metadata"]["name"], "Action: Test Action"
    135        )
    136 
    137    def test_unknown(self):
    138        context = {"tasks_for": "bitkeeper-push"}
    139        rendered = jsone.render(self.taskcluster_yml, context)
    140        pprint.pprint(rendered)
    141        self.assertEqual(rendered["tasks"], [])
    142 
    143 
    144 if __name__ == "__main__":
    145    main()