2011-12-05 02:50:08 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
test_description="python bindings"
|
2017-09-25 22:38:19 +02:00
|
|
|
. $(dirname "$0")/test-lib.sh || exit 1
|
2011-12-05 02:50:08 +01:00
|
|
|
|
2015-08-02 08:40:55 +02:00
|
|
|
test_require_external_prereq ${NOTMUCH_PYTHON}
|
|
|
|
|
2011-12-05 02:50:08 +01:00
|
|
|
add_email_corpus
|
|
|
|
|
|
|
|
test_begin_subtest "compare thread ids"
|
2011-12-07 10:46:17 +01:00
|
|
|
test_python <<EOF
|
2011-12-05 02:50:08 +01:00
|
|
|
import notmuch
|
2012-01-02 15:51:26 +01:00
|
|
|
db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
|
2011-12-05 02:50:08 +01:00
|
|
|
q_new = notmuch.Query(db, 'tag:inbox')
|
2012-01-02 15:51:26 +01:00
|
|
|
q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
|
2011-12-05 02:50:08 +01:00
|
|
|
for t in q_new.search_threads():
|
2015-05-23 22:28:44 +02:00
|
|
|
print (t.get_thread_id())
|
2011-12-05 02:50:08 +01:00
|
|
|
EOF
|
2012-01-02 15:51:26 +01:00
|
|
|
notmuch search --sort=oldest-first --output=threads tag:inbox | sed s/^thread:// > EXPECTED
|
2017-04-05 02:36:29 +02:00
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
2012-01-02 15:51:27 +01:00
|
|
|
|
|
|
|
test_begin_subtest "compare message ids"
|
|
|
|
test_python <<EOF
|
|
|
|
import notmuch
|
|
|
|
db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
|
|
|
|
q_new = notmuch.Query(db, 'tag:inbox')
|
|
|
|
q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
|
|
|
|
for m in q_new.search_messages():
|
2015-05-23 22:28:44 +02:00
|
|
|
print (m.get_message_id())
|
2012-01-02 15:51:27 +01:00
|
|
|
EOF
|
|
|
|
notmuch search --sort=oldest-first --output=messages tag:inbox | sed s/^id:// > EXPECTED
|
2017-04-05 02:36:29 +02:00
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
2012-01-02 15:51:27 +01:00
|
|
|
|
2012-05-18 06:13:41 +02:00
|
|
|
test_begin_subtest "get non-existent file"
|
|
|
|
test_python <<EOF
|
|
|
|
import notmuch
|
|
|
|
db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
|
2015-05-23 22:28:44 +02:00
|
|
|
print (db.find_message_by_filename("i-dont-exist"))
|
2012-05-18 06:13:41 +02:00
|
|
|
EOF
|
|
|
|
test_expect_equal "$(cat OUTPUT)" "None"
|
|
|
|
|
2017-03-09 14:32:28 +01:00
|
|
|
test_begin_subtest "get revision"
|
|
|
|
test_python ${MAIL_DIR} <<'EOF'
|
|
|
|
import notmuch
|
|
|
|
db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
|
|
|
|
(revision, uuid) = db.get_revision()
|
|
|
|
print ("%s\t%lu" % (uuid, revision))
|
|
|
|
EOF
|
|
|
|
notmuch_uuid_sanitize < OUTPUT > CLEAN
|
|
|
|
cat <<'EOF' >EXPECTED
|
|
|
|
UUID 53
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED CLEAN
|
|
|
|
|
|
|
|
grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT
|
|
|
|
|
|
|
|
test_begin_subtest "output of count matches test code"
|
|
|
|
notmuch count --lastmod '*' | cut -f2-3 > OUTPUT
|
|
|
|
test_expect_equal_file INITIAL_OUTPUT OUTPUT
|
2017-09-24 14:36:12 +02:00
|
|
|
add_message '[content-type]="text/plain; charset=iso-8859-2"' \
|
|
|
|
'[content-transfer-encoding]=8bit' \
|
|
|
|
'[subject]="ISO-8859-2 encoded message"' \
|
|
|
|
"[body]=$'Czech word tu\350\362\341\350\350\355 means pinguin\'s.'" # ISO-8859-2 characters are generated by shell's escape sequences
|
|
|
|
test_begin_subtest "Add ISO-8859-2 encoded message, call get_message_parts"
|
|
|
|
test_python <<EOF
|
|
|
|
import notmuch
|
|
|
|
db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
|
|
|
|
q_new = notmuch.Query(db, 'ISO-8859-2 encoded message')
|
|
|
|
for m in q_new.search_messages():
|
|
|
|
for mp in m.get_message_parts():
|
|
|
|
continue
|
|
|
|
print(m.get_message_id())
|
|
|
|
EOF
|
|
|
|
|
|
|
|
notmuch search --sort=oldest-first --output=messages "tučňáččí" | sed s/^id:// > EXPECTED
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
2017-03-09 14:32:28 +01:00
|
|
|
|
2017-12-07 12:40:49 +01:00
|
|
|
# TODO currently these tests for setting and getting config values are
|
|
|
|
# somewhat interdependent. This is because the config values stored in the
|
|
|
|
# database are not cleaned up after each test, so they remain there for the
|
|
|
|
# next test. The ./README file states that this can happen so it seems kind
|
|
|
|
# of ok.
|
|
|
|
|
|
|
|
test_begin_subtest "set and get config values"
|
|
|
|
test_python <<'EOF'
|
|
|
|
import notmuch
|
|
|
|
db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
|
|
|
|
db.set_config('testkey1', 'testvalue1')
|
|
|
|
db.set_config('testkey2', 'testvalue2')
|
|
|
|
v1 = db.get_config('testkey1')
|
|
|
|
v2 = db.get_config('testkey2')
|
|
|
|
print('testkey1 = ' + v1)
|
|
|
|
print('testkey2 = ' + v2)
|
|
|
|
EOF
|
|
|
|
cat <<'EOF' >EXPECTED
|
|
|
|
testkey1 = testvalue1
|
|
|
|
testkey2 = testvalue2
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
2017-12-07 12:40:50 +01:00
|
|
|
test_begin_subtest "get_configs with no match returns empty generator"
|
2017-12-07 12:40:49 +01:00
|
|
|
test_python <<'EOF'
|
|
|
|
import notmuch
|
|
|
|
db = notmuch.Database()
|
2017-12-07 12:40:50 +01:00
|
|
|
v = db.get_configs('nonexistent')
|
2017-12-07 12:40:49 +01:00
|
|
|
print(list(v) == [])
|
|
|
|
EOF
|
|
|
|
test_expect_equal "$(cat OUTPUT)" "True"
|
|
|
|
|
2017-12-07 12:40:50 +01:00
|
|
|
test_begin_subtest "get_configs with no arguments returns all pairs"
|
2017-12-07 12:40:49 +01:00
|
|
|
test_python <<'EOF'
|
|
|
|
import notmuch
|
|
|
|
db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
|
|
|
|
db.set_config("zzzafter", "afterval")
|
|
|
|
db.set_config("aaabefore", "beforeval")
|
2017-12-07 12:40:50 +01:00
|
|
|
v = db.get_configs()
|
2017-12-07 12:40:49 +01:00
|
|
|
for index, keyval in enumerate(v):
|
|
|
|
key, val = keyval
|
|
|
|
print('{}: {} => {}'.format(index, key, val))
|
|
|
|
EOF
|
|
|
|
cat <<'EOF' >EXPECTED
|
|
|
|
0: aaabefore => beforeval
|
|
|
|
1: testkey1 => testvalue1
|
|
|
|
2: testkey2 => testvalue2
|
|
|
|
3: zzzafter => afterval
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
2017-12-07 12:40:50 +01:00
|
|
|
test_begin_subtest "get_configs prefix is used to match keys"
|
2017-12-07 12:40:49 +01:00
|
|
|
test_python <<'EOF'
|
|
|
|
import notmuch
|
|
|
|
db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
|
|
|
|
db.set_config('testkey1', 'testvalue1')
|
|
|
|
db.set_config('testkey2', 'testvalue2')
|
2017-12-07 12:40:50 +01:00
|
|
|
v = db.get_configs('testkey')
|
2017-12-07 12:40:49 +01:00
|
|
|
for index, keyval in enumerate(v):
|
|
|
|
key, val = keyval
|
|
|
|
print('{}: {} => {}'.format(index, key, val))
|
|
|
|
EOF
|
|
|
|
cat <<'EOF' >EXPECTED
|
|
|
|
0: testkey1 => testvalue1
|
|
|
|
1: testkey2 => testvalue2
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
2011-12-05 02:50:08 +01:00
|
|
|
test_done
|