Skip to content

Commit

Permalink
Fixing tests, crypto policy issue #383, _do_search interface
Browse files Browse the repository at this point in the history
  • Loading branch information
BjarniRunar committed Oct 25, 2014
1 parent a90dfa3 commit e1efa08
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
18 changes: 9 additions & 9 deletions mailpile/plugins/crypto_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def command(self):
if self._update_crypto_state(email):
updated.add(email)

return updated
return self._success(_('Discovered crypto policy'), result=updated)


class UpdateCryptoPolicyForUser(CryptoPolicyBaseAction):
Expand All @@ -114,17 +114,19 @@ def command(self):
vcard = self.session.config.vcards.get_vcard(email)
if vcard:
self._update_vcard(vcard, policy)
return {'email': email, 'policy:': policy}
return self._success(_('Set crypto policy for %s to %s'
) % (email, policy),
result={'email': email, 'policy:': policy})
else:
return self._error('No vcard for email %s!' % email)
return self._error(_('No vcard for email %s!') % email)

def _parse_args(self):
if self.data:
email = unicode(self.data['email'][0])
policy = unicode(self.data['policy'][0])
else:
if len(self.args) != 2:
return self._error('Please provide email address and policy!')
return self._error(_('Please provide email address and policy!'))

email = self.args[0]
policy = self.args[1]
Expand All @@ -142,12 +144,10 @@ def command(self):
return self._error('Please provide a single email address!')

email = self.args[0]
policy = self._vcard_policy(email) or self._find_policy(email)

policy_from_vcard = self._vcard_policy(email)
if policy_from_vcard:
return policy_from_vcard
else:
return self._find_policy(email)
return self._success(_('Crypto policy for %s is %s') % (email, policy),
result=policy)

def _vcard_policy(self, email):
vcard = self.session.config.vcards.get_vcard(email)
Expand Down
5 changes: 2 additions & 3 deletions mailpile/plugins/crypto_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,12 @@ def command(self):
if addr is None:
return self._error("Must supply an address", None)

session, idx, _, _ = self._do_search(search=["from:%s" % addr])
session, idx = self._do_search(search=["from:%s" % addr])
total = 0
for messageid in session.results:
total += 1

session, idx, _, _ = self._do_search(search=["from:%s" % addr,
"has:pgp"])
session, idx = self._do_search(search=["from:%s" % addr, "has:pgp"])
pgp = 0
for messageid in session.results:
pgp += 1
Expand Down
2 changes: 1 addition & 1 deletion mailpile/plugins/keylookup/email_keylookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _score(self, key):
def _lookup(self, address):
results = {}
terms = ['from:%s' % address, 'has:pgpkey']
session, idx, _, _ = self._do_search(search=terms)
session, idx = self._do_search(search=terms)
deadline = time.time() + (0.75 * self.TIMEOUT)
for messageid in session.results[:5]:
for key_data in self._get_keys(messageid):
Expand Down
7 changes: 4 additions & 3 deletions mailpile/plugins/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _do_search(self, search=None, process_args=False):
context=context).as_set())
idx.sort_results(session, session.results, session.order)

return session, idx, self._start, self._num
return session, idx

def cache_requirements(self, result):
msgs = self.session.results[self._start:self._start + self._num]
Expand All @@ -192,10 +192,11 @@ def fix_term(term):
return reqs

def command(self):
session, idx, start, num = self._do_search()
session, idx = self._do_search()
full_threads = self.data.get('full', False)
session.displayed = SearchResults(session, idx,
start=start, num=num,
start=self._start,
num=self._num,
full_threads=full_threads)
session.ui.mark(_('Prepared %d search results (context=%s)'
) % (len(session.results), self.context))
Expand Down
5 changes: 3 additions & 2 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ def test_help_urlmap_as_text(self):

def test_crypto_policy_auto_set_all_action(self):
res = self.mp.crypto_policy_auto_set_all()
self.assertEqual(res.as_dict()["message"], 'crypto_policy/auto_set_all')
self.assertEqual(res.as_dict()["message"], u'Discovered crypto policy')
self.assertEqual(set(), res.as_dict()['result'])

def test_crypto_policy_action(self):
res = self.mp.crypto_policy("foobar")
self.assertEqual(res.as_dict()["message"], 'crypto_policy')
self.assertEqual(res.as_dict()["message"], u'Crypto policy for foobar is none')
self.assertEqual(res.as_dict()["result"], 'none')


class TestCommandResult(MailPileUnittest):
Expand Down

0 comments on commit e1efa08

Please sign in to comment.