예제 #1
0
def test_follow_user():
    follower = "follower_id"
    followee = "followee_id"
    f.write_document("users", follower, {"following_users": ["some_id"]})
    assert d.follow_user(follower, followee)
    assert followee in d.get_user(follower).get("following_users")
    assert len(d.get_user(follower).get("following_users")) == 2
예제 #2
0
def send_invite(doc_id: str, to_mail: str, locale: str, user_id: str) -> None:
    user = d.get_user(user_id)
    maildef = InviteMail(to_mail, d.get_email(user_id), user["nickname"],
                         get_language(locale))
    result = mailer.sendmail(maildef)
    log.info("Sent invite %s for %s to %s -> %s", doc_id, user_id, to_mail,
             result)
예제 #3
0
    def test_register_user(self, mocker, new_invite, nickname, inviter_user):
        get_invites_mock = mocker.patch(
            "phenoback.functions.invite.register.get_invite_ids",
            return_value=[new_invite],
        )
        register.register_user(INVITEE_USER_ID, nickname)

        get_invites_mock.assert_called_once_with(INVITEE_USER_ID)
        assert (f.get_document(
            INVITE_COLLECTION,
            new_invite).get("register_user") == INVITEE_USER_ID)
        assert (f.get_document(INVITE_COLLECTION,
                               new_invite).get("register_nick") == nickname)
        assert (f.get_document(INVITE_COLLECTION,
                               new_invite).get("register_date") is not None)
        assert INVITEE_USER_ID in d.get_user(inviter_user).get(
            "following_users")
예제 #4
0
def process(doc_id: str,
            to_mail: str,
            locale: str,
            user_id: str,
            sent: datetime = None) -> bool:
    send = False
    if d.user_exists(to_mail):
        log.info(
            "Invite %s by %s to %s: User already exists, registering",
            doc_id,
            user_id,
            to_mail,
        )
        invitee_user_id = d.get_user_id_by_email(to_mail)
        invitee_nickname = d.get_user(invitee_user_id).get("nickname")
        register.register_user_invite(doc_id, invitee_user_id,
                                      invitee_nickname)
    else:
        if sent:
            delta = datetime.now().replace(tzinfo=timezone.utc) - sent
            if delta.seconds < 600:  # resent only every 10 minutes
                log.info(
                    "Invite %s by %s to %s failed: Resend time of %i seconds to short",
                    doc_id,
                    user_id,
                    to_mail,
                    delta.seconds,
                )
            else:
                send = True
        else:
            send = True

    if send:
        send_invite(doc_id, to_mail, locale, user_id)
        update_documents(doc_id, to_mail)
    else:
        clear_resend(doc_id)

    return send
예제 #5
0
def test_follow_user__no_array():
    follower = "follower_id"
    followee = "followee_id"
    f.write_document("users", follower, {"some_data": "data"})
    assert d.follow_user(follower, followee)
    assert followee in d.get_user(follower).get("following_users")