]> git.notmuchmail.org Git - notmuch/blob - test/T390-python.sh
python: Rename get_config_list to get_configs
[notmuch] / test / T390-python.sh
1 #!/usr/bin/env bash
2 test_description="python bindings"
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 test_require_external_prereq ${NOTMUCH_PYTHON}
6
7 add_email_corpus
8
9 test_begin_subtest "compare thread ids"
10 test_python <<EOF
11 import notmuch
12 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
13 q_new = notmuch.Query(db, 'tag:inbox')
14 q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
15 for t in q_new.search_threads():
16     print (t.get_thread_id())
17 EOF
18 notmuch search --sort=oldest-first --output=threads tag:inbox | sed s/^thread:// > EXPECTED
19 test_expect_equal_file EXPECTED OUTPUT
20
21 test_begin_subtest "compare message ids"
22 test_python <<EOF
23 import notmuch
24 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
25 q_new = notmuch.Query(db, 'tag:inbox')
26 q_new.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
27 for m in q_new.search_messages():
28     print (m.get_message_id())
29 EOF
30 notmuch search --sort=oldest-first --output=messages tag:inbox | sed s/^id:// > EXPECTED
31 test_expect_equal_file EXPECTED OUTPUT
32
33 test_begin_subtest "get non-existent file"
34 test_python <<EOF
35 import notmuch
36 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
37 print (db.find_message_by_filename("i-dont-exist"))
38 EOF
39 test_expect_equal "$(cat OUTPUT)" "None"
40
41 test_begin_subtest "get revision"
42 test_python ${MAIL_DIR} <<'EOF'
43 import notmuch
44 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
45 (revision, uuid) = db.get_revision()
46 print ("%s\t%lu" % (uuid, revision))
47 EOF
48 notmuch_uuid_sanitize < OUTPUT > CLEAN
49 cat <<'EOF' >EXPECTED
50 UUID    53
51 EOF
52 test_expect_equal_file EXPECTED CLEAN
53
54 grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT
55
56 test_begin_subtest "output of count matches test code"
57 notmuch count --lastmod '*' | cut -f2-3 > OUTPUT
58 test_expect_equal_file INITIAL_OUTPUT OUTPUT
59 add_message '[content-type]="text/plain; charset=iso-8859-2"' \
60             '[content-transfer-encoding]=8bit' \
61             '[subject]="ISO-8859-2 encoded message"' \
62             "[body]=$'Czech word tu\350\362\341\350\350\355 means pinguin\'s.'" # ISO-8859-2 characters are generated by shell's escape sequences
63 test_begin_subtest "Add ISO-8859-2 encoded message, call get_message_parts"
64 test_python <<EOF
65 import notmuch
66 db = notmuch.Database(mode=notmuch.Database.MODE.READ_ONLY)
67 q_new = notmuch.Query(db, 'ISO-8859-2 encoded message')
68 for m in q_new.search_messages():
69     for mp in m.get_message_parts():
70       continue
71     print(m.get_message_id())
72 EOF
73
74 notmuch search --sort=oldest-first --output=messages "tučňáččí" | sed s/^id:// > EXPECTED
75 test_expect_equal_file EXPECTED OUTPUT
76
77 # TODO currently these tests for setting and getting config values are
78 # somewhat interdependent.  This is because the config values stored in the
79 # database are not cleaned up after each test, so they remain there for the
80 # next test.  The ./README file states that this can happen so it seems kind
81 # of ok.
82
83 test_begin_subtest "set and get config values"
84 test_python <<'EOF'
85 import notmuch
86 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
87 db.set_config('testkey1', 'testvalue1')
88 db.set_config('testkey2', 'testvalue2')
89 v1 = db.get_config('testkey1')
90 v2 = db.get_config('testkey2')
91 print('testkey1 = ' + v1)
92 print('testkey2 = ' + v2)
93 EOF
94 cat <<'EOF' >EXPECTED
95 testkey1 = testvalue1
96 testkey2 = testvalue2
97 EOF
98 test_expect_equal_file EXPECTED OUTPUT
99
100 test_begin_subtest "get_configs with no match returns empty generator"
101 test_python <<'EOF'
102 import notmuch
103 db = notmuch.Database()
104 v = db.get_configs('nonexistent')
105 print(list(v) == [])
106 EOF
107 test_expect_equal "$(cat OUTPUT)" "True"
108
109 test_begin_subtest "get_configs with no arguments returns all pairs"
110 test_python <<'EOF'
111 import notmuch
112 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
113 db.set_config("zzzafter", "afterval")
114 db.set_config("aaabefore", "beforeval")
115 v = db.get_configs()
116 for index, keyval in enumerate(v):
117     key, val = keyval
118     print('{}: {} => {}'.format(index, key, val))
119 EOF
120 cat <<'EOF' >EXPECTED
121 0: aaabefore => beforeval
122 1: testkey1 => testvalue1
123 2: testkey2 => testvalue2
124 3: zzzafter => afterval
125 EOF
126 test_expect_equal_file EXPECTED OUTPUT
127
128 test_begin_subtest "get_configs prefix is used to match keys"
129 test_python <<'EOF'
130 import notmuch
131 db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
132 db.set_config('testkey1', 'testvalue1')
133 db.set_config('testkey2', 'testvalue2')
134 v = db.get_configs('testkey')
135 for index, keyval in enumerate(v):
136     key, val = keyval
137     print('{}: {} => {}'.format(index, key, val))
138 EOF
139 cat <<'EOF' >EXPECTED
140 0: testkey1 => testvalue1
141 1: testkey2 => testvalue2
142 EOF
143 test_expect_equal_file EXPECTED OUTPUT
144
145 test_done