File: test_uids.py

package info (click to toggle)
gnome-keysign 1.3.0-5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,460 kB
  • sloc: python: 5,143; xml: 126; makefile: 33; sh: 16
file content (43 lines) | stat: -rw-r--r-- 1,100 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python
"""We want our custom UID wrapper to return encodable and displayable
strings, rather than raw bytes, for the raw UID, email, name,
and comment component.
"""
from __future__ import unicode_literals

from keysign import gpgkey

def is_string(s):
    return type(s) == type("string")

def is_bytes(s):
    return type(s) == type(b"bytes")

def assert_string(s):
    assert is_string(s), "Expected String, but got %s (%r)" % (type(s), s)

def assert_bytes(s):
    assert is_bytes(s), "Expected Bytes, but got %s (%r)" % (type(s), s)

class FakeMKSUID:
    uid = b''
    expire = 0

def test_mks_utf8_uid():
    "The normal case"
    uid = FakeMKSUID()
    uid.uid = 'foo bar <foo@bar.com>'
    u = gpgkey.UID.from_monkeysign(uid)
    assert_string(u.name)
    assert_string(u.comment)
    assert_string(u.email)
    assert_string(u.uid)

def test_mks_latin_uid():
    uid = FakeMKSUID()
    uid.uid = 'fo\udcf6e\udce9ba <foo@bma.d>'
    u = gpgkey.UID.from_monkeysign(uid)
    assert_string(u.name)
    assert_string(u.comment)
    assert_string(u.email)
    assert_string(u.uid)