| import unittest |
| from unittest.mock import MagicMock |
| from steps import git_metadata |
| |
| class TestGitMetadata(unittest.TestCase): |
| def setUp(self): |
| self.step = git_metadata.GitMetadata() |
| |
| self.step.repos = " [('repo0', 'branch0', 'dir0'), \ |
| ('repo1', 'branch1', ''), \ |
| ('repo2', '', 'dir1'), \ |
| ('repo3', '', 'dir1'), \ |
| ('repo4', '', 'dir1')]" |
| |
| self.step.git_clone_with_branch = MagicMock() |
| self.step.git_clone = MagicMock() |
| |
| self.step.run_script() |
| |
| def test_git_clone_with_branch(self): |
| """Tests git_clone_with_branch method is called with the right arguments""" |
| self.step.git_clone_with_branch.assert_any_call("repo0", "branch0", "dir0") |
| self.step.git_clone_with_branch.assert_called_with("repo1", "branch1", "") |
| |
| def test_git_clone(self): |
| """Tests git_clone method is called with the right arguments""" |
| self.step.git_clone.assert_any_call("repo2", "dir1") |
| self.step.git_clone.assert_any_call("repo3", "dir1") |
| self.step.git_clone.assert_called_with("repo4", "dir1") |
| |
| def test_git_clone_with_branch_order(self): |
| """Tests that git_clone_with_branch method calls are in the right order""" |
| actual_calls = self.step.git_clone_with_branch.call_args_list |
| expected_calls = [(("repo0", "branch0", "dir0"),), |
| (("repo1", "branch1", ""),)] |
| |
| self.assertEqual(actual_calls, expected_calls) |
| |
| def test_git_clone_order(self): |
| """Tests the order in which git_clone method are called""" |
| actual_calls = self.step.git_clone.call_args_list |
| expected_calls = [(("repo2", "dir1"),), |
| (("repo3", "dir1"),), |
| (("repo4", "dir1"),)] |
| |
| self.assertEqual(actual_calls, expected_calls) |