/
test_events.py
657 lines (537 loc) · 29.4 KB
/
test_events.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
"""Tests for metabot.modules.events."""
from __future__ import absolute_import, division, print_function, unicode_literals
import pytest
from metabot.calendars import loader
from metabot.modules import events
from metabot.modules import moderator
@pytest.fixture
def conversation(build_conversation, monkeypatch): # pylint: disable=missing-docstring
monkeypatch.setattr('time.time', lambda: 2000.)
cal = loader.get('static:test_events')
assert cal.calcode == '6fc2c510'
cal.events = {
'6fc2c510:alpha': {
'description': 'Alpha Description',
'end': 2000,
'local_id': '6fc2c510:alpha',
'location': 'Alpha Venue, Rest of Alpha Location',
'start': 1000,
'summary': 'Alpha Summary',
},
'6fc2c510:bravo': {
'description': 'Bravo Description',
'end': 60 * 60 * 24 * 7 + 60 * 60,
'local_id': '6fc2c510:bravo',
'location': 'Bravo Venue, Rest of Bravo Location',
'start': 60 * 60 * 24 * 7,
'summary': 'Bravo Summary',
},
'6fc2c510:charlie': {
'description': 'Charlie Description',
'end': 60 * 60 * 24 * 7 + 1 + 60 * 60,
'local_id': '6fc2c510:charlie',
'location': 'Charlie Venue, Rest of Charlie Location',
'start': 60 * 60 * 24 * 7 + 1,
'summary': 'Charlie Summary',
},
}
conv = build_conversation(events, moderator)
conv.multibot.multical.add('static:test_events')
conv.multibot.calendars['6fc2c510'] = {'name': 'Test Calendar'}
return conv
# pylint: disable=line-too-long
def test_group(conversation, monkeypatch): # pylint: disable=redefined-outer-name
"""Test /events in a group chat."""
assert conversation.message('/notevents') == ''
assert conversation.message('/events', chat_type='supergroup') == """\
[chat_id=-1001000001000 disable_web_page_preview=True parse_mode=HTML reply_to_message_id=2000]
I'm not configured for this group! Ask a bot admin to go into the <b>moderator</b> module settings, group <b>-1001000001000</b>, and choose one or more calendars and set the time zone.
"""
assert conversation.message(
'/admin modulestestbot moderator -1001000001000 calendars add 6fc2c510') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a moderator \u203a -1001000001000 \u203a calendars: <b>Select a calendar</b>
Added <code>6fc2c510</code> to your calendar view.
Which calendars should be listed in /events?
Select a calendar to add or remove from the list below:
[Remove Test Calendar | /admin modulestestbot moderator -1001000001000 calendars remove 6fc2c510]
[Back | /admin modulestestbot moderator -1001000001000]
"""
assert conversation.message('/admin modulestestbot moderator -1001000001000 timezone') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a moderator \u203a -1001000001000 \u203a timezone: <b>Choose a time zone</b>
What time zone should be used in /events?
Choose a time zone:
[Africa | /admin modulestestbot moderator -1001000001000 timezone Africa]
[America | /admin modulestestbot moderator -1001000001000 timezone America]
[Antarctica | /admin modulestestbot moderator -1001000001000 timezone Antarctica]
[Arctic | /admin modulestestbot moderator -1001000001000 timezone Arctic]
[Asia | /admin modulestestbot moderator -1001000001000 timezone Asia]
[Atlantic | /admin modulestestbot moderator -1001000001000 timezone Atlantic]
[Australia | /admin modulestestbot moderator -1001000001000 timezone Australia]
[\xa0 | /stop] [Next | /admin modulestestbot moderator -1001000001000 timezone - 1]
[Back | /admin modulestestbot moderator -1001000001000]
"""
assert conversation.message(
'/admin modulestestbot moderator -1001000001000 timezone - 1') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a moderator \u203a -1001000001000 \u203a timezone: <b>Choose a time zone</b>
What time zone should be used in /events?
Choose a time zone:
[Canada | /admin modulestestbot moderator -1001000001000 timezone Canada]
[Europe | /admin modulestestbot moderator -1001000001000 timezone Europe]
[GMT | /admin modulestestbot moderator -1001000001000 timezone GMT]
[Indian | /admin modulestestbot moderator -1001000001000 timezone Indian]
[Pacific | /admin modulestestbot moderator -1001000001000 timezone Pacific]
[US | /admin modulestestbot moderator -1001000001000 timezone US]
[UTC | /admin modulestestbot moderator -1001000001000 timezone UTC]
[Prev | /admin modulestestbot moderator -1001000001000 timezone - 0] [\xa0 | /stop]
[Back | /admin modulestestbot moderator -1001000001000]
"""
assert conversation.message('/admin modulestestbot moderator -1001000001000 timezone',
language_code='en-us') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a moderator \u203a -1001000001000 \u203a timezone: <b>Choose a time zone</b>
What time zone should be used in /events?
Choose a time zone:
[US/Alaska | /admin modulestestbot moderator -1001000001000 timezone US/Alaska]
[US/Arizona | /admin modulestestbot moderator -1001000001000 timezone US/Arizona]
[US/Central | /admin modulestestbot moderator -1001000001000 timezone US/Central]
[US/Eastern | /admin modulestestbot moderator -1001000001000 timezone US/Eastern]
[US/Hawaii | /admin modulestestbot moderator -1001000001000 timezone US/Hawaii]
[US/Mountain | /admin modulestestbot moderator -1001000001000 timezone US/Mountain]
[US/Pacific | /admin modulestestbot moderator -1001000001000 timezone US/Pacific]
[Back | /admin modulestestbot moderator -1001000001000]
"""
assert conversation.message('/admin modulestestbot moderator -1001000001000 timezone',
language_code='en-ca') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a moderator \u203a -1001000001000 \u203a timezone: <b>Choose a time zone</b>
What time zone should be used in /events?
Choose a time zone:
[Canada/Atlantic | /admin modulestestbot moderator -1001000001000 timezone Canada/Atlantic]
[Canada/Central | /admin modulestestbot moderator -1001000001000 timezone Canada/Central]
[Canada/Eastern | /admin modulestestbot moderator -1001000001000 timezone Canada/Eastern]
[Canada/Mountain | /admin modulestestbot moderator -1001000001000 timezone Canada/Mountain]
[Canada/Newfoundland | /admin modulestestbot moderator -1001000001000 timezone Canada/Newfoundland]
[Canada/Pacific | /admin modulestestbot moderator -1001000001000 timezone Canada/Pacific]
[Back | /admin modulestestbot moderator -1001000001000]
"""
assert conversation.message('/admin modulestestbot moderator -1001000001000 timezone',
language_code='en-gb') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a moderator \u203a -1001000001000 \u203a timezone: <b>Choose a time zone</b>
What time zone should be used in /events?
Choose a time zone:
[Europe/London | /admin modulestestbot moderator -1001000001000 timezone Europe/London]
[Back | /admin modulestestbot moderator -1001000001000]
"""
assert conversation.message(
'/admin modulestestbot moderator -1001000001000 timezone America/Indiana') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a moderator \u203a -1001000001000 \u203a timezone: <b>Choose a time zone</b>
What time zone should be used in /events?
Choose a time zone:
[America/Indiana/Indianapolis | /admin modulestestbot moderator -1001000001000 timezone America/Indiana/Indianapolis]
[America/Indiana/Knox | /admin modulestestbot moderator -1001000001000 timezone America/Indiana/Knox]
[America/Indiana/Marengo | /admin modulestestbot moderator -1001000001000 timezone America/Indiana/Marengo]
[America/Indiana/Petersburg | /admin modulestestbot moderator -1001000001000 timezone America/Indiana/Petersburg]
[America/Indiana/Tell_City | /admin modulestestbot moderator -1001000001000 timezone America/Indiana/Tell_City]
[America/Indiana/Vevay | /admin modulestestbot moderator -1001000001000 timezone America/Indiana/Vevay]
[America/Indiana/Vincennes | /admin modulestestbot moderator -1001000001000 timezone America/Indiana/Vincennes]
[\xa0 | /stop] [Next | /admin modulestestbot moderator -1001000001000 timezone America/Indiana 1]
[Back | /admin modulestestbot moderator -1001000001000]
"""
assert conversation.message(
'/admin modulestestbot moderator -1001000001000 timezone America/Indiana 1') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a moderator \u203a -1001000001000 \u203a timezone: <b>Choose a time zone</b>
What time zone should be used in /events?
Choose a time zone:
[America/Indiana/Winamac | /admin modulestestbot moderator -1001000001000 timezone America/Indiana/Winamac]
[Prev | /admin modulestestbot moderator -1001000001000 timezone America/Indiana 0] [\xa0 | /stop]
[Back | /admin modulestestbot moderator -1001000001000]
"""
assert conversation.message(
'/admin modulestestbot moderator -1001000001000 timezone US/Pacific') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a moderator \u203a -1001000001000: <b>Choose a field</b>
Set timezone to <code>US/Pacific</code>.
[calendars (6fc2c510) \u2022 Which calendars should be listed in /events? | /admin modulestestbot moderator -1001000001000 calendars]
[daily \u2022 Should I announce upcoming events once a day? If so, at what hour? | /admin modulestestbot moderator -1001000001000 daily]
[dailytext \u2022 One or more messages (one per line) to use/cycle through for the daily announcement. | /admin modulestestbot moderator -1001000001000 dailytext]
[greeting \u2022 How should I greet people when they join? | /admin modulestestbot moderator -1001000001000 greeting]
[maxeventscount \u2022 How many events should be listed in /events? | /admin modulestestbot moderator -1001000001000 maxeventscount]
[maxeventsdays \u2022 How many days into the future should /events look? | /admin modulestestbot moderator -1001000001000 maxeventsdays]
[timezone (US/Pacific) \u2022 What time zone should be used in /events? | /admin modulestestbot moderator -1001000001000 timezone]
[Back | /admin modulestestbot moderator]
"""
assert conversation.message('/events', chat_type='supergroup') == """\
[chat_id=-1001000001000 disable_web_page_preview=True parse_mode=HTML reply_to_message_id=2000]
<b>Alpha Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYQ">TODAY, Wed 31, 4:16\u20134:33 pm</a> @ <a href="https://maps.google.com/maps?q=Alpha+Venue%2C+Rest+of+Alpha+Location">Alpha Venue</a>
"""
assert conversation.message(
'/admin modulestestbot moderator -1001000001000 timezone UTC') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a moderator \u203a -1001000001000: <b>Choose a field</b>
Set timezone to <code>UTC</code>.
[calendars (6fc2c510) \u2022 Which calendars should be listed in /events? | /admin modulestestbot moderator -1001000001000 calendars]
[daily \u2022 Should I announce upcoming events once a day? If so, at what hour? | /admin modulestestbot moderator -1001000001000 daily]
[dailytext \u2022 One or more messages (one per line) to use/cycle through for the daily announcement. | /admin modulestestbot moderator -1001000001000 dailytext]
[greeting \u2022 How should I greet people when they join? | /admin modulestestbot moderator -1001000001000 greeting]
[maxeventscount \u2022 How many events should be listed in /events? | /admin modulestestbot moderator -1001000001000 maxeventscount]
[maxeventsdays \u2022 How many days into the future should /events look? | /admin modulestestbot moderator -1001000001000 maxeventsdays]
[timezone (UTC) \u2022 What time zone should be used in /events? | /admin modulestestbot moderator -1001000001000 timezone]
[Back | /admin modulestestbot moderator]
"""
assert conversation.message('/events', chat_type='supergroup') == """\
[chat_id=-1001000001000 disable_web_page_preview=True parse_mode=HTML reply_to_message_id=2000]
<b>Alpha Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYQ">TODAY, Thu 1, 12:16\u201312:33 am</a> @ <a href="https://maps.google.com/maps?q=Alpha+Venue%2C+Rest+of+Alpha+Location">Alpha Venue</a>
<b>Bravo Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDpicmF2bw">1 week on Thu 8, 12\u20131 am</a> @ <a href="https://maps.google.com/maps?q=Bravo+Venue%2C+Rest+of+Bravo+Location">Bravo Venue</a>
"""
assert conversation.message(
'/admin modulestestbot moderator -1001000001000 maxeventscount 1') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Bot Admin \u203a modulestestbot \u203a moderator \u203a -1001000001000: <b>Choose a field</b>
Set <code>maxeventscount</code> to <code>1</code>.
[calendars (6fc2c510) \u2022 Which calendars should be listed in /events? | /admin modulestestbot moderator -1001000001000 calendars]
[daily \u2022 Should I announce upcoming events once a day? If so, at what hour? | /admin modulestestbot moderator -1001000001000 daily]
[dailytext \u2022 One or more messages (one per line) to use/cycle through for the daily announcement. | /admin modulestestbot moderator -1001000001000 dailytext]
[greeting \u2022 How should I greet people when they join? | /admin modulestestbot moderator -1001000001000 greeting]
[maxeventscount (1) \u2022 How many events should be listed in /events? | /admin modulestestbot moderator -1001000001000 maxeventscount]
[maxeventsdays \u2022 How many days into the future should /events look? | /admin modulestestbot moderator -1001000001000 maxeventsdays]
[timezone (UTC) \u2022 What time zone should be used in /events? | /admin modulestestbot moderator -1001000001000 timezone]
[Back | /admin modulestestbot moderator]
"""
assert conversation.message('/events', chat_type='supergroup') == """\
[chat_id=-1001000001000 disable_web_page_preview=True parse_mode=HTML reply_to_message_id=2000]
<b>Alpha Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYQ">TODAY, Thu 1, 12:16\u201312:33 am</a> @ <a href="https://maps.google.com/maps?q=Alpha+Venue%2C+Rest+of+Alpha+Location">Alpha Venue</a>
"""
monkeypatch.setattr('time.time', lambda: 2000000.)
assert conversation.message('/events', chat_type='supergroup') == """\
[chat_id=-1001000001000 disable_web_page_preview=True parse_mode=HTML reply_to_message_id=2000]
No events in the next 6 days!
"""
def test_private(conversation, monkeypatch): # pylint: disable=redefined-outer-name
"""Test /events in a private chat."""
assert conversation.message('/events') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Please choose one or more calendars and set your time zone!
[Settings | /events set]
"""
assert conversation.message('/events set') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings: <b>Choose a field</b>
[calendars \u2022 Which calendars do you want to see? | /events set calendars]
[timezone \u2022 What time zone are you in? | /events set timezone]
[Back | /events]
"""
assert conversation.message('/events set calendars') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings \u203a calendars: <b>Select a calendar</b>
Which calendars do you want to see?
Select a calendar to add or remove from the list below:
[Add Test Calendar | /events set calendars add 6fc2c510]
[Back | /events set]
"""
assert conversation.message('/events set calendars add 6fc2c510') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings \u203a calendars: <b>Select a calendar</b>
Added <code>6fc2c510</code> to your calendar view.
Which calendars do you want to see?
Select a calendar to add or remove from the list below:
[Remove Test Calendar | /events set calendars remove 6fc2c510]
[Back | /events set]
"""
assert conversation.message('/events set timezone US/Pacific') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings: <b>Choose a field</b>
Set timezone to <code>US/Pacific</code>.
[calendars (6fc2c510) \u2022 Which calendars do you want to see? | /events set calendars]
[timezone (US/Pacific) \u2022 What time zone are you in? | /events set timezone]
[Back | /events]
"""
assert conversation.message('/events') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
<b>Alpha Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYQ">TODAY, Wed 31, 4:16\u20134:33 pm</a> @ <a href="https://maps.google.com/maps?q=Alpha+Venue%2C+Rest+of+Alpha+Location">Alpha Venue</a>
Alpha Description
[\xa0 | /stop] [Settings | /events set] [Next | /events 6fc2c510:bravo]
"""
assert conversation.message('/events 6fc2c510:bravo') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
<b>Bravo Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDpicmF2bw">1 week on Wed, Jan (1970) 7, 4\u20135 pm</a> @ <a href="https://maps.google.com/maps?q=Bravo+Venue%2C+Rest+of+Bravo+Location">Bravo Venue</a>
Bravo Description
[Prev | /events 6fc2c510:alpha] [Current | /events] [Next | /events 6fc2c510:charlie]
"""
monkeypatch.setattr('time.time', lambda: 2000000.)
assert conversation.message('/events') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
No upcoming events!
[\xa0 | /stop] [Settings | /events set] [\xa0 | /stop]
"""
def test_inline(conversation, monkeypatch): # pylint: disable=redefined-outer-name
"""Test @BOTUSER events."""
assert conversation.raw_inline('events') == [
{
'cache_time': 30,
'inline_query_id': 2000,
'is_personal': True,
'switch_pm_text': 'Click to choose one or more calendars and set your time zone!',
'switch_pm_parameter': 'L2V2ZW50cw',
'results': [],
},
] # yapf: disable
assert conversation.message('/events set calendars add 6fc2c510') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings \u203a calendars: <b>Select a calendar</b>
Added <code>6fc2c510</code> to your calendar view.
Which calendars do you want to see?
Select a calendar to add or remove from the list below:
[Remove Test Calendar | /events set calendars remove 6fc2c510]
[Back | /events set]
"""
assert conversation.message('/events set timezone US/Pacific') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings: <b>Choose a field</b>
Set timezone to <code>US/Pacific</code>.
[calendars (6fc2c510) \u2022 Which calendars do you want to see? | /events set calendars]
[timezone (US/Pacific) \u2022 What time zone are you in? | /events set timezone]
[Back | /events]
"""
assert conversation.raw_inline('events') == [
{
'cache_time': 30,
'inline_query_id': 2000,
'is_personal': True,
'switch_pm_text': 'Settings',
'switch_pm_parameter': 'L2V2ZW50cyBzZXQ',
'results': [
{
'description': 'TODAY, Wed 31, 4:16\u20134:33 pm @ Alpha Venue',
'id': '6fc2c510:alpha',
'input_message_content': {
'disable_web_page_preview': True,
'message_text': '<b>Alpha Summary</b>\n'
'<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYQ">TODAY, Wed 31, 4:16\u20134:33 pm</a> @ <a href="https://maps.google.com/maps?q=Alpha+Venue%2C+Rest+of+Alpha+Location">Alpha Venue</a>',
'parse_mode': 'HTML',
},
'title': 'Alpha Summary',
'type': 'article',
},
{
'description': '1 week on Wed, Jan (1970) 7, 4\u20135 pm @ Bravo Venue',
'id': '6fc2c510:bravo',
'input_message_content': {
'disable_web_page_preview': True,
'message_text': '<b>Bravo Summary</b>\n'
'<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDpicmF2bw">1 week on Wed, Jan (1970) 7, 4\u20135 pm</a> @ <a href="https://maps.google.com/maps?q=Bravo+Venue%2C+Rest+of+Bravo+Location">Bravo Venue</a>',
'parse_mode': 'HTML',
},
'title': 'Bravo Summary',
'type': 'article',
},
{
'description': '1 week on Wed, Jan (1970) 7, 4\u20135 pm @ Charlie Venue',
'id': '6fc2c510:charlie',
'input_message_content': {
'disable_web_page_preview': True,
'message_text': '<b>Charlie Summary</b>\n'
'<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDpjaGFybGll">1 week on Wed, Jan (1970) 7, 4\u20135 pm</a> @ <a href="https://maps.google.com/maps?q=Charlie+Venue%2C+Rest+of+Charlie+Location">Charlie Venue</a>',
'parse_mode': 'HTML',
},
'title': 'Charlie Summary',
'type': 'article',
},
],
},
] # yapf: disable
assert conversation.raw_inline('events bra') == [
{
'cache_time': 30,
'inline_query_id': 2000,
'is_personal': True,
'switch_pm_text': 'Settings',
'switch_pm_parameter': 'L2V2ZW50cyBzZXQ',
'results': [
{
'description': '1 week on Wed, Jan (1970) 7, 4\u20135 pm @ Bravo Venue',
'id': '6fc2c510:bravo',
'input_message_content': {
'disable_web_page_preview': True,
'message_text': '<b>Bravo Summary</b>\n'
'<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDpicmF2bw">1 week on Wed, Jan (1970) 7, 4\u20135 pm</a> @ <a href="https://maps.google.com/maps?q=Bravo+Venue%2C+Rest+of+Bravo+Location">Bravo Venue</a>',
'parse_mode': 'HTML',
},
'title': 'Bravo Summary',
'type': 'article',
},
],
},
] # yapf: disable
assert conversation.raw_inline('events full bra') == [
{
'cache_time': 30,
'inline_query_id': 2000,
'is_personal': True,
'switch_pm_text': 'Settings',
'switch_pm_parameter': 'L2V2ZW50cyBzZXQ',
'results': [
{
'description': 'Bravo Description',
'id': '6fc2c510:bravo',
'input_message_content': {
'disable_web_page_preview': True,
'message_text': '<b>Bravo Summary</b>\n'
'<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDpicmF2bw">1 week on Wed, Jan (1970) 7, 4\u20135 pm</a> @ <a href="https://maps.google.com/maps?q=Bravo+Venue%2C+Rest+of+Bravo+Location">Bravo Venue</a>\n'
'\n'
'Bravo Description',
'parse_mode': 'HTML',
},
'title': 'Bravo Summary \u2022 1 week on Wed, Jan (1970) 7, 4\u20135 pm @ Bravo Venue',
'type': 'article',
},
],
},
] # yapf: disable
monkeypatch.setattr('time.time', lambda: 2000000.)
assert conversation.raw_inline('events') == [
{
'cache_time': 30,
'inline_query_id': 2000,
'is_personal': True,
'switch_pm_text': 'Settings',
'switch_pm_parameter': 'L2V2ZW50cyBzZXQ',
'results': [],
},
] # yapf: disable
def test_settings(conversation): # pylint: disable=redefined-outer-name
"""Test /events set."""
assert conversation.message('/events set') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings: <b>Choose a field</b>
[calendars \u2022 Which calendars do you want to see? | /events set calendars]
[timezone \u2022 What time zone are you in? | /events set timezone]
[Back | /events]
"""
assert conversation.message('/events set calendars') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings \u203a calendars: <b>Select a calendar</b>
Which calendars do you want to see?
Select a calendar to add or remove from the list below:
[Add Test Calendar | /events set calendars add 6fc2c510]
[Back | /events set]
"""
assert conversation.message('/events set calendars add 6fc2c510') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings \u203a calendars: <b>Select a calendar</b>
Added <code>6fc2c510</code> to your calendar view.
Which calendars do you want to see?
Select a calendar to add or remove from the list below:
[Remove Test Calendar | /events set calendars remove 6fc2c510]
[Back | /events set]
"""
assert conversation.message('/events set calendars add 6fc2c510') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings \u203a calendars: <b>Select a calendar</b>
<code>6fc2c510</code> is already in your calendar view!
Which calendars do you want to see?
Select a calendar to add or remove from the list below:
[Remove Test Calendar | /events set calendars remove 6fc2c510]
[Back | /events set]
"""
assert conversation.message('/events set calendars remove 6fc2c510') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings \u203a calendars: <b>Select a calendar</b>
Removed <code>6fc2c510</code> from your calendar view.
Which calendars do you want to see?
Select a calendar to add or remove from the list below:
[Add Test Calendar | /events set calendars add 6fc2c510]
[Back | /events set]
"""
assert conversation.message('/events set calendars remove 6fc2c510') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings \u203a calendars: <b>Select a calendar</b>
<code>6fc2c510</code> is not in your calendar view!
Which calendars do you want to see?
Select a calendar to add or remove from the list below:
[Add Test Calendar | /events set calendars add 6fc2c510]
[Back | /events set]
"""
assert conversation.message('/events set calendars add bogus') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings \u203a calendars: <b>Select a calendar</b>
<code>bogus</code> is not a calendar!
Which calendars do you want to see?
Select a calendar to add or remove from the list below:
[Add Test Calendar | /events set calendars add 6fc2c510]
[Back | /events set]
"""
assert conversation.message('/events set bogus') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
Events \u203a Settings: <b>Choose a field</b>
I can't set <code>bogus</code>.
[calendars \u2022 Which calendars do you want to see? | /events set calendars]
[timezone \u2022 What time zone are you in? | /events set timezone]
[Back | /events]
"""
def test_help(conversation): # pylint: disable=redefined-outer-name
"""Test /help."""
assert conversation.message('/help', user_id=2000) == """\
[chat_id=2000 disable_web_page_preview=True parse_mode=HTML]
<b>Commands</b>
/events \u2013 Display recent and upcoming events
"""
def test_format_daily_message(): # pylint: disable=missing-docstring
# yapf: disable - pylint: disable=protected-access
assert events._format_daily_message('', ['EVENT1']) == (
"There's an event coming up:\n"
'\n'
'EVENT1')
assert events._format_daily_message('', ['EVENT1', 'EVENT2']) == (
"There are a couple events coming up:\n"
'\n'
'EVENT1\n'
'EVENT2')
assert events._format_daily_message('', ['EVENT1', 'EVENT2', 'EVENT3']) == (
"There are a few events coming up:\n"
'\n'
'EVENT1\n'
'EVENT2\n'
'EVENT3')
assert events._format_daily_message('', ['EVENT1', 'EVENT2', 'EVENT3', 'EVENT4']) == (
"There are a bunch of events coming up:\n"
'\n'
'EVENT1\n'
'EVENT2\n'
'EVENT3\n'
'EVENT4')
assert events._format_daily_message('', ['EVENT1', 'EVENT2', 'EVENT3', 'EVENT4', 'EVENT5']) == (
"There are a bunch of events coming up:\n"
'\n'
'EVENT1\n'
'EVENT2\n'
'EVENT3\n'
'EVENT4\n'
'EVENT5')
assert events._format_daily_message('1 + 1 = 2!', ['EVENT1']) == (
"1 + 1 = 2! Also, there's an event coming up:\n"
'\n'
'EVENT1')
assert events._format_daily_message('Visit @MYGROUP', ['EVENT1']) == (
"Visit @MYGROUP \u2022 Also, there's an event coming up:\n"
'\n'
'EVENT1')
assert events._format_daily_message('I love events.', ['EVENT1']) == (
"I love events. Speaking of which, there's an event coming up:\n"
'\n'
'EVENT1')
assert events._format_daily_message('I love events:', ['EVENT1']) == (
"I love events:\n"
'\n'
'EVENT1')