2 test_description="python bindings"
3 . $(dirname "$0")/test-lib.sh || exit 1
5 test_require_external_prereq ${NOTMUCH_PYTHON}
7 if [ -n "${NOTMUCH_TEST_INSTALLED-}" ]; then
14 test_begin_subtest "compare thread ids"
17 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
18 q_new = notmuch.Query(db, 'tag:inbox')
19 q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
20 for t in q_new.search_threads():
21 print (t.get_thread_id())
23 notmuch search --sort=oldest-first --output=threads tag:inbox | sed s/^thread:// > EXPECTED
24 test_expect_equal_file EXPECTED OUTPUT
26 test_begin_subtest "compare message ids"
29 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
30 q_new = notmuch.Query(db, 'tag:inbox')
31 q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
32 for m in q_new.search_messages():
33 print (m.get_message_id())
35 notmuch search --sort=oldest-first --output=messages tag:inbox | sed s/^id:// > EXPECTED
36 test_expect_equal_file EXPECTED OUTPUT
38 test_begin_subtest "get non-existent file"
41 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
42 print (db.find_message_by_filename("i-dont-exist"))
44 test_expect_equal "$(cat OUTPUT)" "None"
46 test_begin_subtest "get revision"
47 test_python ${MAIL_DIR} <<'EOF'
49 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
50 (revision, uuid) = db.get_revision()
51 print ("%s\t%lu" % (uuid, revision))
53 notmuch_uuid_sanitize < OUTPUT > CLEAN
57 test_expect_equal_file EXPECTED CLEAN
59 grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT
61 test_begin_subtest "output of count matches test code"
62 notmuch count --lastmod '*' | cut -f2-3 > OUTPUT
63 test_expect_equal_file INITIAL_OUTPUT OUTPUT
64 add_message '[content-type]="text/plain; charset=iso-8859-2"' \
65 '[content-transfer-encoding]=8bit' \
66 '[subject]="ISO-8859-2 encoded message"' \
67 "[body]=$'Czech word tu\350\362\341\350\350\355 means pinguin\'s.'" # ISO-8859-2 characters are generated by shell's escape sequences
68 test_begin_subtest "Add ISO-8859-2 encoded message, call get_message_parts"
71 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
72 q_new = notmuch.Query(db, 'ISO-8859-2 encoded message')
73 for m in q_new.search_messages():
74 for mp in m.get_message_parts():
76 print(m.get_message_id())
79 notmuch search --sort=oldest-first --output=messages "tučňáččí" | sed s/^id:// > EXPECTED
80 test_expect_equal_file EXPECTED OUTPUT
82 # TODO currently these tests for setting and getting config values are
83 # somewhat interdependent. This is because the config values stored in the
84 # database are not cleaned up after each test, so they remain there for the
85 # next test. The ./README file states that this can happen so it seems kind
88 test_begin_subtest "set and get config values"
91 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
92 db.set_config('testkey1', 'testvalue1')
93 db.set_config('testkey2', 'testvalue2')
94 v1 = db.get_config('testkey1')
95 v2 = db.get_config('testkey2')
96 print('testkey1 = ' + v1)
97 print('testkey2 = ' + v2)
100 testkey1 = testvalue1
101 testkey2 = testvalue2
103 test_expect_equal_file EXPECTED OUTPUT
105 test_begin_subtest "get_configs with no match returns empty generator"
108 db = notmuch.Database()
109 v = db.get_configs('nonexistent')
112 test_expect_equal "$(cat OUTPUT)" "True"
114 test_begin_subtest "get_configs with no arguments returns all pairs"
117 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
118 db.set_config("zzzafter", "afterval")
119 db.set_config("aaabefore", "beforeval")
121 for index, keyval in enumerate(v):
123 print('{}: {} => {}'.format(index, key, val))
125 cat <<'EOF' >EXPECTED
126 0: aaabefore => beforeval
127 1: testkey1 => testvalue1
128 2: testkey2 => testvalue2
129 3: zzzafter => afterval
131 test_expect_equal_file EXPECTED OUTPUT
133 test_begin_subtest "get_configs prefix is used to match keys"
136 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
137 db.set_config('testkey1', 'testvalue1')
138 db.set_config('testkey2', 'testvalue2')
139 v = db.get_configs('testkey')
140 for index, keyval in enumerate(v):
142 print('{}: {} => {}'.format(index, key, val))
144 cat <<'EOF' >EXPECTED
145 0: testkey1 => testvalue1
146 1: testkey2 => testvalue2
148 test_expect_equal_file EXPECTED OUTPUT
150 test_begin_subtest "set_config with no value will unset config entries"
153 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
154 db.set_config('testkey1', '')
155 db.set_config('testkey2', '')
156 db.set_config("zzzafter", '')
157 db.set_config("aaabefore", '')
161 test_expect_equal "$(cat OUTPUT)" "True"
163 mkdir -p "${MAIL_DIR}/cur"
164 fname="${MAIL_DIR}/cur/simplemsg.eml"
166 From: test_suite@notmuchmail.org
167 To: test_suite@notmuchmail.org
168 Subject: encrypted message
169 Date: Sat, 01 Jan 2000 12:00:00 +0000
170 Message-ID: <simplemsg@crypto.notmuchmail.org>
172 Content-Type: multipart/encrypted; boundary="=-=-=";
173 protocol="application/pgp-encrypted"
176 Content-Type: application/pgp-encrypted
181 Content-Type: application/octet-stream
183 $(printf 'Content-Type: text/plain\n\nThis is the sekrit message\n' | gpg --no-tty --batch --quiet --trust-model=always --encrypt --armor --recipient test_suite@notmuchmail.org)
187 test_begin_subtest "index message with decryption"
190 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
191 (m, status) = db.index_file('$fname', decrypt_policy=notmuch.Database.DECRYPTION_POLICY.TRUE)
192 if status == notmuch.errors.STATUS.DUPLICATE_MESSAGE_ID:
193 print("got duplicate message")
194 q_new = notmuch.Query(db, 'sekrit')
195 for m in q_new.search_messages():
196 print(m.get_filename())
198 echo "$fname" > EXPECTED
199 test_expect_equal_file EXPECTED OUTPUT