Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
Change some Readme and add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
naveen521kk committed Sep 19, 2020
1 parent ee7400e commit adf286e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 32 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[![PyPI Version](https://img.shields.io/pypi/v/scxu)](https://pypi.org/project/scxu/)
[![PyPI Version](https://img.shields.io/pypi/v/sxcu)](https://pypi.org/project/scxu/)
[![Python Versions](https://img.shields.io/pypi/pyversions/scxu)](https://pypi.org/project/scxu/)
[![Python Wheel](https://img.shields.io/pypi/wheel/scxu)](https://pypi.org/project/scxu/)
[![License](https://img.shields.io/badge/License-Apache2.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
[![Code Style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Code Quality: flake8](https://img.shields.io/badge/code%20quality-flake8-000000.svg)](https://gitlab.com/pycqa/flake8)

# scxu
Python API wraper for scxu.net
# SXCU
Python API wraper for sxcu.net. Pretty much everything is explained in `doc strings` and soon I will create a tutorial on how to use it.

## Contributing
Please refer to [CONTRIBUTING.md](CONTRIBUTING.md) file for more information on how to
Expand Down
31 changes: 26 additions & 5 deletions sxcu/sxcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
# token=d6208525-a58a-4b91-8dc3-bcb7ad086445
# dom=pls.click-if-you-da.re

__all__=["og_properties","SXCU"]
__all__ = ["og_properties", "SXCU"]


class og_properties(object):
def __init__(self, color=None, description=None, title=None):
self.color = color
Expand Down Expand Up @@ -202,9 +204,28 @@ def domain_list(count: int = -1):
else:
toEncode = con.json()[:count]
for i in range(len(toEncode)):
temp={}
temp = {}
for j in toEncode[i]:
if type(toEncode[i][j])==str:
temp[j]=toEncode[i][j].encode()
toEncode[i]=temp
if type(toEncode[i][j]) == str:
temp[j] = toEncode[i][j].encode()
toEncode[i] = temp
return toEncode

@staticmethod
def delete_image(delete_url: str):
"""Deletes images from sxcu.net
Parameters
==========
delete_url : :class:`str`
The delete URL returned from sxcu.net while uploading.
Returns
=======
:class:`bool`
Deleted or not
"""
con = requests.get(delete_url)
if con.status_code == 200:
return True
else:
return False
71 changes: 47 additions & 24 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,63 @@
import json
import os
import pytest
import time

def test_ogproperties():
from sxcu import 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()

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()


def test_upload_keys_default_domain():
from sxcu import SXCU
pathFile=os.path.dirname(os.path.abspath(__file__))
img_loc=os.path.join(pathFile,"assets","glen-ardi-ljXFGnvmlno-unsplash.jpg")
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

@pytest.mark.xfail(reason="sxcu optimises images")

pathFile = os.path.dirname(os.path.abspath(__file__))
img_loc = os.path.join(pathFile, "assets", "glen-ardi-ljXFGnvmlno-unsplash.jpg")
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


@pytest.mark.xfail(run=False,reason="sxcu optimises images")
def test_upload_image_default_domain():
from sxcu import SXCU
import requests
pathFile=os.path.dirname(os.path.abspath(__file__))
img_loc=os.path.join(pathFile,"assets","yoonjae-baik-F8ZR9BmWD3E-unsplash.jpg")

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

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

pathFile = os.path.dirname(os.path.abspath(__file__))
img_loc = os.path.join(pathFile, "assets", "yoonjae-baik-F8ZR9BmWD3E-unsplash.jpg")

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

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



# TODO: Test subdomains


def test_delete_image():
from sxcu import SXCU
import requests

pathFile = os.path.dirname(os.path.abspath(__file__))
img_loc = os.path.join(pathFile, "assets", "yoonjae-baik-F8ZR9BmWD3E-unsplash.jpg")
time.sleep(30) #to prevent overloading server
t = SXCU()
con = t.upload_image(file=img_loc, noembed=True)
a=SXCU.delete_image(con["del_url"])
assert a==True

0 comments on commit adf286e

Please sign in to comment.