Beispiel #1
0
def test_daily_messages_geometry(conversation, daily_messages):  # pylint: disable=redefined-outer-name
    """See https://github.com/nmlorg/metabot/issues/75."""

    daily_messages(True)

    cal = loader.get('static:test_events')
    cal.events['6fc2c510:alpha']['description'] = 'Trigger'
    conversation.bot.config['issue37']['moderator']['-1002000002000']['maxeventscount'] = 1

    assert daily_messages() == ({
        ('modulestestbot', '-1002000002000'): (0, [{
            'description': 'Trigger',
            'end': 2000,
            'local_id': '6fc2c510:alpha',
            'location': 'Alpha Venue, Rest of Alpha Location',
            'start': 1000,
            'summary': 'Alpha Summary',
        }], {
            'message_id': 12345,
        }),
    }, """\
[chat_id=-1002000002000 disable_notification=True disable_web_page_preview=True parse_mode=HTML reply_to_message_id=12345]
Updated:
  • Alpha Summary
    ◦ <i>Alpha Description</i> → <b>Trigger</b>


[chat_id=-1002000002000 disable_web_page_preview=True message_id=12345 parse_mode=HTML]
There's an event coming up:

<b>Alpha Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYSBVVEM">TODAY, Thu 1ˢᵗ, 12:16–12:33ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=Alpha+Venue%2C+Rest+of+Alpha+Location">Alpha Venue</a>

[<a href="https://t.me/c/2000002000/12345">Updated 12ᵃᵐ</a>]
""")
Beispiel #2
0
    def add(self, calid):
        """Add a new calendar to the manager (if it's not already installed)."""

        if calid not in self.calendars:
            self.calendars[calid] = loader.get(calid)
            self.ordered.extend(self.calendars[calid].events.values())
            self._rebuild()
        return self.calendars[calid]
Beispiel #3
0
def test_daily_messages_add_remove_event(conversation, daily_messages):  # pylint: disable=redefined-outer-name
    """Verify what happens when events are added/removed entirely."""

    daily_messages(True)

    cal = loader.get('static:test_events')
    cal.events['6fc2c510:new'] = {
        'description': 'New Description',
        'end': 3000,
        'local_id': '6fc2c510:new',
        'location': 'New Venue, Rest of New Location',
        'start': 2000,
        'summary': 'New Summary',
    }
    conversation.multibot.multical.ordered.append(cal.events['6fc2c510:new'])
    cal.events.pop('6fc2c510:bravo')
    assert conversation.multibot.multical.ordered[1]['local_id'] == '6fc2c510:bravo'
    assert conversation.multibot.multical.ordered.pop(1)
    conversation.multibot.multical._rebuild()  # pylint: disable=protected-access

    assert daily_messages() == ({
        ('modulestestbot', '-1002000002000'): (0, [{
            'description': 'Alpha Description',
            'end': 2000,
            'local_id': '6fc2c510:alpha',
            'location': 'Alpha Venue, Rest of Alpha Location',
            'start': 1000,
            'summary': 'Alpha Summary',
        }, {
            'description': 'New Description',
            'end': 3000,
            'local_id': '6fc2c510:new',
            'location': 'New Venue, Rest of New Location',
            'start': 2000,
            'summary': 'New Summary',
        }], {
            'message_id': 12345,
        }),
    }, """\
[chat_id=-1002000002000 disable_notification=True disable_web_page_preview=True parse_mode=HTML reply_to_message_id=12345]
Updated:
  • New Summary
    ◦ New event!
  • Bravo Summary
    ◦ Removed.


[chat_id=-1002000002000 disable_web_page_preview=True message_id=12345 parse_mode=HTML]
There are a couple events coming up:

<b>Alpha Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYSBVVEM">TODAY, Thu 1ˢᵗ, 12:16–12:33ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=Alpha+Venue%2C+Rest+of+Alpha+Location">Alpha Venue</a>
<b>New Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDpuZXcgVVRD">TODAY, Thu 1ˢᵗ, 12:33–12:50ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=New+Venue%2C+Rest+of+New+Location">New Venue</a>

[<a href="https://t.me/c/2000002000/12345">Updated 12ᵃᵐ</a>]
""")
Beispiel #4
0
def test_daily_messages_ignored(daily_messages):  # pylint: disable=redefined-outer-name
    """Verify non-notification-worthy changes are properly ignored."""

    daily_messages(True)

    cal = loader.get('static:test_events')
    cal.events['6fc2c510:alpha']['description'] = (
        'Alpha Description https://www.example.com/?id=1234')

    assert daily_messages()[1] == ''

    cal.events['6fc2c510:alpha']['updated'] = 23456

    assert daily_messages()[1] == ''
Beispiel #5
0
def test_daily_messages_future(daily_messages, monkeypatch):  # pylint: disable=redefined-outer-name
    """Test the behavior when an event transitions from TODAY to NOW."""

    daily_messages(True)

    monkeypatch.setattr('time.time', lambda: 1000)

    assert daily_messages()[1] == ''

    cal = loader.get('static:test_events')
    cal.events['6fc2c510:alpha']['summary'] = 'Now Summary'

    # Note that TODAY is displayed as NOW now:
    assert daily_messages()[1] == """\
Beispiel #6
0
def test_daily_messages_multiline(daily_messages):  # pylint: disable=redefined-outer-name
    """Verify multiline event components are rendered in updates concisely."""

    daily_messages(True)

    cal = loader.get('static:test_events')
    cal.events['6fc2c510:alpha']['description'] = 'Multi\n\nLine\nDescription'

    assert daily_messages() == ({
        ('modulestestbot', '-1002000002000'): (0, [{
            'description': 'Multi\n\nLine\nDescription',
            'end': 2000,
            'local_id': '6fc2c510:alpha',
            'location': 'Alpha Venue, Rest of Alpha Location',
            'start': 1000,
            'summary': 'Alpha Summary',
        }, {
            'description': 'Bravo Description',
            'end': 608400,
            'local_id': '6fc2c510:bravo',
            'location': 'Bravo Venue, Rest of Bravo Location',
            'start': 604800,
            'summary': 'Bravo Summary',
        }], {
            'message_id': 12345,
        }),
    }, """\
[chat_id=-1002000002000 disable_notification=True disable_web_page_preview=True parse_mode=HTML reply_to_message_id=12345]
Updated:
  • Alpha Summary
    ◦ <i>Alpha Description</i> → <b>Multi Line Description</b>


[chat_id=-1002000002000 disable_web_page_preview=True message_id=12345 parse_mode=HTML]
There are a couple events coming up:

<b>Alpha Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYSBVVEM">TODAY, Thu 1ˢᵗ, 12:16–12:33ᵃᵐ</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=L2V2ZW50cyA2ZmMyYzUxMDpicmF2byBVVEM">⁷ ᵈᵃʸˢ Thu 8ᵗʰ, 12–1ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=Bravo+Venue%2C+Rest+of+Bravo+Location">Bravo Venue</a>

[<a href="https://t.me/c/2000002000/12345">Updated 12ᵃᵐ</a>]
""")
Beispiel #7
0
def test_loader(monkeypatch, tmpdir):
    """Run through loader.get."""

    # pylint: disable=protected-access
    monkeypatch.setattr(loader._CachingCalendarMixin, '_cache_dir',
                        tmpdir.strpath)
    fname = tmpdir.strpath + '/3ccaceeb.pickle'
    with open(fname, 'wb') as cachefile:
        cachefile.write(pickle.dumps({'test_value': 1}))
    cal = loader.get('static:[email protected]')
    assert cal._CachingCalendarMixin__fname == fname
    assert cal.test_value == 1
    os.remove(fname)

    assert not cal.poll()
    assert not os.path.exists(fname)

    cal.poll_result = True
    assert cal.poll()
    assert os.path.exists(fname)
    os.remove(fname)

    local = cal.add({
        'start': 1000,
        'end': 2000,
    })
    assert local
    assert os.path.exists(fname)
    os.remove(fname)

    assert cal.update(local['local_id'], {'summary': 'new summary'})
    assert os.path.exists(fname)
    os.remove(fname)

    cal.remove(local['local_id'])
    assert os.path.exists(fname)
    os.remove(fname)
Beispiel #8
0
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
Beispiel #9
0
def test_daily_messages_icons(conversation, daily_messages):  # pylint: disable=redefined-outer-name
    """Run through all the cases where events trigger banner images."""

    daily_messages(True)

    cal = loader.get('static:test_events')
    cal.events['6fc2c510:alpha']['description'] = 'Board Games!'

    # An update does not include references to icons.
    assert daily_messages()[1] == """\
[chat_id=-1002000002000 disable_notification=True disable_web_page_preview=True parse_mode=HTML reply_to_message_id=12345]
Updated:
  • Alpha Summary
    ◦ <i>Alpha Description</i> → <b>Board Games!</b>


[chat_id=-1002000002000 disable_web_page_preview=True message_id=12345 parse_mode=HTML]
There are a couple events coming up:

<b>Alpha Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYSBVVEM">TODAY, Thu 1ˢᵗ, 12:16–12:33ᵃᵐ</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=L2V2ZW50cyA2ZmMyYzUxMDpicmF2byBVVEM">⁷ ᵈᵃʸˢ Thu 8ᵗʰ, 12–1ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=Bravo+Venue%2C+Rest+of+Bravo+Location">Bravo Venue</a>

[<a href="https://t.me/c/2000002000/12345">Updated 12ᵃᵐ</a>]
"""

    # But an initial announcement does (photo=...).
    assert daily_messages(True)[1] == """\
[chat_id=-1002000002000 disable_notification=True parse_mode=HTML photo=https://ssl.gstatic.com/calendar/images/eventillustrations/v1/img_gamenight_2x.jpg]
There are a couple events coming up:

<b>Alpha Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYSBVVEM">TODAY, Thu 1ˢᵗ, 12:16–12:33ᵃᵐ</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=L2V2ZW50cyA2ZmMyYzUxMDpicmF2byBVVEM">⁷ ᵈᵃʸˢ Thu 8ᵗʰ, 12–1ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=Bravo+Venue%2C+Rest+of+Bravo+Location">Bravo Venue</a>
"""

    conversation.bot.config['issue37']['events']['series']['ha sum'] = 'SERIES ICON'

    assert daily_messages(True)[1] == """\
[chat_id=-1002000002000 disable_notification=True parse_mode=HTML photo=SERIES ICON]
There are a couple events coming up:

<b>Alpha Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYSBVVEM">TODAY, Thu 1ˢᵗ, 12:16–12:33ᵃᵐ</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=L2V2ZW50cyA2ZmMyYzUxMDpicmF2byBVVEM">⁷ ᵈᵃʸˢ Thu 8ᵗʰ, 12–1ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=Bravo+Venue%2C+Rest+of+Bravo+Location">Bravo Venue</a>
"""

    conversation.bot.config['issue37']['events']['events']['6fc2c510:alpha'] = 'EVENT ICON'

    assert daily_messages(True)[1] == """\
[chat_id=-1002000002000 disable_notification=True parse_mode=HTML photo=EVENT ICON]
There are a couple events coming up:

<b>Alpha Summary</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyA2ZmMyYzUxMDphbHBoYSBVVEM">TODAY, Thu 1ˢᵗ, 12:16–12:33ᵃᵐ</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=L2V2ZW50cyA2ZmMyYzUxMDpicmF2byBVVEM">⁷ ᵈᵃʸˢ Thu 8ᵗʰ, 12–1ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=Bravo+Venue%2C+Rest+of+Bravo+Location">Bravo Venue</a>
"""

    cal.events['6fc2c510:alpha']['description'] = 'Fun Games!'

    # Removing an icon trigger leaves the image in place.
    assert daily_messages()[1] == """\
Beispiel #10
0
def test_simple(conversation, monkeypatch):  # pylint: disable=redefined-outer-name
    """Verify the natlang module."""

    assert conversation.message('When is the next sock hop?') == ''

    monkeypatch.setattr('time.time', lambda: 1000.)

    other_cal = loader.get('static:other_cal')
    assert other_cal.calcode == '2a366983'
    other_cal.events = {
        '2a366983:alpha': {
            'description': 'Alpha Description',
            'end': 3000,
            'local_id': '2a366983:alpha',
            'location': 'Alpha Venue, Rest of Alpha Location',
            'start': 2000,
            'summary': 'Other Sock Hop',
        },
    }
    conversation.multibot.multical.add('static:other_cal')
    conversation.multibot.calendars['2a366983'] = {'name': 'Other Group'}

    my_cal = loader.get('static:my_cal')
    assert my_cal.calcode == 'fc2d5e05'
    my_cal.events = {
        'fc2d5e05:bravo': {
            'description': '',
            'end': 5000,
            'local_id': 'fc2d5e05:bravo',
            'location': 'My Venue, Rest of My Location',
            'start': 4000,
            'summary': 'My Sock Hop',
        },
        'fc2d5e05:charlie': {
            'description': '',
            'end': 7000,
            'local_id': 'fc2d5e05:charlie',
            'location': 'My Venue, Rest of My Location',
            'start': 6000,
            'summary': 'Special Sock Hop',
        },
        'fc2d5e05:delta': {
            'description': '',
            'end': 9000,
            'local_id': 'fc2d5e05:delta',
            'location': 'Alternate Venue, Rest of Special Location',
            'start': 8000,
            'summary': 'Alternate Sock Hop',
        },
    }
    conversation.multibot.multical.add('static:my_cal')
    conversation.multibot.calendars['fc2d5e05'] = {'name': 'My Group'}

    conversation.bot.config['issue37']['events']['users']['1000'][
        'calendars'] = 'fc2d5e05'

    assert conversation.message('When is the next sock hop?') == """\
[chat_id=1000 disable_web_page_preview=True parse_mode=HTML]
<i>The next sock hop I know about is:</i>

<b>Other Sock Hop</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyAyYTM2Njk4MzphbHBoYSBVVEM">TODAY, Thu 1ˢᵗ, 12:33–12:50ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=Alpha+Venue%2C+Rest+of+Alpha+Location">Alpha Venue</a>

<i>The next sock hop on the My Group calendar is:</i>

<b>My Sock Hop</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyBmYzJkNWUwNTpicmF2byBVVEM">TODAY, Thu 1ˢᵗ, 1:06–1:23ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=My+Venue%2C+Rest+of+My+Location">My Venue</a>

<i>The next Special Sock Hop is:</i>

<b>Special Sock Hop</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyBmYzJkNWUwNTpjaGFybGllIFVUQw">TODAY, Thu 1ˢᵗ, 1:40–1:56ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=My+Venue%2C+Rest+of+My+Location">My Venue</a>

<i>The next sock hop at Alternate Venue is:</i>

<b>Alternate Sock Hop</b>
<a href="https://t.me/modulestestbot?start=L2V2ZW50cyBmYzJkNWUwNTpkZWx0YSBVVEM">TODAY, Thu 1ˢᵗ, 2:13–2:30ᵃᵐ</a> @ <a href="https://maps.google.com/maps?q=Alternate+Venue%2C+Rest+of+Special+Location">Alternate Venue</a>
"""

    assert conversation.message('When is the next my sock hop?') == """\