-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
huntzhan
committed
Aug 13, 2016
1 parent
490f37e
commit 1995f34
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |