1 from __future__
import absolute_import
, division
, unicode_literals
7 from cola
.models
import main
12 class MainModelTestCase(helper
.GitRepositoryTestCase
):
13 """Tests the MainModel class."""
15 def test_project(self
):
16 """Test the 'project' attribute."""
17 project
= os
.path
.basename(self
.test_path())
18 self
.model
.set_worktree(core
.getcwd())
19 self
.assertEqual(self
.model
.project
, project
)
21 def test_local_branches(self
):
22 """Test the 'local_branches' attribute."""
24 self
.model
.update_status()
25 self
.assertEqual(self
.model
.local_branches
, ['master'])
27 def test_remote_branches(self
):
28 """Test the 'remote_branches' attribute."""
29 self
.model
.update_status()
30 self
.assertEqual(self
.model
.remote_branches
, [])
33 self
.run_git('remote', 'add', 'origin', '.')
34 self
.run_git('fetch', 'origin')
35 self
.model
.update_status()
36 self
.assertEqual(self
.model
.remote_branches
, ['origin/master'])
38 def test_modified(self
):
39 """Test the 'modified' attribute."""
40 self
.write_file('A', 'change')
41 self
.model
.update_status()
42 self
.assertEqual(self
.model
.modified
, ['A'])
44 def test_unstaged(self
):
45 """Test the 'unstaged' attribute."""
46 self
.write_file('A', 'change')
47 self
.write_file('C', 'C')
48 self
.model
.update_status()
49 self
.assertEqual(self
.model
.unstaged
, ['A', 'C'])
51 def test_untracked(self
):
52 """Test the 'untracked' attribute."""
53 self
.write_file('C', 'C')
54 self
.model
.update_status()
55 self
.assertEqual(self
.model
.untracked
, ['C'])
57 def test_remotes(self
):
58 """Test the 'remote' attribute."""
59 self
.run_git('remote', 'add', 'origin', '.')
60 self
.model
.update_status()
61 self
.assertEqual(self
.model
.remotes
, ['origin'])
63 def test_currentbranch(self
):
64 """Test the 'currentbranch' attribute."""
65 self
.run_git('checkout', '-b', 'test')
66 self
.model
.update_status()
67 self
.assertEqual(self
.model
.currentbranch
, 'test')
70 """Test the 'tags' attribute."""
72 self
.run_git('tag', 'test')
73 self
.model
.update_status()
74 self
.assertEqual(self
.model
.tags
, ['test'])
77 class RemoteArgsTestCase(unittest
.TestCase
):
80 self
.remote
= 'server'
81 self
.local_branch
= 'local'
82 self
.remote_branch
= 'remote'
84 def test_remote_args_fetch(self
):
87 main
.remote_args(self
.remote
,
88 local_branch
=self
.local_branch
,
89 remote_branch
=self
.remote_branch
)
91 self
.assertEqual(args
, [self
.remote
, 'remote:local'])
92 self
.assertTrue(kwargs
['verbose'])
93 self
.assertFalse('tags' in kwargs
)
94 self
.assertFalse('rebase' in kwargs
)
96 def test_remote_args_fetch_tags(self
):
99 main
.remote_args(self
.remote
,
101 local_branch
=self
.local_branch
,
102 remote_branch
=self
.remote_branch
)
104 self
.assertEqual(args
, [self
.remote
, 'remote:local'])
105 self
.assertTrue(kwargs
['verbose'])
106 self
.assertTrue(kwargs
['tags'])
107 self
.assertFalse('rebase' in kwargs
)
109 def test_remote_args_pull(self
):
112 main
.remote_args(self
.remote
,
115 remote_branch
=self
.remote_branch
)
117 self
.assertEqual(args
, [self
.remote
, 'remote'])
118 self
.assertTrue(kwargs
['verbose'])
119 self
.assertFalse('rebase' in kwargs
)
120 self
.assertFalse('tags' in kwargs
)
122 def test_remote_args_pull_rebase(self
):
125 main
.remote_args(self
.remote
,
129 remote_branch
=self
.remote_branch
)
131 self
.assertEqual(args
, [self
.remote
, 'remote'])
132 self
.assertTrue(kwargs
['verbose'])
133 self
.assertTrue(kwargs
['rebase'])
134 self
.assertFalse('tags' in kwargs
)
136 def test_remote_args_push(self
):
137 # Push, swap local and remote
139 main
.remote_args(self
.remote
,
140 local_branch
=self
.remote_branch
,
141 remote_branch
=self
.local_branch
)
143 self
.assertEqual(args
, [self
.remote
, 'local:remote'])
144 self
.assertTrue(kwargs
['verbose'])
145 self
.assertFalse('tags' in kwargs
)
146 self
.assertFalse('rebase' in kwargs
)
148 def test_remote_args_push_tags(self
):
149 # Push, swap local and remote
151 main
.remote_args(self
.remote
,
153 local_branch
=self
.remote_branch
,
154 remote_branch
=self
.local_branch
)
156 self
.assertEqual(args
, [self
.remote
, 'local:remote'])
157 self
.assertTrue(kwargs
['verbose'])
158 self
.assertTrue(kwargs
['tags'])
159 self
.assertFalse('rebase' in kwargs
)
161 def test_remote_args_push_same_remote_and_local(self
):
163 main
.remote_args(self
.remote
,
165 local_branch
=self
.local_branch
,
166 remote_branch
=self
.local_branch
,
169 self
.assertEqual(args
, [self
.remote
, 'local'])
170 self
.assertTrue(kwargs
['verbose'])
171 self
.assertTrue(kwargs
['tags'])
172 self
.assertFalse('rebase' in kwargs
)
174 def test_remote_args_push_set_upstream(self
):
176 main
.remote_args(self
.remote
,
178 local_branch
=self
.local_branch
,
179 remote_branch
=self
.local_branch
,
183 self
.assertEqual(args
, [self
.remote
, 'local'])
184 self
.assertTrue(kwargs
['verbose'])
185 self
.assertTrue(kwargs
['tags'])
186 self
.assertTrue(kwargs
['set_upstream'])
187 self
.assertFalse('rebase' in kwargs
)
189 def test_remote_args_rebase_only(self
):
191 main
.remote_args(self
.remote
,
195 self
.assertTrue(kwargs
['rebase'])
196 self
.assertFalse('ff_only' in kwargs
)
198 def test_run_remote_action(self
):
200 def passthrough(*args
, **kwargs
):
201 return (args
, kwargs
)
204 main
.run_remote_action(passthrough
,
206 local_branch
=self
.local_branch
,
207 remote_branch
=self
.remote_branch
)
209 self
.assertEqual(args
, (self
.remote
, 'remote:local'))
210 self
.assertTrue(kwargs
['verbose'])
211 self
.assertFalse('tags' in kwargs
)
212 self
.assertFalse('rebase' in kwargs
)
215 if __name__
== '__main__':