-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_filter_changes.py
More file actions
138 lines (109 loc) · 5.89 KB
/
test_filter_changes.py
File metadata and controls
138 lines (109 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3
"""
Test script to verify the new filtering functionality for submodules and local/remote categories.
"""
import unittest
from unittest.mock import Mock, patch, MagicMock
import sys
import os
# Add the current directory to sys.path so we can import the main module
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# Mock tkinter to avoid GUI creation during testing
with patch('tkinter.Tk'), patch('tkinter.ttk.Style'), patch('tkinter.ttk.Treeview'):
from git_repository_manager import GitRepositoryManager, GitRepository, GitBranch
class TestFilterChanges(unittest.TestCase):
def setUp(self):
"""Set up test fixtures"""
with patch('tkinter.Tk'), patch('tkinter.ttk.Style'), patch('tkinter.ttk.Treeview'):
self.app = GitRepositoryManager()
self.app.repo_tree = Mock()
self.app.search_scope = Mock()
# Create mock repositories
self.main_repo = Mock(spec=GitRepository)
self.main_repo.path = "/test/main_repo"
self.main_repo.name = "main_repo"
self.main_repo.is_submodule = False
self.submodule = Mock(spec=GitRepository)
self.submodule.path = "/test/main_repo/submodule"
self.submodule.name = "submodule"
self.submodule.is_submodule = True
# Create mock branches
self.local_branch_match = Mock(spec=GitBranch)
self.local_branch_match.author = "test_user"
self.local_branch_match.commit_message = "test message"
self.local_branch_match.is_remote = False
self.local_branch_no_match = Mock(spec=GitBranch)
self.local_branch_no_match.author = "other_user"
self.local_branch_no_match.commit_message = "other message"
self.local_branch_no_match.is_remote = False
self.remote_branch_match = Mock(spec=GitBranch)
self.remote_branch_match.author = "test_user"
self.remote_branch_match.commit_message = "remote test message"
self.remote_branch_match.is_remote = True
self.remote_branch_no_match = Mock(spec=GitBranch)
self.remote_branch_no_match.author = "other_user"
self.remote_branch_no_match.commit_message = "other remote message"
self.remote_branch_no_match.is_remote = True
def test_repo_has_matching_branches_with_filter(self):
"""Test _repo_has_matching_branches method with active filters"""
# Set up repository with branches
self.main_repo.local_branches = [self.local_branch_match, self.local_branch_no_match]
self.main_repo.remote_branches = [self.remote_branch_no_match]
# Set up filter
self.app.branch_filter_user = "test_user"
self.app.branch_filter_message = ""
self.app.search_scope.get = Mock(return_value="remote and local")
# Test
result = self.app._repo_has_matching_branches(self.main_repo)
self.assertTrue(result, "Should find matching branch")
def test_repo_has_matching_branches_no_filter(self):
"""Test _repo_has_matching_branches method with no active filters"""
# Set up repository with branches
self.main_repo.local_branches = [self.local_branch_no_match]
self.main_repo.remote_branches = [self.remote_branch_no_match]
# No filters
self.app.branch_filter_user = ""
self.app.branch_filter_message = ""
# Test
result = self.app._repo_has_matching_branches(self.main_repo)
self.assertTrue(result, "Should return True when no filters are active and branches exist")
def test_get_matching_branch_types_local_only(self):
"""Test _get_matching_branch_types when only local branches match"""
# Set up repository
self.main_repo.local_branches = [self.local_branch_match]
self.main_repo.remote_branches = [self.remote_branch_no_match]
# Set up filter
self.app.branch_filter_user = "test_user"
self.app.branch_filter_message = ""
self.app.search_scope.get = Mock(return_value="remote and local")
# Test
has_local, has_remote = self.app._get_matching_branch_types(self.main_repo)
self.assertTrue(has_local, "Should have local matches")
self.assertFalse(has_remote, "Should not have remote matches")
def test_get_matching_branch_types_remote_only(self):
"""Test _get_matching_branch_types when only remote branches match"""
# Set up repository
self.main_repo.local_branches = [self.local_branch_no_match]
self.main_repo.remote_branches = [self.remote_branch_match]
# Set up filter
self.app.branch_filter_user = "test_user"
self.app.branch_filter_message = ""
self.app.search_scope.get = Mock(return_value="remote and local")
# Test
has_local, has_remote = self.app._get_matching_branch_types(self.main_repo)
self.assertFalse(has_local, "Should not have local matches")
self.assertTrue(has_remote, "Should have remote matches")
def test_get_matching_branch_types_no_filter(self):
"""Test _get_matching_branch_types when no filters are active"""
# Set up repository
self.main_repo.local_branches = [self.local_branch_no_match]
self.main_repo.remote_branches = [self.remote_branch_no_match]
# No filters
self.app.branch_filter_user = ""
self.app.branch_filter_message = ""
# Test
has_local, has_remote = self.app._get_matching_branch_types(self.main_repo)
self.assertTrue(has_local, "Should have local when no filters")
self.assertTrue(has_remote, "Should have remote when no filters")
if __name__ == "__main__":
unittest.main()