Esempio n. 1
0
    def bad_use_invite(self):
        initial_invite = m.UserInvite.manufacture(self.mk_user())

        # creating this user claims the invite
        m.User.from_invite(r.User(name="u2", password="******"), initial_invite.token)

        # using the invite again raise an error
        with pytest.raises(e.AlreadyUsedInvite):
            m.User.from_invite(r.User(name="u3", password="******"), initial_invite.token)

        with pytest.raises(e.NoSuchInvite):
            m.User.from_invite(r.User(name="u4", password="******"), "a-non-existent-token")
Esempio n. 2
0
 def mk_user(self, name="gdritter", password="******") -> m.User:
     return m.User.from_request(
         r.User(
             name=name,
             password=password,
         )
     )
Esempio n. 3
0
    def test_use_invite(self):
        u = self.mk_user()
        initial_invite = m.UserInvite.manufacture(u)

        assert initial_invite.claimed_by is None
        assert initial_invite.claimed_at is None

        u2 = m.User.from_invite(r.User(name="u2", password="******"), initial_invite.token)

        invite = m.UserInvite.by_code(initial_invite.token)
        assert invite.token == initial_invite.token
        assert invite.created_by.id == u.id
        assert invite.claimed_by.id == u2.id
        assert invite.created_at is not None
        assert invite.claimed_at is not None
Esempio n. 4
0
def main():
    c.app.init_db()
    m.create_tables()

    u = m.User.get_or_none(name="gdritter")
    if not u:
        u = m.User.from_request(
            r.User(
                name="gdritter",
                password=os.getenv("PASSWORD", "behest").strip(),
            ))
        u.set_as_admin()

    c.log(f"created user {u.name}")

    with open("scripts/aisamanra.json") as f:
        u.import_pinboard_data(f)