Skip to content

Commit

Permalink
Added simple testcase.
Browse files Browse the repository at this point in the history
  • Loading branch information
huntzhan committed Aug 13, 2016
1 parent 490f37e commit 1995f34
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/test_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
from __future__ import (
division, absolute_import, print_function, unicode_literals,
)
from builtins import * # noqa
from future.builtins.disabled import * # noqa

from tempfile import NamedTemporaryFile
import random
import string

import pytest

from img2url.config import load_and_check_config
from img2url.github import load_file, create_file, update_file


def random_str(n):
return ''.join(
random.SystemRandom().choice(string.ascii_uppercase)
for _ in range(n)
)


def tmpfile(content, _disable_gc=[]):
f = NamedTemporaryFile()
_disable_gc.append(f)
with open(f.name, 'w', encoding='utf-8') as _f:
_f.write(content)
return f.name


CONFIG_PATH = tmpfile('''
token: c57e63c26ca29d20352e70f7d6ccc0f039fc7727
user: img2url-testing
repo: img2url-testing-travisci
''')


def test_config():
load_and_check_config(CONFIG_PATH)

bad_path = tmpfile('''
user: img2url-testing
repo: img2url-testing-travisci
''')
with pytest.raises(RuntimeError):
load_and_check_config(bad_path)


def test_create_and_update():
config = load_and_check_config(CONFIG_PATH)

path = tmpfile(random_str(10))
assert create_file(path, config).status_code == 201

_, _, sha = load_file(path)
assert update_file(path, config, pre_sha=sha).status_code == 200

0 comments on commit 1995f34

Please sign in to comment.