Merge pull request #251 from sharkykh/tests

INITIAL UNIT TESTING FUCK YEAH
This commit is contained in:
Johnny Ding 2017-06-07 23:27:53 -07:00 committed by GitHub
commit ffb2cdec5f
8 changed files with 87 additions and 8 deletions

View File

@ -2,17 +2,29 @@ language: python
python: "3.6" python: "3.6"
dist: xenial dist: trusty
sudo: false sudo: required
matrix: matrix:
fast_finish: true fast_finish: true
cache: pip cache: pip
install: pip install --upgrade pycodestyle services:
mysql
script: ./lint.sh --check before_install:
- mysql -u root -e 'CREATE DATABASE nyaav2 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;'
install:
- pip install -r requirements.txt
- sed "s/mysql:\/\/test:test123@/mysql:\/\/root:@/" config.example.py > config.py
- python db_create.py
- ./db_migrate.py stamp head
script:
- python -m pytest tests/
- ./lint.sh --check
notifications: notifications:
email: false email: false

View File

@ -1,4 +1,4 @@
# NyaaV2 # NyaaV2 [![Build Status](https://travis-ci.org/nyaadevs/nyaa.svg?branch=master)](https://travis-ci.org/nyaadevs/nyaa)
## Setting up for development ## Setting up for development
This project uses Python 3.6. There are features used that do not exist in 3.5, so make sure to use Python 3.6. This project uses Python 3.6. There are features used that do not exist in 3.5, so make sure to use Python 3.6.
@ -10,6 +10,11 @@ It's not impossible to run Nyaa on Windows, but this guide doesn't focus on that
- You may also use `./lint.sh -c` to see a list of warnings/problems instead of having `lint.sh` making modifications for you - You may also use `./lint.sh -c` to see a list of warnings/problems instead of having `lint.sh` making modifications for you
- Other than PEP8, try to keep your code clean and easy to understand, as well. It's only polite! - Other than PEP8, try to keep your code clean and easy to understand, as well. It's only polite!
### Running Tests
We have some basic tests that check if each page can render correctly. To run the tests:
- Make sure that you are in the python virtual environment.
- Run `python -m pytest tests/` while in the repository directory.
### Setting up Pyenv ### Setting up Pyenv
pyenv eases the use of different Python versions, and as not all Linux distros offer 3.6 packages, it's right up our alley. pyenv eases the use of different Python versions, and as not all Linux distros offer 3.6 packages, it's right up our alley.
- Install dependencies https://github.com/pyenv/pyenv/wiki/Common-build-problems - Install dependencies https://github.com/pyenv/pyenv/wiki/Common-build-problems

View File

@ -49,3 +49,5 @@ if [[ ${action} == check_lint ]]; then
echo "The code requires some changes." echo "The code requires some changes."
fi fi
fi fi
if [[ ${result} -ne 0 ]]; then exit 1; fi

View File

@ -70,4 +70,4 @@ assets = Environment(app)
# output='style.css', depends='**/*.scss') # output='style.css', depends='**/*.scss')
# assets.register('style_all', css) # assets.register('style_all', css)
from nyaa import routes # noqa from nyaa import routes # noqa E402

View File

@ -322,7 +322,11 @@ def v2_api_info(torrent_id_or_hash):
'information': torrent.information, 'information': torrent.information,
'description': torrent.description, 'description': torrent.description,
'stats': {'seeders': torrent.stats.seed_count, 'leechers': torrent.stats.leech_count, 'downloads': torrent.stats.download_count}, 'stats': {
'seeders': torrent.stats.seed_count,
'leechers': torrent.stats.leech_count,
'downloads': torrent.stats.download_count
},
'filesize': torrent.filesize, 'filesize': torrent.filesize,
'files': files, 'files': files,

View File

@ -29,10 +29,12 @@ orderedset==2.0
packaging==16.8 packaging==16.8
passlib==1.7.1 passlib==1.7.1
progressbar33==2.4 progressbar33==2.4
py==1.4.34
pycodestyle==2.3.1 pycodestyle==2.3.1
pycparser==2.17 pycparser==2.17
PyMySQL==0.7.11 PyMySQL==0.7.11
pyparsing==2.2.0 pyparsing==2.2.0
pytest==3.1.1
python-dateutil==2.6.0 python-dateutil==2.6.0
python-editor==1.0.3 python-editor==1.0.3
python-utils==2.1.0 python-utils==2.1.0

53
tests/test_nyaa.py Normal file
View File

@ -0,0 +1,53 @@
import os
import unittest
import tempfile
import nyaa
class NyaaTestCase(unittest.TestCase):
def setUp(self):
self.db, nyaa.app.config['DATABASE'] = tempfile.mkstemp()
nyaa.app.config['TESTING'] = True
self.app = nyaa.app.test_client()
with nyaa.app.app_context():
nyaa.db.create_all()
def tearDown(self):
os.close(self.db)
os.unlink(nyaa.app.config['DATABASE'])
def test_index_url(self):
rv = self.app.get('/')
assert b'Browse :: Nyaa' in rv.data
assert b'Guest' in rv.data
def test_upload_url(self):
rv = self.app.get('/upload')
assert b'Upload Torrent' in rv.data
assert b'You are not logged in, and are uploading anonymously.' in rv.data
def test_rules_url(self):
rv = self.app.get('/rules')
assert b'Site Rules' in rv.data
def test_help_url(self):
rv = self.app.get('/help')
assert b'Using the Site' in rv.data
def test_rss_url(self):
rv = self.app.get('/?page=rss')
assert b'/xmlns/nyaa' in rv.data
def test_login_url(self):
rv = self.app.get('/login')
assert b'Username or email address' in rv.data
def test_registration_url(self):
rv = self.app.get('/register')
assert b'Username' in rv.data
assert b'Password' in rv.data
if __name__ == '__main__':
unittest.main()

View File

@ -112,7 +112,8 @@ if __name__ == '__main__':
exit(1) exit(1)
else: else:
formatted_filesize = easy_file_size(response.get('filesize', 0)) formatted_filesize = easy_file_size(response.get('filesize', 0))
flag_info = ', '.join(n+': '+_as_yes_no(response['is_'+n.lower()]) for n in FLAG_NAMES) flag_info = ', '.join(
n + ': ' + _as_yes_no(response['is_' + n.lower()]) for n in FLAG_NAMES)
info_str = INFO_TEMPLATE.format(formatted_filesize=formatted_filesize, info_str = INFO_TEMPLATE.format(formatted_filesize=formatted_filesize,
flag_info=flag_info, **response) flag_info=flag_info, **response)