Skip to content

Commit 6528b9e

Browse files
committed
Work with Python 3.
1 parent b9544fb commit 6528b9e

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ __pycache__
33
.data
44
.cache
55
.coverage
6+
uploads

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: python
22
sudo: required
33
python:
4-
- "2.7"
4+
- "3.5"
55
install:
66
- pip install -r requirements.txt
77
before_script:

app.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
app = Flask(__name__)
77
app.config["UPLOAD_FOLDER"] = os.getenv("UPLOAD_FOLDER", "/usr/share/nginx/html")
88

9+
if not os.path.exists(app.config["UPLOAD_FOLDER"]):
10+
os.makedirs(app.config["UPLOAD_FOLDER"])
11+
912

1013
@app.route("/")
1114
def index():
12-
return "Hello."
15+
return "You shouldn't be here."
1316

1417

1518
@app.route("/save", methods=["POST"])
@@ -30,4 +33,5 @@ def save():
3033

3134

3235
if __name__ == "__main__":
33-
app.run(use_debugger=True, use_reloader=True, port=8000, host="0.0.0.0")
36+
port = int(os.getenv("PORT", "8000"))
37+
app.run(use_debugger=True, use_reloader=True, port=port, host="0.0.0.0")

tests/test_general.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from cStringIO import StringIO
1+
from io import BytesIO as StringIO
22
import os
33

44

@@ -12,27 +12,26 @@ def test_no_file_uploaded(self, client):
1212
assert r.status_code == 400
1313

1414
def test_missing_filename(self, client):
15-
file = StringIO("the quick brown fox jumps over the lazy dog")
15+
file = StringIO(b"the quick brown fox jumps over the lazy dog")
1616
r = client.post("/save", data=dict(file=(file, "")))
1717
assert r.status_code == 400
1818

1919
def test_save_prefix(self, client):
2020
prefix = "hello"
21-
file = StringIO("the quick brown fox jumps over the lazy dog")
22-
url = client.post(
23-
"/save", data=dict(file=(file, "hello.txt"), prefix=prefix)).data
24-
assert url[:len(prefix)] == prefix
21+
file = StringIO(b"the quick brown fox jumps over the lazy dog")
22+
url = client.post("/save", data=dict(file=(file, "hello.txt"), prefix=prefix)).data
23+
assert url[:len(prefix)].decode() == prefix
2524

2625
def test_save_suffix(self, client):
2726
suffix = "hello.txt"
28-
file = StringIO("the quick brown fox jumps over the lazy dog")
29-
url = client.post(
30-
"/save", data=dict(file=(file, "hello.txt"), suffix=suffix)).data
31-
assert url[-len(suffix):] == suffix
27+
file = StringIO(b"the quick brown fox jumps over the lazy dog")
28+
url = client.post("/save", data=dict(file=(file, "hello.txt"), suffix=suffix)).data
29+
assert url[-len(suffix):].decode() == suffix
3230

3331
def test_retrieved(self, app, client):
34-
data = "the quick brown fox jumps over the lazy dog"
32+
data = b"the quick brown fox jumps over the lazy dog"
3533
file = StringIO(data)
3634
url = client.post("/save", data=dict(file=(file, "hello.txt"))).data
37-
with open(os.path.join(app.config["UPLOAD_FOLDER"], url), "r") as f:
38-
assert f.read() == data
35+
path = os.path.join(app.config["UPLOAD_FOLDER"], url.decode())
36+
with open(path, "r") as f:
37+
assert f.read() == data.decode()

0 commit comments

Comments
 (0)