Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 8d7ad1f

Browse files
authored
Merge pull request #564 from frennkie/completion2
[WIP] Improve completion
2 parents ff1b121 + e4a19f3 commit 8d7ad1f

File tree

6 files changed

+1076
-841
lines changed

6 files changed

+1076
-841
lines changed

tests/core/ui/test_commands.py

Lines changed: 58 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -20,130 +20,123 @@
2020
class TestCommands:
2121

2222
def setup_class(cls):
23-
instance = commands.Commands()
24-
instance.cmd_open('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
25-
instance.cmd_store()
23+
commands.Open().run('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
24+
commands.Store().run()
2625

2726
def teardown_method(self):
28-
instance = commands.Commands()
29-
instance.cmd_close()
27+
commands.Close().run()
3028

3129
def test_init(self):
3230
instance = commands.Commands()
3331
assert isinstance(instance, commands.Commands)
3432

3533
def test_help(self, capsys):
36-
instance = commands.Commands()
37-
instance.cmd_help()
38-
instance.cmd_clear()
34+
commands.Help().run()
35+
commands.Clear().run()
3936
out, err = capsys.readouterr()
4037
assert re.search(r".* Commands.*", out)
4138
assert re.search(r".* Modules.*", out)
4239

4340
def test_notes(self, capsys):
44-
instance = commands.Commands()
45-
instance.cmd_notes('-h')
46-
instance.cmd_notes('-l')
41+
commands.Notes().run('-h')
4742
out, err = capsys.readouterr()
4843
assert re.search("usage: notes \[-h\] .*", out)
44+
45+
commands.Notes().run('-l')
46+
out, err = capsys.readouterr()
4947
assert re.search(".*No open session.*", out)
5048

5149
def test_open(self, capsys):
52-
instance = commands.Commands()
53-
instance.cmd_open('-h')
54-
instance.cmd_open('-u', 'https://github.com/viper-framework/viper-test-files/raw/master/test_files/cmd.exe')
50+
commands.Open().run('-h')
51+
commands.Open().run('-u', 'https://github.com/viper-framework/viper-test-files/raw/master/test_files/cmd.exe')
5552
out, err = capsys.readouterr()
5653
assert re.search("usage: open \[-h\] .*", out)
5754
assert re.search(".*Session opened on /tmp/.*", out)
5855

5956
def test_open_tor(self, capsys):
60-
instance = commands.Commands()
61-
instance.cmd_open('-h')
62-
instance.cmd_open('-t', '-u', 'https://github.com/viper-framework/viper-test-files/raw/master/test_files/cmd.exe')
57+
commands.Open().run('-h')
58+
commands.Open().run('-t', '-u', 'https://github.com/viper-framework/viper-test-files/raw/master/test_files/cmd.exe')
6359
out, err = capsys.readouterr()
6460
assert re.search("usage: open \[-h\] .*", out)
6561
assert re.search(".*Session opened on /tmp/.*", out)
6662

6763
def test_notes_existing(self, capsys):
68-
instance = commands.Commands()
69-
instance.cmd_open('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
64+
commands.Open().run('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
7065
Database().add_note(commands.__sessions__.current.file.sha256, 'Note test', 'This is the content')
71-
instance.cmd_notes('-l')
72-
instance.cmd_notes('-v', '1')
73-
instance.cmd_notes('-d', '1')
66+
commands.Notes().run('-l')
67+
commands.Notes().run('-v', '1')
68+
commands.Notes().run('-d', '1')
7469
out, err = capsys.readouterr()
7570
assert re.search(".*1 | Note test.*", out)
7671
assert re.search(".*This is the content.*", out)
7772

7873
def test_analysis(self, capsys):
79-
instance = commands.Commands()
80-
instance.cmd_open('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
81-
instance.cmd_analysis('-h')
82-
instance.cmd_analysis('-l')
83-
instance.cmd_analysis('-v', '1')
74+
commands.Open().run('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
75+
commands.Analysis().run('-h')
76+
commands.Analysis().run('-l')
77+
commands.Analysis().run('-v', '1')
8478
out, err = capsys.readouterr()
8579
assert re.search("usage: analysis \[-h\] .*", out)
8680
assert re.search(".*Saved On.*", out)
8781
assert re.search(".*Cmd Line.*", out)
8882

8983
def test_store(self, capsys):
90-
instance = commands.Commands()
91-
instance.cmd_store('-h')
84+
commands.Store().run('-h')
9285
out, err = capsys.readouterr()
9386
assert re.search("usage: store \[-h\] .*", out)
9487

9588
def test_delete(self, capsys):
96-
instance = commands.Commands()
97-
instance.cmd_delete('-h')
89+
commands.Delete().run('-h')
9890
out, err = capsys.readouterr()
9991
assert re.search("usage: delete \[-h\] .*", out)
10092

10193
def test_find(self, capsys):
102-
instance = commands.Commands()
103-
instance.cmd_find('-h')
94+
commands.Find().run('-h')
10495
out, err = capsys.readouterr()
10596
assert re.search("usage: find \[-h\] .*", out)
10697

98+
commands.Find().run('all')
99+
out, err = capsys.readouterr()
100+
assert re.search(".*chromeinstall-8u31.exe.*", out)
101+
107102
def test_tags(self, capsys):
108-
instance = commands.Commands()
109-
instance.cmd_tags('-h')
103+
commands.Tags().run('-h')
110104
out, err = capsys.readouterr()
111105
assert re.search("usage: tags \[-h\] .*", out)
112106

113107
def test_tags_use(self, capsys):
114-
instance = commands.Commands()
115-
instance.cmd_open('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
116-
instance.cmd_tags('-a', 'mytag')
117-
instance.cmd_tags('-d', 'mytag')
108+
commands.Open().run('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
109+
commands.Tags().run('-a', 'mytag')
110+
commands.Tags().run('-d', 'mytag')
118111
out, err = capsys.readouterr()
119112
lines = out.split('\n')
120113
assert re.search(".*Tags added to the currently opened file.*", lines[1])
121114
assert re.search(".*Refreshing session to update attributes....*", lines[2])
122115

123116
def test_sessions(self, capsys):
124-
instance = commands.Commands()
125-
instance.cmd_sessions('-h')
126-
instance.cmd_sessions('-l')
117+
commands.Sessions().run('-h')
127118
out, err = capsys.readouterr()
128119
assert re.search("usage: sessions \[-h\] .*", out)
129-
assert re.search(".*6af69bf32d84229ff9a8904ab8ed28d7.*", out)
120+
121+
commands.Sessions().run('-l')
122+
out, err = capsys.readouterr()
123+
assert re.search(".*Opened Sessions.*", out)
130124

131125
def test_projects(self, capsys):
132-
instance = commands.Commands()
133-
instance.cmd_projects('-h')
126+
commands.Projects().run('-h')
134127
out, err = capsys.readouterr()
135128
assert re.search("usage: projects \[-h\] .*", out)
136129

137130
p = Project()
138131
p.open("project_switch_test1")
139132

140-
instance.cmd_projects('-l')
133+
commands.Projects().run('-l')
141134
out, err = capsys.readouterr()
142135
assert re.search(".*Projects Available.*", out)
143136
assert re.search(".*project_switch_test1.*", out)
144137
assert not re.search(".*not_there.*", out)
145138

146-
instance.cmd_projects('-s', 'project_switch_test1')
139+
commands.Projects().run('-s', 'project_switch_test1')
147140
out, err = capsys.readouterr()
148141
lines = out.split('\n')
149142
assert re.search(".*Switched to project.*", lines[0])
@@ -152,96 +145,89 @@ def test_projects(self, capsys):
152145
p.open("default")
153146

154147
def test_export(self, capsys):
155-
instance = commands.Commands()
156-
instance.cmd_export('-h')
148+
commands.Export().run('-h')
157149
out, err = capsys.readouterr()
158150
assert re.search("usage: export \[-h\] .*", out)
159151

160152
def test_stats(self, capsys):
161-
instance = commands.Commands()
162-
instance.cmd_stats('-h')
153+
commands.Stats().run('-h')
163154
out, err = capsys.readouterr()
164155
assert re.search("usage: stats \[-h\] .*", out)
165156

166157
def test_parent(self, capsys):
167-
instance = commands.Commands()
168-
instance.cmd_parent('-h')
158+
commands.Parent().run('-h')
169159
out, err = capsys.readouterr()
170160
assert re.search("usage: parent \[-h\] .*", out)
171161

172162
def test_rename(self, capsys):
173-
instance = commands.Commands()
174-
175-
instance.cmd_find("all")
163+
commands.Find().run("all")
176164
out, err = capsys.readouterr()
177165
assert out == ""
178166

179-
instance.cmd_open('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
180-
instance.cmd_store()
167+
commands.Open().run('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
168+
commands.Store().run()
181169
_, _ = capsys.readouterr()
182170

183171
if sys.version_info <= (3, 0):
184172
in_fct = 'viper.core.ui.commands.input'
185173
else:
186174
in_fct = 'builtins.input'
187175
with mock.patch(in_fct, return_value='chromeinstall-8u31.exe.new'):
188-
instance.cmd_rename()
176+
commands.Rename().run()
189177
out, err = capsys.readouterr()
190178
lines = out.split('\n')
191179
assert re.search(r".*Current name is.*1mchromeinstall-8u31.exe.*", lines[0])
192180
assert re.search(r".*Refreshing session to update attributes.*", lines[1])
193181

194182
def test_copy(self, capsys):
195-
instance = commands.Commands()
196-
197-
instance.cmd_projects('-s', 'copy_test_dst')
183+
commands.Projects().run('-s', 'copy_test_dst')
198184
out, err = capsys.readouterr()
199185
lines = out.split('\n')
200186
assert re.search(r".*Switched to project.*", lines[0])
201187

202-
instance.cmd_find('all')
188+
commands.Find().run('all')
203189
out, err = capsys.readouterr()
204190
assert out == ""
205191

206-
instance.cmd_projects('-s', 'copy_test_src')
192+
commands.Projects().run('-s', 'copy_test_src')
207193
out, err = capsys.readouterr()
208194
lines = out.split('\n')
209195
assert re.search(r".*Switched to project.*", lines[0])
210196

211-
instance.cmd_find('all')
197+
commands.Find().run('all')
212198
out, err = capsys.readouterr()
213199
assert out == ""
214200

215-
instance.cmd_open('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
216-
instance.cmd_store()
201+
commands.Open().run('-f', os.path.join(FIXTURE_DIR, "chromeinstall-8u31.exe"))
202+
commands.Store().run()
217203
out, err = capsys.readouterr()
218204
lines = out.split('\n')
219205
assert re.search(r".*Session opened on.*", lines[0])
220206
assert re.search(r".*Stored file.*", lines[1])
221207

222-
instance.cmd_find('all')
208+
commands.Find().run('all')
223209
out, err = capsys.readouterr()
224210
assert re.search(r".*\| 1 \| chromeinstall-8u31.exe.*", out)
225211
assert not re.search(r".*\| 2 \|.*", out)
226212

227-
instance.cmd_copy('-d', 'copy_test_dst')
213+
commands.Copy().run('-d', 'copy_test_dst')
228214
out, err = capsys.readouterr()
229215
lines = out.split('\n')
230216
assert re.search(r".*Copied:.*", lines[0])
231217
assert re.search(r".*Deleted:.*", lines[1])
232218
assert re.search(r".*Successfully copied sample.*", lines[2])
233219

234-
instance.cmd_find('all')
220+
commands.Find().run('all')
235221
out, err = capsys.readouterr()
236222
assert out == ""
237223
assert not re.search(r".*\| 1 \| chromeinstall-8u31.exe.*", out)
238224
assert not re.search(r".*\| 2 \|.*", out)
239225

240-
instance.cmd_projects('-s', 'copy_test_dst')
226+
commands.Projects().run('-s', 'copy_test_dst')
241227
out, err = capsys.readouterr()
242228
assert re.search(r".*Switched to project.*", out)
243229

244-
instance.cmd_find('all')
230+
commands.Find().run('all')
245231
out, err = capsys.readouterr()
246232
assert re.search(r".*\| 1 \| chromeinstall-8u31.exe.*", out)
247233
assert not re.search(r".*\| 2 \|.*", out)

0 commit comments

Comments
 (0)