Esempio n. 1
0
def test_upload():
    USER = FlarumUser(forum_url=os.environ['forum_url'], username_or_email='test', password=os.environ['account_password'], extensions=[admin.AdminExtension]) # type: admin.AdminFlarumUserMixin

    # Get random birb image:
    birb_link = requests.get("https://some-random-api.ml/img/birb").json()['link']
    birb_image = requests.get(birb_link, stream=True).content

    # Upload it as avatar:
    updated_user = USER.upload_user_avatar(birb_image)
    print(updated_user.data.avatarUrl)

    # ...or for someone else:
    _user = USER.get_user_by_id(3)
    USER.upload_user_avatar(birb_image, user=_user)
    print(USER.data.id)

    # Also, why not upload it as logo?
    USER.upload_logo(birb_image)

    # Remove uploaded favicon:
    USER.remove_favicon()
    print("OK")
Esempio n. 2
0
def test_spamblock():
    USER = FlarumUser(forum_url=os.environ['forum_url'],
                      username_or_email='test',
                      password=os.environ['account_password'],
                      extensions=[
                          admin.AdminExtension,
                          FoF_Spamblock.SpamblockExtension,
                          Flarum_Suspend.SuspendExtension
                      ])
    ID_TO_BLOCK = 3

    to_block = USER.get_user_by_id(
        ID_TO_BLOCK
    )  # type: FoF_Spamblock.SpamblockUserMixin | Flarum_Suspend.SuspendUserMixin
    blocked = to_block.spamblock()
    print(f"Success: {blocked}")

    try:
        to_block.suspend(suspended_for=timedelta(minutes=15))
        print("Suspended for 15 minutes instead.")

    except FlarumError as error:
        print(f"Error: {error}")