Example #1
0
def test_comment_in_thread(database, reddit):
    comment_id = utils.random_id()
    thread_id = utils.random_id()
    comment = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author="Watchful1",
        created=utils.datetime_now(),
        id=comment_id,
        link_id="t3_" + thread_id,
        permalink=f"/r/test/{thread_id}/_/{comment_id}/",
        subreddit="test")
    reddit.add_comment(comment)

    comments.process_comment(comment.get_pushshift_dict(), reddit, database)

    comment_id_2 = utils.random_id()
    comment_2 = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author="Watchful1",
        created=utils.datetime_now(),
        id=comment_id_2,
        link_id="t3_" + thread_id,
        permalink=f"/r/test/{thread_id}/_/{comment_id_2}/")
    reddit.add_comment(comment_2)

    comments.process_comment(comment_2.get_pushshift_dict(), reddit, database)

    assert len(comment_2.children) == 0
    assert len(reddit.sent_messages) == 1
    assert reddit.sent_messages[0].author.name == static.ACCOUNT_NAME
    assert "I've already replied to another comment in this thread" in reddit.sent_messages[
        0].body
Example #2
0
def test_remove_all_reminders(database, reddit):
    utils.debug_time = utils.parse_datetime_string("2019-01-01 12:00:00")
    message = reddit_test.RedditObject(body=f"RemoveAll!", author="Watchful1")
    messages.process_message(message, reddit, database)
    assert "Deleted" not in message.get_first_child().body

    reminder1 = Reminder(
        source="https://www.reddit.com/message/messages/XXXXX",
        message="KKKKK",
        user=database.get_or_add_user("Watchful1"),
        requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
        target_date=utils.parse_datetime_string("2019-01-04 05:00:00"))
    reminder2 = Reminder(
        source="https://www.reddit.com/message/messages/YYYYY",
        message="FFFFF",
        user=database.get_or_add_user("Watchful1"),
        requested_date=utils.parse_datetime_string("2019-02-02 06:00:00"),
        target_date=utils.parse_datetime_string("2019-02-05 07:00:00"))
    reminder3 = Reminder(
        source="https://www.reddit.com/message/messages/ZZZZZ",
        message="JJJJJ",
        user=database.get_or_add_user("Watchful2"),
        requested_date=utils.parse_datetime_string("2019-03-02 06:00:00"),
        target_date=utils.parse_datetime_string("2019-03-05 07:00:00"))
    database.add_reminder(reminder1)
    database.add_reminder(reminder2)
    database.add_reminder(reminder3)

    message = reddit_test.RedditObject(body=f"RemoveAll!", author="Watchful1")
    messages.process_message(message, reddit, database)
    body = message.get_first_child().body
    assert "Deleted **2** reminders." in body

    assert len(database.get_all_user_reminders("Watchful1")) == 0
    assert len(database.get_all_user_reminders("Watchful2")) == 1
Example #3
0
def test_delete_comment(database, reddit):
    db_comment = DbComment(thread_id="XXXXX",
                           comment_id="ZZZZZ",
                           reminder_id="YYYYY",
                           user="******",
                           source="www.reddit.com/r/test/comments/XXXXX",
                           current_count=1)
    database.save_comment(db_comment)
    comment = reddit_test.RedditObject(body="Click here for a reminder!",
                                       author=static.ACCOUNT_NAME,
                                       id="ZZZZZ")
    reddit.add_comment(comment, True)

    message = reddit_test.RedditObject(body=f"Delete! SSSSSS",
                                       author="Watchful1")
    messages.process_message(message, reddit, database)
    assert "This comment doesn't exist or was already deleted." in message.get_first_child(
    ).body

    message = reddit_test.RedditObject(body=f"Delete! XXXXX",
                                       author="Watchful2")
    messages.process_message(message, reddit, database)
    assert "It looks like the bot wasn't replying to you." in message.get_first_child(
    ).body

    message = reddit_test.RedditObject(body=f"Delete! XXXXX",
                                       author="Watchful1")
    messages.process_message(message, reddit, database)
    assert "Comment deleted." in message.get_first_child().body
    assert comment.id not in reddit.all_comments
Example #4
0
def test_get_reminders(database, reddit):
    utils.debug_time = utils.parse_datetime_string("2019-01-01 12:00:00")
    message = reddit_test.RedditObject(body="MyReminders!", author="Watchful1")
    messages.process_message(message, reddit, database)
    result = message.get_first_child().body
    assert "You don't have any reminders." in result

    reminders = [
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message="KKKKK",
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-04 05:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/YYYYY",
            message="FFFFF",
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-02-02 06:00:00"),
            target_date=utils.parse_datetime_string("2019-02-05 07:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/ZZZZZ",
            message="GGGGG",
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-02-02 06:00:00"),
            target_date=utils.parse_datetime_string("2019-02-05 07:00:00"),
            recurrence="one day")
    ]
    for reminder in reminders:
        database.add_reminder(reminder)

    message = reddit_test.RedditObject(body="MyReminders!", author="Watchful1")
    messages.process_message(message, reddit, database)
    result = message.get_first_child().body

    assert "Click here to delete all your reminders" in result
    assert "|Source|Message|Date|In|Repeat|Remove|" in result
    assert "|Source|Message|Date|In|Remove|" in result

    assert reminders[0].source in result
    assert reminders[0].message in result
    assert "01-04 05" in result

    assert reminders[1].source in result
    assert reminders[1].message in result
    assert "02-05 07" in result

    assert reminders[2].recurrence in result

    user = database.get_or_add_user(user_name="Watchful1")
    user.timezone = "America/Los_Angeles"
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "Your timezone is currently set to: `America/Los_Angeles`" in result
    assert "01-03 21" in result
    assert "02-04 23" in result
Example #5
0
def test_add_cakeday_exists(database, reddit):
    username = "******"
    created = utils.parse_datetime_string("2015-05-05 15:25:17")
    user = reddit_test.User(username, created.timestamp())
    message = reddit_test.RedditObject(body="Cakeday!", author=user)
    messages.process_message(message, reddit, database)

    message2 = reddit_test.RedditObject(body="Cakeday!", author=user)
    messages.process_message(message2, reddit, database)

    result = message2.get_first_child().body

    assert "It looks like you already have a cakeday reminder set." in result
Example #6
0
def test_get_reminders(database, reddit):
    utils.debug_time = utils.parse_datetime_string("2019-01-01 12:00:00")
    message = reddit_test.RedditObject(body="MyReminders!", author="Watchful1")
    messages.process_message(message, reddit, database)
    result = message.get_first_child().body
    assert "You don't have any reminders." in result

    reminder1 = Reminder(
        source="https://www.reddit.com/message/messages/XXXXX",
        message="KKKKK",
        user="******",
        requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
        target_date=utils.parse_datetime_string("2019-01-04 05:00:00"))
    reminder2 = Reminder(
        source="https://www.reddit.com/message/messages/YYYYY",
        message="FFFFF",
        user="******",
        requested_date=utils.parse_datetime_string("2019-02-02 06:00:00"),
        target_date=utils.parse_datetime_string("2019-02-05 07:00:00"))
    database.save_reminder(reminder1)
    database.save_reminder(reminder2)
    cakeday = Cakeday(
        user="******",
        date_time=utils.parse_datetime_string("2019-05-05 15:25:17"))
    database.add_cakeday(cakeday)

    message = reddit_test.RedditObject(body="MyReminders!", author="Watchful1")
    messages.process_message(message, reddit, database)
    result = message.get_first_child().body

    assert "Click here to delete all your reminders" in result

    assert "Happy cakeday!" in result

    assert reminder1.source in result
    assert reminder1.message in result
    assert "01-04 05" in result

    assert reminder2.source in result
    assert reminder2.message in result
    assert "02-05 07" in result

    database.save_settings(
        UserSettings(user="******", timezone="America/Los_Angeles"))
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "Your timezone is currently set to: `America/Los_Angeles`" in result
    assert "01-03 21" in result
    assert "02-04 23" in result
Example #7
0
def test_add_reminder(database, reddit):
    created = utils.datetime_now()
    username = "******"
    keyword = "reminderstring"
    id = utils.random_id()
    message = reddit_test.RedditObject(
        body=f"[{keyword}]\n{static.TRIGGER}! 1 day",
        author=username,
        created=created,
        id=id)

    messages.process_message(message, reddit, database)
    result = message.get_first_child().body

    assert "reminderstring" in result

    assert "This time has already passed" not in result
    assert "Could not find a time in message" not in result
    assert "Could not parse date" not in result

    reminders = database.get_user_reminders(username)
    assert len(reminders) == 1
    assert reminders[0].user == username
    assert reminders[0].message == keyword
    assert reminders[0].source == utils.message_link(id)
    assert reminders[0].requested_date == created
    assert reminders[0].target_date == created + timedelta(hours=24)
    assert reminders[0].db_id is not None
Example #8
0
def test_add_recurring_reminder(database, reddit):
    created = utils.datetime_now()
    username = "******"
    keyword = "reminderstring"
    id = utils.random_id()
    message = reddit_test.RedditObject(
        body=f"[{keyword}]\n{static.TRIGGER_RECURRING}! 1 day",
        author=username,
        created=created,
        id=id)

    messages.process_message(message, reddit, database)
    result = message.get_first_child().body

    assert "reminderstring" in result
    assert "and then every `1 day`" in result

    assert "This time has already passed" not in result
    assert "Could not find a time in message" not in result
    assert "Could not parse date" not in result
    assert "Can't use a default for a recurring reminder" not in result
    assert "I got the same date rather than one after it" not in result
    assert "I got a date before that rather than one after it" not in result

    reminders = database.get_all_user_reminders(username)
    assert len(reminders) == 1
    assert reminders[0].user.name == username
    assert reminders[0].message == keyword
    assert reminders[0].source == utils.message_link(id)
    assert reminders[0].requested_date == created
    assert reminders[0].target_date == created + timedelta(hours=24)
    assert reminders[0].id is not None
    assert reminders[0].recurrence == "1 day"
Example #9
0
def test_process_comment(database, reddit):
    created = utils.datetime_now()
    username = "******"
    comment_id = utils.random_id()
    thread_id = utils.random_id()
    comment = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author=username,
        created=created,
        id=comment_id,
        link_id="t3_" + thread_id,
        permalink=f"/r/test/{thread_id}/_/{comment_id}/",
        subreddit="test")

    reddit.add_comment(comment)

    comments.process_comment(comment.get_pushshift_dict(), reddit, database)
    result = comment.get_first_child().body

    assert "CLICK THIS LINK" in result

    reminders = database.get_all_user_reminders(username)
    assert len(reminders) == 1
    assert reminders[0].user.name == username
    assert reminders[0].message is None
    assert reminders[0].source == utils.reddit_link(comment.permalink)
    assert reminders[0].requested_date == created
    assert reminders[0].target_date == created + timedelta(hours=24)
    assert reminders[0].id is not None
    assert reminders[0].recurrence is None
Example #10
0
def test_process_comment_timezone(database, reddit):
    user = database.get_or_add_user(user_name="Watchful1")
    user.timezone = "America/Los_Angeles"

    username = "******"
    comment_id = utils.random_id()
    thread_id = utils.random_id()
    created = utils.datetime_now()
    comment = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author=username,
        created=created,
        id=comment_id,
        link_id="t3_" + thread_id,
        permalink=f"/r/test/{thread_id}/_/{comment_id}/",
        subreddit="test")
    reddit.add_comment(comment)

    comments.process_comment(comment.get_pushshift_dict(), reddit, database)
    result = comment.get_first_child().body

    assert "default time zone" in result
    assert "`America/Los_Angeles`" in result

    reminders = database.get_all_user_reminders(username)
    assert reminders[0].target_date == created + timedelta(hours=24)
Example #11
0
def test_set_timezone(database, reddit):
    username = "******"
    message = reddit_test.RedditObject(body="Timezone! ", author=username)
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "I couldn't find a timezone in your message." in result

    message.body = "Timezone! EST"
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "EST is not a valid timezone." in result

    message.body = "Timezone! America/Los_Angeles"
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "Updated your timezone to America/Los_Angeles" in result
    user_settings = database.get_settings(username)
    assert user_settings.timezone == "America/Los_Angeles"

    message.body = "Timezone! UTC"
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "Reset your timezone to the default" in result
    user_settings = database.get_settings(username)
    assert user_settings.timezone is None
Example #12
0
def test_set_clock(database, reddit):
    username = "******"
    message = reddit_test.RedditObject(body="Clock! ", author=username)
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "I couldn't find a clock type in your message." in result

    message.body = "Clock! 22"
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "22 is not a valid clock type." in result

    message.body = "Clock! 12"
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "Updated your clock type to a 12 hour clock" in result
    user = database.get_or_add_user(username)
    assert user.time_format == "12"

    message.body = "Clock! 24"
    messages.process_message(message, reddit, database)
    result = message.get_last_child().body
    assert "Reset your clock type to the default 24 hour clock" in result
    user = database.get_or_add_user(username)
    assert user.time_format is None
Example #13
0
def test_remove_reminder(database, reddit):
    reminder1 = Reminder(
        source="https://www.reddit.com/message/messages/XXXXX",
        message="KKKKK",
        user="******",
        requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
        target_date=utils.parse_datetime_string("2019-01-04 05:00:00"))
    reminder2 = Reminder(
        source="https://www.reddit.com/message/messages/YYYYY",
        message="FFFFF",
        user="******",
        requested_date=utils.parse_datetime_string("2019-02-02 06:00:00"),
        target_date=utils.parse_datetime_string("2019-02-05 07:00:00"))
    reminder3 = Reminder(
        source="https://www.reddit.com/message/messages/ZZZZZ",
        message="JJJJJ",
        user="******",
        requested_date=utils.parse_datetime_string("2019-03-02 06:00:00"),
        target_date=utils.parse_datetime_string("2019-03-05 07:00:00"))
    database.save_reminder(reminder1)
    database.save_reminder(reminder2)
    database.save_reminder(reminder3)

    message = reddit_test.RedditObject(body=f"Remove! test",
                                       author="Watchful2")
    messages.process_message(message, reddit, database)
    assert "I couldn't find a reminder id to remove." in message.get_first_child(
    ).body

    message = reddit_test.RedditObject(body=f"Remove! {reminder1.db_id}",
                                       author="Watchful2")
    messages.process_message(message, reddit, database)
    assert "It looks like you don't own this reminder or it doesn't exist." in message.get_first_child(
    ).body

    message = reddit_test.RedditObject(body=f"Remove! {reminder1.db_id}",
                                       author="Watchful1")
    messages.process_message(message, reddit, database)
    assert "Reminder deleted." in message.get_first_child().body

    assert len(database.get_user_reminders("Watchful1")) == 1
    assert len(database.get_user_reminders("Watchful2")) == 1
Example #14
0
def test_remove_cakeday(database, reddit):
    cakeday1 = Cakeday(
        user="******",
        date_time=utils.parse_datetime_string("2015-05-05 15:25:17"))
    cakeday2 = Cakeday(
        user="******",
        date_time=utils.parse_datetime_string("2015-05-05 15:25:17"))
    database.add_cakeday(cakeday1)
    database.add_cakeday(cakeday2)

    message = reddit_test.RedditObject(body=f"Remove! cakeday",
                                       author="Watchful3")
    messages.process_message(message, reddit, database)
    assert "You don't have a cakeday reminder set." in message.get_first_child(
    ).body

    message = reddit_test.RedditObject(body=f"Remove! cakeday",
                                       author="Watchful1")
    messages.process_message(message, reddit, database)
    assert "Cakeday reminder deleted." in message.get_first_child().body
    assert database.get_cakeday("Watchful1") is None
    assert database.get_cakeday("Watchful2") is not None
Example #15
0
def test_commenting_deleted(database, reddit):
    comment_id = utils.random_id()
    thread_id = utils.random_id()
    comment = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author="Watchful1",
        created=utils.datetime_now(),
        id=comment_id,
        link_id="t3_" + thread_id,
        permalink=f"/r/test/{thread_id}/_/{comment_id}/",
        subreddit="test")
    comments.process_comment(comment.get_pushshift_dict(), reddit, database)

    assert len(comment.children) == 0
    assert len(reddit.sent_messages) == 1
    assert "it was deleted before I could get to it" in reddit.sent_messages[
        0].body
Example #16
0
def test_add_cakeday(database, reddit):
    username = "******"
    created = utils.parse_datetime_string("2015-05-05 15:25:17")
    user = reddit_test.User(username, created.timestamp())
    message = reddit_test.RedditObject(body="Cakeday!", author=user)

    utils.debug_time = utils.parse_datetime_string("2019-01-05 12:00:00")
    messages.process_message(message, reddit, database)
    result = message.get_first_child().body

    assert "to remind you of your cakeday" in result

    cakeday = database.get_cakeday(username)
    assert cakeday is not None
    assert cakeday.user == username
    assert cakeday.date_time == utils.parse_datetime_string(
        "2019-05-05 15:25:17")
    assert cakeday.db_id is not None
Example #17
0
def test_reset_recurring_reminder_limit(database, reddit):
    reminder = Reminder(
        source="https://www.reddit.com/message/messages/XXXXX",
        message="KKKKK",
        user=database.get_or_add_user("Watchful1"),
        requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
        target_date=utils.parse_datetime_string("2019-01-05 05:00:00"),
        recurrence="one day")
    database.add_reminder(reminder)

    utils.debug_time = utils.parse_datetime_string("2019-01-05 12:00:00")
    notifications.send_reminders(reddit, database)
    assert database.get_or_add_user("Watchful1").recurring_sent == 1

    message = reddit_test.RedditObject(body="MyReminders!", author="Watchful1")
    messages.process_message(message, reddit, database)

    assert database.get_or_add_user("Watchful1").recurring_sent == 0
Example #18
0
def test_commenting_locked(database, reddit):
    thread_id = utils.random_id()

    reddit.lock_thread(thread_id)

    comment_id = utils.random_id()
    comment = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author="Watchful1",
        created=utils.datetime_now(),
        id=comment_id,
        link_id="t3_" + thread_id,
        permalink=f"/r/test/{thread_id}/_/{comment_id}/",
        subreddit="test")
    reddit.add_comment(comment)
    comments.process_comment(comment.get_pushshift_dict(), reddit, database)

    assert len(comment.children) == 0
    assert len(reddit.sent_messages) == 1
    assert "the thread is locked" in reddit.sent_messages[0].body
Example #19
0
def test_timezone_reminder_message(database, reddit):
    user = database.get_or_add_user(user_name="Watchful1")
    user.timezone = "America/Los_Angeles"

    created = utils.datetime_now()
    target = created + timedelta(hours=24)
    username = "******"
    message = reddit_test.RedditObject(
        body=
        f"{static.TRIGGER}! {utils.get_datetime_string(utils.datetime_as_timezone(target, user.timezone))}",
        author=username,
        created=created)

    messages.process_message(message, reddit, database)

    reminders = database.get_all_user_reminders(username)
    assert len(reminders) == 1
    assert reminders[0].requested_date == created
    assert reminders[0].target_date == utils.datetime_as_utc(
        pytz.timezone(user.timezone).localize(target.replace(tzinfo=None)))
Example #20
0
def test_commenting_banned(database, reddit):
    reddit.ban_subreddit("test")

    comment_id = utils.random_id()
    thread_id = utils.random_id()
    comment = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author="Watchful1",
        created=utils.datetime_now(),
        id=comment_id,
        link_id="t3_" + thread_id,
        permalink=f"/r/test/{thread_id}/_/{comment_id}/",
        subreddit="test")
    reddit.add_comment(comment)
    comments.process_comment(comment.get_pushshift_dict(), reddit, database)

    assert len(comment.children) == 0
    assert len(reddit.sent_messages) == 1
    assert "I'm not allowed to reply in this subreddit" in reddit.sent_messages[
        0].body
Example #21
0
def test_add_cakeday(database, reddit):
    username = "******"
    created = utils.parse_datetime_string("2015-05-05 15:25:17")
    user = reddit_test.User(username, created.timestamp())
    message = reddit_test.RedditObject(body="Cakeday!", author=user)

    utils.debug_time = utils.parse_datetime_string("2019-01-05 12:00:00")
    messages.process_message(message, reddit, database)
    result = message.get_first_child().body

    assert "to remind you of your cakeday" in result

    reminders = database.get_all_user_reminders(username)
    assert len(reminders) == 1
    assert reminders[0].user.name == username
    assert reminders[0].target_date == utils.parse_datetime_string(
        "2019-05-05 15:25:17")
    assert reminders[0].id is not None
    assert reminders[0].recurrence == "1 year"
    assert reminders[0].message == "Happy Cakeday!"
Example #22
0
def test_process_cakeday_comment(database, reddit):
    username = "******"
    user = reddit_test.User(
        username,
        utils.parse_datetime_string("2015-05-05 15:25:17").timestamp())
    reddit.add_user(user)
    created = utils.parse_datetime_string("2019-01-05 11:00:00")
    comment_id = utils.random_id()
    thread_id = utils.random_id()
    comment = reddit_test.RedditObject(
        body=f"{static.TRIGGER_CAKEDAY}!",
        author=username,
        created=created,
        id=comment_id,
        link_id="t3_" + thread_id,
        permalink=f"/r/test/{thread_id}/_/{comment_id}/",
        subreddit="test")

    reddit.add_comment(comment)

    utils.debug_time = utils.parse_datetime_string("2019-01-05 12:00:00")
    comments.process_comment(comment.get_pushshift_dict(), reddit, database)
    result = comment.get_first_child().body

    assert "to remind you of your cakeday" in result

    reminders = database.get_all_user_reminders(username)
    assert len(reminders) == 1
    assert reminders[0].user.name == username
    assert reminders[0].source == utils.reddit_link(comment.permalink)
    assert reminders[0].requested_date == created
    assert reminders[0].target_date == utils.parse_datetime_string(
        "2019-05-05 15:25:17")
    assert reminders[0].id is not None
    assert reminders[0].recurrence == "1 year"
    assert reminders[0].message == "Happy Cakeday!"
Example #23
0
def test_add_reminder_no_date(database, reddit):
    created = utils.datetime_now()
    username = "******"
    id = utils.random_id()
    message = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! \"error test\"",
        author=username,
        created=created,
        id=id)

    messages.process_message(message, reddit, database)
    result = message.get_first_child().body

    assert "This time has already passed" not in result
    assert "Could not find a time in message, defaulting to one day" in result

    reminders = database.get_all_user_reminders(username)
    assert len(reminders) == 1
    assert reminders[0].user.name == username
    assert reminders[0].message == "error test"
    assert reminders[0].source == utils.message_link(id)
    assert reminders[0].requested_date == created
    assert reminders[0].target_date == created + timedelta(hours=24)
    assert reminders[0].id is not None
Example #24
0
def test_update_incorrect_comments(database, reddit):
    comment_id1 = utils.random_id()
    thread_id1 = utils.random_id()
    comment1 = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author="Watchful1",
        created=utils.datetime_now(),
        id=comment_id1,
        link_id="t3_" + thread_id1,
        permalink=f"/r/test/{thread_id1}/_/{comment_id1}/",
        subreddit="test")
    reddit.add_comment(comment1)
    comments.process_comment(comment1.get_pushshift_dict(), reddit, database)

    comment_id2 = utils.random_id()
    thread_id2 = utils.random_id()
    comment2 = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author="Watchful1",
        created=utils.datetime_now(),
        id=comment_id2,
        link_id="t3_" + thread_id2,
        permalink=f"/r/test/{thread_id2}/_/{comment_id2}/",
        subreddit="test")
    reddit.add_comment(comment2)
    comments.process_comment(comment2.get_pushshift_dict(), reddit, database)

    comment_id3 = utils.random_id()
    thread_id3 = utils.random_id()
    comment3 = reddit_test.RedditObject(
        body=f"{static.TRIGGER}! 1 day",
        author="Watchful1",
        created=utils.datetime_now(),
        id=comment_id3,
        link_id="t3_" + thread_id3,
        permalink=f"/r/test/{thread_id3}/_/{comment_id3}/",
        subreddit="test")
    reddit.add_comment(comment3)
    comments.process_comment(comment3.get_pushshift_dict(), reddit, database)

    reminders = [
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message=utils.reddit_link(comment1.permalink),
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-05 05:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message=utils.reddit_link(comment1.permalink),
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-06 05:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message=utils.reddit_link(comment1.permalink),
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-07 05:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message=utils.reddit_link(comment2.permalink),
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-08 05:00:00")),
        Reminder(
            source="https://www.reddit.com/message/messages/XXXXX",
            message=utils.reddit_link(comment2.permalink),
            user=database.get_or_add_user("Watchful1"),
            requested_date=utils.parse_datetime_string("2019-01-01 04:00:00"),
            target_date=utils.parse_datetime_string("2019-01-09 05:00:00"))
    ]
    for reminder in reminders:
        database.add_reminder(reminder)

    comments.update_comments(reddit, database)

    assert "3 OTHERS CLICKED THIS LINK" in reddit.get_comment(
        comment_id1).get_first_child().body
    assert "2 OTHERS CLICKED THIS LINK" in reddit.get_comment(
        comment_id2).get_first_child().body
    assert "CLICK THIS LINK" in reddit.get_comment(
        comment_id3).get_first_child().body