示例#1
0
def test_upload_keys_default_domain() -> None:
    from sxcu import SXCU

    t = SXCU()
    con = t.upload_image(file=img_loc)
    expected_keys = ["url", "del_url", "thumb"]
    assert (list(con.keys()).sort() == expected_keys.sort()
            )  # sorting because keys are arraged different
示例#2
0
def test_delete_image() -> None:

    from sxcu import SXCU

    time.sleep(60)  # to prevent overloading server
    t = SXCU()
    con = t.upload_image(file=img_loc, noembed=True)
    a = SXCU.delete_image(con["del_url"])
    assert a is True
示例#3
0
def test_upload_image_default_domain() -> None:
    import requests

    from sxcu import SXCU

    t = SXCU()
    con = t.upload_image(file=img_loc, noembed=True)

    con = requests.get(con["url"])
    assert open(img_loc, "rb") == con.content
示例#4
0
def test_upload_keys_default_domain_and_delete_image() -> None:
    time.sleep(60)

    _t = SXCU()
    con = _t.upload_file(file=IMG_LOC)
    expected_keys = ["url", "del_url", "thumb"]
    assert (list(con.keys()).sort() == expected_keys.sort()
            )  # sorting because keys are arraged different

    _a = SXCU.delete_image(con["del_url"])
    assert _a is True
示例#5
0
def test_upload_image_to_collection() -> None:
    time.sleep(60)
    t = SXCU()
    con = t.upload_file(
        file=img_loc,
        collection=collection_details["collection_id"],
        collection_token=collection_details["collection_token"],
        noembed=True,
    )

    assert con["url"].startswith("https://sxcu.net")
示例#6
0
def test_create_link() -> None:
    time.sleep(60)

    import requests

    from sxcu import SXCU

    t = SXCU()
    con = t.create_link("https://github.com/naveen521kk/sxcu")

    c = requests.get(con["url"])
    assert c.status_code == 200
示例#7
0
def test_sxcu_file_parser_no_argument() -> None:

    sxcu_file = Path(FILE_PATH, "assets", "sxcu.net - why-am-i-he.re.sxcu")
    time.sleep(120)
    t = SXCU(file_sxcu=sxcu_file)
    con = t.upload_file(file=IMG_LOC, noembed=True)

    # test domain
    assert con["url"].startswith("https://why-am-i-he.re")

    # test keys
    expected_keys = ["url", "del_url", "thumb"]
    assert list(con.keys()).sort() == expected_keys.sort()
示例#8
0
def test_sxcu_file_parser() -> None:

    sxcu_file = Path(FILE_PATH, "assets", "sxcu.net - python.is-ne.at.sxcu")
    time.sleep(60)
    _t = SXCU(file_sxcu=sxcu_file)
    con = _t.upload_file(file=IMG_LOC, noembed=True)

    # test domain
    assert con["url"].startswith("https://python.is-ne.at")

    # test keys
    expected_keys = ["url", "del_url", "thumb"]
    assert list(con.keys()).sort() == expected_keys.sort()
示例#9
0
def test_create_collections() -> None:
    time.sleep(120)
    global collection_details
    uploadInfo = {
        "title": "Python Test",
        "desc": "Testing from sxcu Python Library",
        "private": True,
    }
    a = SXCU.create_collection(unlisted=True, **uploadInfo)
    collection_details = a
    b = SXCU.collection_details(a["collection_id"])
    to_check = ["title", "desc"]
    for i in to_check:
        assert uploadInfo[i] == b[i]
示例#10
0
def test_sxcu_file_parser() -> None:
    from sxcu import SXCU

    sxcu_file = os.path.join(pathFile, "assets",
                             "sxcu.net - python.is-ne.at.sxcu")
    time.sleep(60)
    t = SXCU(file_sxcu=sxcu_file)
    con = t.upload_image(file=img_loc, noembed=True)

    # test domain
    assert con["url"].startswith("https://python.is-ne.at")

    # test keys
    expected_keys = ["url", "del_url", "thumb"]
    assert list(con.keys()).sort() == expected_keys.sort()
示例#11
0
def test_ogproperties() -> None:

    og = OGProperties(color="#000",
                      title="Some title",
                      description="A cool description!")
    con = json.dumps({
        "color": "#000",
        "title": "Some title",
        "description": "A cool description!",
        "discord_hide_url": False,
    })
    assert con == og.export()
    t = SXCU()
    a = t.upload_file(file=IMG_LOC, og_properties=og)

    assert a is not None
示例#12
0
def test_list_subdomains() -> None:
    time.sleep(60)

    b = SXCU.domain_list(1)
    req_keys = ["domain", "upload_count", "public", "img_views"]

    assert list(b[0].keys()).sort() == req_keys.sort()
示例#13
0
def test_ogproperties() -> None:
    from sxcu import SXCU, og_properties

    og = og_properties(color="#000",
                       title="Some title",
                       description="A cool description!")
    con = json.dumps({
        "color": "#000",
        "title": "Some title",
        "description": "A cool description!",
    })
    assert con == og.export()
    t = SXCU()
    a = t.upload_image(file=img_loc, og_properties=og)

    assert a is not None
示例#14
0
def test_upload_test() -> None:
    time.sleep(60)
    import requests

    from sxcu import SXCU

    b = SXCU.upload_text("Hello, from sxcu Python Library. Test.")
    con = requests.get(b["url"])

    assert con.status_code == 200
示例#15
0
def test_upload_mock(monkeypatch):
    response = json.dumps({
        "url": "https://sxcu.net/53BhgPNB1",
        "del_url":
        "https://sxcu.net/d/53BhgPNB1/81388fb6-8d20-4c8e-b256-f5472c88e062",
        "thumb": "https://sxcu.net/t/53BhgPNB1.png",
    })

    def mock_get(*args, **kwargs):
        assert "token" in kwargs["data"]
        assert kwargs["data"][
            "token"] == "b8893b47-0e90-4fce-ad46-4264161a3a72"
        return MockUploadResponse(200, response)

    monkeypatch.setattr(requests, "post", mock_get)

    sxcu_file = Path(FILE_PATH, "assets", "sxcu.net - python.is-ne.at.sxcu")
    _t = SXCU(file_sxcu=sxcu_file)
    a = _t.upload_file(IMG_LOC)
    assert json.dumps(a) == response
示例#16
0
def test_upload_text() -> None:
    time.sleep(60)

    import requests

    from sxcu import SXCU

    con = SXCU.upload_text("Testing From Python Library")

    c = requests.get(con["url"])
    assert c.status_code == 200
示例#17
0
def test_edit_collection_delete_collection() -> None:
    time.sleep(120)

    from sxcu import SXCU

    con = SXCU.edit_collection(
        collection_id=collection_details["collection_id"],
        collection_token=collection_details["collection_token"],
        delete_collection=True,
    )

    assert con["token"] is None
示例#18
0
def test_edit_collection_no_delete() -> None:
    time.sleep(120)
    from sxcu import SXCU

    con = SXCU.edit_collection(
        collection_id=collection_details["collection_id"],
        collection_token=collection_details["collection_token"],
        title="New Title",
        desc="Test Description",
        unlisted=True,
    )

    assert con["token"] is None
示例#19
0
def test_image_info() -> None:

    # upload image first
    t = SXCU()
    time.sleep(60)
    con = t.upload_file(file=IMG_LOC, noembed=True)
    details = SXCU.file_details(image_url=con["url"])

    assert con["url"] == details["url"]
    # Now try using id
    time.sleep(60)
    id_url = con["url"].split("/")[-1].split(".")[0]
    details_id = SXCU.file_details(image_id=id_url)

    assert details_id["url"] == con["url"]

    try:
        SXCU.file_details()
        assert False
    except AttributeError:
        assert True
示例#20
0
def test_sxcu_file_init_with_token():
    sxcu_file = Path(FILE_PATH, "assets", "sxcu.net - python.is-ne.at.sxcu")
    _t = SXCU(file_sxcu=sxcu_file)
    assert _t.subdomain == "https://python.is-ne.at"
    assert _t.upload_token == "b8893b47-0e90-4fce-ad46-4264161a3a72"
示例#21
0
def test_list_subdomains_all() -> None:
    b = SXCU.domain_list(-1)
    req_keys = ["domain", "upload_count", "public", "img_views"]

    assert list(b[0].keys()).sort() == req_keys.sort()
示例#22
0
def test_create_link() -> None:
    _t = SXCU()
    con = _t.create_link("https://github.com/naveen521kk/sxcu")
    _c = requests.get(con["url"])
    assert _c.status_code == 200
示例#23
0
def test_sxcu_file_init():
    sxcu_file = Path(FILE_PATH, "assets", "sxcu.net - why-am-i-he.re.sxcu")
    _t = SXCU(file_sxcu=sxcu_file)
    assert _t.subdomain == "https://why-am-i-he.re"
示例#24
0
def test_upload_text() -> None:
    b = SXCU.upload_text("Hello, from sxcu Python Library. Test.")
    con = requests.get(b["url"])

    assert con.status_code == 200
示例#25
0
def test_upload_image_default_domain() -> None:
    t = SXCU()
    con = t.upload_file(file=IMG_LOC, noembed=True)

    con = requests.get(con["url"])
    assert open(IMG_LOC, "rb") == con.content