~ubuntu-branches/ubuntu/natty/pygpgme/natty

« back to all changes in this revision

Viewing changes to gpgme/tests/test_progress.py

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Di Ciurcio Filho
  • Date: 2009-07-16 19:30:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090716193000-3bdzvj2oh58z7h24
Tags: upstream-0.1+bzr20090429
ImportĀ upstreamĀ versionĀ 0.1+bzr20090429

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# pygpgme - a Python wrapper for the gpgme library
 
2
# Copyright (C) 2006  James Henstridge
 
3
#
 
4
# This library is free software; you can redistribute it and/or
 
5
# modify it under the terms of the GNU Lesser General Public
 
6
# License as published by the Free Software Foundation; either
 
7
# version 2.1 of the License, or (at your option) any later version.
 
8
#
 
9
# This library is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
# Lesser General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Lesser General Public
 
15
# License along with this library; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 
 
18
import unittest
 
19
import os
 
20
try:
 
21
    from io import BytesIO
 
22
except ImportError:
 
23
    from StringIO import StringIO as BytesIO
 
24
from textwrap import dedent
 
25
 
 
26
import gpgme
 
27
from gpgme.tests.util import GpgHomeTestCase
 
28
 
 
29
class ProgressTestCase(GpgHomeTestCase):
 
30
 
 
31
    import_keys = ['key1.pub', 'key1.sec']
 
32
 
 
33
    def progress_cb(self, what, type_, current, total):
 
34
        self.progress_cb_called = True
 
35
 
 
36
    def test_sign_with_progress_cb(self):
 
37
        ctx = gpgme.Context()
 
38
        key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')
 
39
        ctx.signers = [key]
 
40
        ctx.progress_cb = self.progress_cb
 
41
        plaintext = BytesIO('Hello World\n')
 
42
        signature = BytesIO()
 
43
 
 
44
        self.progress_cb_called = False
 
45
        new_sigs = ctx.sign(plaintext, signature, gpgme.SIG_MODE_CLEAR)
 
46
 
 
47
        # ensure that progress_cb has been run
 
48
        self.assertEqual(self.progress_cb_called, True)
 
49
 
 
50
        self.assertEqual(new_sigs[0].type, gpgme.SIG_MODE_CLEAR)
 
51
        self.assertEqual(new_sigs[0].fpr,
 
52
                        'E79A842DA34A1CA383F64A1546BB55F0885C65A4')
 
53
 
 
54
def test_suite():
 
55
    loader = unittest.TestLoader()
 
56
    return loader.loadTestsFromName(__name__)