diff --git a/.travis.yml b/.travis.yml index f5fcb2b..3915f25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,17 +2,29 @@ language: python python: "3.6" -dist: xenial -sudo: false +dist: trusty +sudo: required matrix: fast_finish: true 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: email: false diff --git a/README.md b/README.md index 7ef3410..ac9667f 100644 --- a/README.md +++ b/README.md @@ -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 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 - 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 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 diff --git a/lint.sh b/lint.sh index 2152765..46c1660 100755 --- a/lint.sh +++ b/lint.sh @@ -49,3 +49,5 @@ if [[ ${action} == check_lint ]]; then echo "The code requires some changes." fi fi + +if [[ ${result} -ne 0 ]]; then exit 1; fi diff --git a/nyaa/__init__.py b/nyaa/__init__.py index 9ef9bfb..cb406aa 100644 --- a/nyaa/__init__.py +++ b/nyaa/__init__.py @@ -70,4 +70,4 @@ assets = Environment(app) # output='style.css', depends='**/*.scss') # assets.register('style_all', css) -from nyaa import routes # noqa +from nyaa import routes # noqa E402 diff --git a/nyaa/api_handler.py b/nyaa/api_handler.py index 7e17745..bbbd845 100644 --- a/nyaa/api_handler.py +++ b/nyaa/api_handler.py @@ -322,7 +322,11 @@ def v2_api_info(torrent_id_or_hash): 'information': torrent.information, '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, 'files': files, diff --git a/requirements.txt b/requirements.txt index 705ed83..de79b62 100644 --- a/requirements.txt +++ b/requirements.txt @@ -29,10 +29,12 @@ orderedset==2.0 packaging==16.8 passlib==1.7.1 progressbar33==2.4 +py==1.4.34 pycodestyle==2.3.1 pycparser==2.17 PyMySQL==0.7.11 pyparsing==2.2.0 +pytest==3.1.1 python-dateutil==2.6.0 python-editor==1.0.3 python-utils==2.1.0 diff --git a/tests/test_nyaa.py b/tests/test_nyaa.py new file mode 100644 index 0000000..9a81330 --- /dev/null +++ b/tests/test_nyaa.py @@ -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() diff --git a/utils/api_info.py b/utils/api_info.py index acff5d7..2f3de9e 100755 --- a/utils/api_info.py +++ b/utils/api_info.py @@ -112,7 +112,8 @@ if __name__ == '__main__': exit(1) else: 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, flag_info=flag_info, **response)