Skip to content

Commit

Permalink
Merge pull request #46 from LukaszSielski/extract_commons
Browse files Browse the repository at this point in the history
added tests
  • Loading branch information
LukaszSielski authored Sep 24, 2024
2 parents 97ef719 + 50c89d4 commit b166565
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion scripts/test_script.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import unittest
from unittest import mock
import argparse

from gh_cli import PrNotFoundException, GhCliException
import script
import subprocess

@mock.patch('script.argparse.ArgumentParser.parse_args', return_value=argparse.Namespace(commit_sha='123', deploy_env='dev'))
@mock.patch('gh_cli.check_output')
Expand All @@ -27,3 +28,17 @@ def test_should_properly_tag_ado_work_items_if_many_work_item_tag_in_pr_body(sel
mock.call('az boards work-item update --id 123456 --org https://dev.azure.com/lukaszadamsielski0187 --fields "System.Tags=VNXT CL Dev"', shell=True, stderr=-2),
mock.call('az boards work-item update --id 654321 --org https://dev.azure.com/lukaszadamsielski0187 --fields "System.Tags=VNXT CL Dev"', shell=True, stderr=-2),
])

def test_should_throw_exception_if_pr__not_found(self, az_cli_check_output, gh_cli_check_output, parse_args_mock):
gh_cli_check_output.return_value = '[]'

with self.assertRaises(PrNotFoundException) as e:
script.main()
self.assertEquals('Could not find pull request for commit identitifed by 123 SHA', str(e.exception))

def test_should_throw_exception_if_gh_cli_command_failed(self, az_cli_check_output, gh_cli_check_output, parse_args_mock):
gh_cli_check_output.side_effect = subprocess.CalledProcessError('test', 'test', 'Error!')

with self.assertRaises(GhCliException) as e:
script.main()
self.assertEquals('Failed to execute GH CLI command! Error: Error!', str(e.exception))

0 comments on commit b166565

Please sign in to comment.