2 test_description="python bindings"
3 . $(dirname "$0")/test-lib.sh || exit 1
5 test_require_external_prereq ${NOTMUCH_PYTHON}
10 test_begin_subtest "compare thread ids"
13 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
14 q_new = notmuch.Query(db, 'tag:inbox')
15 q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
16 for t in q_new.search_threads():
17 print (t.get_thread_id())
19 notmuch search --sort=oldest-first --output=threads tag:inbox | sed s/^thread:// > EXPECTED
20 test_expect_equal_file EXPECTED OUTPUT
22 test_begin_subtest "compare message ids"
25 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
26 q_new = notmuch.Query(db, 'tag:inbox')
27 q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
28 for m in q_new.search_messages():
29 print (m.get_message_id())
31 notmuch search --sort=oldest-first --output=messages tag:inbox | sed s/^id:// > EXPECTED
32 test_expect_equal_file EXPECTED OUTPUT
34 test_begin_subtest "get non-existent file"
37 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
38 print (db.find_message_by_filename("i-dont-exist"))
40 test_expect_equal "$(cat OUTPUT)" "None"
42 test_begin_subtest "get revision"
43 test_python ${MAIL_DIR} <<'EOF'
45 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
46 (revision, uuid) = db.get_revision()
47 print ("%s\t%lu" % (uuid, revision))
49 notmuch_uuid_sanitize < OUTPUT > CLEAN
53 test_expect_equal_file EXPECTED CLEAN
55 grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT
57 test_begin_subtest "output of count matches test code"
58 notmuch count --lastmod '*' | cut -f2-3 > OUTPUT
59 test_expect_equal_file INITIAL_OUTPUT OUTPUT
60 add_message '[content-type]="text/plain; charset=iso-8859-2"' \
61 '[content-transfer-encoding]=8bit' \
62 '[subject]="ISO-8859-2 encoded message"' \
63 "[body]=$'Czech word tu\350\362\341\350\350\355 means pinguin\'s.'" # ISO-8859-2 characters are generated by shell's escape sequences
64 test_begin_subtest "Add ISO-8859-2 encoded message, call get_message_parts"
67 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
68 q_new = notmuch.Query(db, 'ISO-8859-2 encoded message')
69 for m in q_new.search_messages():
70 for mp in m.get_message_parts():
72 print(m.get_message_id())
75 notmuch search --sort=oldest-first --output=messages "tučňáččí" | sed s/^id:// > EXPECTED
76 test_expect_equal_file EXPECTED OUTPUT
78 # TODO currently these tests for setting and getting config values are
79 # somewhat interdependent. This is because the config values stored in the
80 # database are not cleaned up after each test, so they remain there for the
81 # next test. The ./README file states that this can happen so it seems kind
84 test_begin_subtest "set and get config values"
87 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
88 db.set_config('testkey1', 'testvalue1')
89 db.set_config('testkey2', 'testvalue2')
90 v1 = db.get_config('testkey1')
91 v2 = db.get_config('testkey2')
92 print('testkey1 = ' + v1)
93 print('testkey2 = ' + v2)
99 test_expect_equal_file EXPECTED OUTPUT
101 test_begin_subtest "get_configs with no match returns empty generator"
104 db = notmuch.Database()
105 v = db.get_configs('nonexistent')
108 test_expect_equal "$(cat OUTPUT)" "True"
110 test_begin_subtest "get_configs with no arguments returns all pairs"
113 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
114 db.set_config("zzzafter", "afterval")
115 db.set_config("aaabefore", "beforeval")
117 for index, keyval in enumerate(v):
119 print('{}: {} => {}'.format(index, key, val))
121 cat <<'EOF' >EXPECTED
122 0: aaabefore => beforeval
123 1: testkey1 => testvalue1
124 2: testkey2 => testvalue2
125 3: zzzafter => afterval
127 test_expect_equal_file EXPECTED OUTPUT
129 test_begin_subtest "get_configs prefix is used to match keys"
132 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
133 db.set_config('testkey1', 'testvalue1')
134 db.set_config('testkey2', 'testvalue2')
135 v = db.get_configs('testkey')
136 for index, keyval in enumerate(v):
138 print('{}: {} => {}'.format(index, key, val))
140 cat <<'EOF' >EXPECTED
141 0: testkey1 => testvalue1
142 1: testkey2 => testvalue2
144 test_expect_equal_file EXPECTED OUTPUT
146 test_begin_subtest "set_config with no value will unset config entries"
149 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
150 db.set_config('testkey1', '')
151 db.set_config('testkey2', '')
152 db.set_config("zzzafter", '')
153 db.set_config("aaabefore", '')
157 test_expect_equal "$(cat OUTPUT)" "True"
159 mkdir -p "${MAIL_DIR}/cur"
160 fname="${MAIL_DIR}/cur/simplemsg.eml"
162 From: test_suite@notmuchmail.org
163 To: test_suite@notmuchmail.org
164 Subject: encrypted message
165 Date: Sat, 01 Jan 2000 12:00:00 +0000
166 Message-ID: <simplemsg@crypto.notmuchmail.org>
168 Content-Type: multipart/encrypted; boundary="=-=-=";
169 protocol="application/pgp-encrypted"
172 Content-Type: application/pgp-encrypted
177 Content-Type: application/octet-stream
179 $(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)
183 test_begin_subtest "index message with decryption"
186 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
187 (m, status) = db.index_file('$fname', decrypt_policy=notmuch.Database.DECRYPTION_POLICY.TRUE)
188 if status == notmuch.errors.STATUS.DUPLICATE_MESSAGE_ID:
189 print("got duplicate message")
190 q_new = notmuch.Query(db, 'sekrit')
191 for m in q_new.search_messages():
192 print(m.get_filename())
194 echo "$fname" > EXPECTED
195 test_expect_equal_file EXPECTED OUTPUT