Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
added tests, added default get values, SECRET and PUBLIC from environ…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
Sergey Ozeranskiy committed Jul 13, 2019
1 parent 4bfbdc7 commit d180d3c
Show file tree
Hide file tree
Showing 9 changed files with 458 additions and 76 deletions.
3 changes: 2 additions & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ line_length = 119
multi_line_output = 3
sections = FUTURE, STDLIB, THIRDPARTY, FIRSTPARTY, LOCALFOLDER
include_trailing_comma = True
skip_glob = .git, *docs*, media, static, *venv*
skip_glob = .git, *docs*, *venv*
known_third_party = requests_mock
import_heading_stdlib = Standard libraries
import_heading_firstparty = Project
import_heading_thirdparty = Third party libraries
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ sphinx = "*"
sphinx_rtd_theme = "*"
isort = "*"
bump2version = "*"
requests_mock = "*"
python-coveralls = "*"

[packages]
requests = "*"
dataclasses-json = "*"
python-coveralls = "*"

[requires]
python_version = "3.7"
98 changes: 34 additions & 64 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![PyPI](https://img.shields.io/pypi/v/tilda-wrapper-api.svg) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/tilda-wrapper-api.svg) ![PyPI - License](https://img.shields.io/pypi/l/tilda-wrapper-api.svg) ![PyPI - Format](https://img.shields.io/pypi/format/tilda-wrapper-api.svg) ![PyPI - Status](https://img.shields.io/pypi/status/tilda-wrapper-api.svg)
![PyPI](https://img.shields.io/pypi/v/tilda-wrapper-api.svg) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/tilda-wrapper-api.svg) ![PyPI - License](https://img.shields.io/pypi/l/tilda-wrapper-api.svg) ![PyPI - Format](https://img.shields.io/pypi/format/tilda-wrapper-api.svg) ![PyPI - Status](https://img.shields.io/pypi/status/tilda-wrapper-api.svg) [![Coverage Status](https://coveralls.io/repos/github/ozeranskiy/tilda_wrapper_api/badge.svg)](https://coveralls.io/github/ozeranskiy/tilda_wrapper_api)

# Tilda API

Expand Down Expand Up @@ -31,8 +31,8 @@ import os
# Project
from tilda_wrapper_api.client import Client

# create a client object
client = Client(secret=os.getenv('SECRET'), public=os.getenv('PUBLIC'))
# create a client object, default value secret=os.getenv('SECRET') and public=os.getenv('PUBLIC')
client = Client()

# get list of projects
projects = client.get_projects_list()
Expand Down
7 changes: 2 additions & 5 deletions examples/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Standard libraries
import os

# Project
from tilda_wrapper_api.client import Client

Expand All @@ -11,8 +8,8 @@ def run() -> None:
:return:
"""

# create a client object
client = Client(secret=os.getenv('SECRET'), public=os.getenv('PUBLIC'))
# create a client object, default value secret=os.getenv('SECRET') and public=os.getenv('PUBLIC')
client = Client()

# get list of projects
projects = client.get_projects_list()
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'isort',
'mock',
'nose',
'requests_mock',
'coverage',
'tox',
'sphinx',
Expand Down
127 changes: 127 additions & 0 deletions tests/test-dataclasses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Project
from tests.base import TestCase
from tilda_wrapper_api.dataclasses.exceptions import TildaError
from tilda_wrapper_api.dataclasses.page import Pages, SinglePage
from tilda_wrapper_api.dataclasses.project import Projects, SingleProject


class DataclassesTest(TestCase):

def test_exception(self) -> None:
error_dict = {
'status': 'ERROR',
'message': 'Wrong public key',
'errorside': 'info'
}

exception_class = TildaError.from_dict(error_dict)
self.assertEqual(exception_class.to_dict(), error_dict)
self.assertEqual(str(exception_class), exception_class.message)

def test_projects(self) -> None:
projects_dict = {
'status': 'FOUND',
'result': [{
'id': '0000000',
'title': 'Title',
'descr': 'Description',
'export_csspath': '',
'export_jspath': '',
'export_imgpath': '',
'indexpageid': None,
'htaccess': '',
'customdomain': '',
'images': [],
'css': [],
'js': []
}]
}

projects_class = Projects.from_dict(projects_dict)
self.assertEqual(projects_class.to_dict(), projects_dict)

def test_single_project(self) -> None:
project_dict = {
'status': 'FOUND',
'result': {
'id': '0000000',
'title': 'Title',
'descr': 'Description',
'export_csspath': '',
'export_jspath': '',
'export_imgpath': '',
'indexpageid': None,
'htaccess': '',
'customdomain': '',
'images': [],
'css': [
'https://static.tildacdn.com/css/main.css',
],
'js': [
'https://static.tildacdn.com/js/main.js',
]
}
}

project_class = SingleProject.from_dict(project_dict)
self.assertEqual(project_class.to_dict(), project_dict)

def test_pages(self) -> None:
pages_dict = {
'status': 'FOUND',
'result': [{
'id': '0000000',
'projectid': '0000000',
'title': 'Landing 1',
'descr': '',
'img': '',
'featureimg': '',
'alias': '',
'date': '2019-06-15 17:32:09',
'sort': '10',
'published': '1561875543',
'filename': 'page0000000.html',
'html': '',
'images': []
}, {
'id': '0000001',
'projectid': '0000000',
'title': 'Landing 2',
'descr': '',
'img': '',
'featureimg': '',
'alias': 'landing2',
'date': '2019-06-26 08:19:46',
'sort': '20',
'published': '1562070685',
'filename': 'page0000001.html',
'html': '',
'images': []
}]
}

pages_class = Pages.from_dict(pages_dict)
self.assertEqual(pages_class.to_dict(), pages_dict)

def test_single_page(self) -> None:
page_dict = {
'status': 'FOUND',
'result': {
'id': '0000000',
'projectid': '0000000',
'title': 'Landing 1',
'descr': '',
'img': '',
'featureimg': '',
'alias': '',
'date': '2019-06-15 17:32:09',
'sort': '10',
'published': '1561875543',
'filename': 'page0000000.html',
'html': '<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>',
'images': []
},
}

page_class = SinglePage.from_dict(page_dict)
self.assertEqual(page_class.to_dict(), page_dict)
Loading

0 comments on commit d180d3c

Please sign in to comment.