Tests for helpers added

This commit is contained in:
JayPiKay 2019-02-03 10:30:58 +01:00
parent 1659310151
commit e021aac0bb
5 changed files with 30 additions and 12 deletions

View File

@ -25,6 +25,7 @@ def new():
basename = request.files['file'].filename
filename = '{:08x}_{}'.format(int(time.time()), basename)
try:
filename = filename.lower()
filename = image_set.save(request.files['file'], name=filename)
except UploadNotAllowed:
flash(f'Invalid filename "{filename}" (Check extension)')

View File

@ -1,15 +1,14 @@
import os
import time
from flask import current_app, g
from goatnet.mediamgr import get_image_set
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() \
in current_app.config['ALLOWED_EXTENSIONS']
def timestamp_file(filename):
tstamp = int(time.time())
username = g.user['username']
return f'{tstamp}-{username}-{filename}'
if not '.' in filename:
return False
filename = filename.lower()
extension = filename.rsplit('.', 1)[1]
image_set = get_image_set()
return image_set.extension_allowed(extension)

View File

@ -1,6 +1,3 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3
import pytest

8
tests/test_imprint.py Normal file
View File

@ -0,0 +1,8 @@
import pytest
def test_imprint(client, auth):
response = client.get('/imprint')
assert b"Home" in response.data
assert b"Imprint" in response.data
assert b"Impressum" in response.data
assert b"KTHXBYE." in response.data

View File

@ -0,0 +1,13 @@
import pytest
from goatnet.utils.helpers import allowed_file
def test_allowed_file(app):
with app.app_context():
assert allowed_file('not_allowed') is False
assert allowed_file('not_allowed.exe') is False
assert allowed_file('allowed.jpg') is True
assert allowed_file('allowed.JPEG') is True
assert allowed_file('allowed.PNG') is True
assert allowed_file('allowed.gif') is True