예제 #1
0
class NyaaTestCase(unittest.TestCase):

    nyaa_app = nyaa.create_app('config')

    def setUp(self):
        self.db, self.nyaa_app.config['DATABASE'] = tempfile.mkstemp()
        self.nyaa_app.config['TESTING'] = True
        self.app = self.nyaa_app.test_client()
        with self.nyaa_app.app_context():
            nyaa.db.create_all()

    def tearDown(self):
        os.close(self.db)
        os.unlink(self.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
예제 #2
0
    def setUpClass(cls):
        app = create_app('config')
        app.config['TESTING'] = True
        cls.app_context = app.app_context()

        # Use a seperate database for testing
        # if USE_MYSQL:
        #     cls.db_name = 'nyaav2_tests'
        #     db_uri = 'mysql://root:@localhost/{}?charset=utf8mb4'.format(cls.db_name)
        # else:
        #     cls.db_name = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'test.db')
        #     db_uri = 'sqlite:///{}?check_same_thread=False'.format(cls.db_name)

        # if not os.environ.get('TRAVIS'):  # Travis doesn't need a seperate DB
        #     app.config['USE_MYSQL'] = USE_MYSQL
        #     app.config['SQLALCHEMY_DATABASE_URI'] = db_uri

        with cls.app_context:
            cls.app = app.test_client()
예제 #3
0
This is a one-shot deal, so you'd either need to complement it
with a cron job or some binlog-reading thing (TODO)
"""
import sys
import json

# This should be progressbar33
import progressbar
from elasticsearch import Elasticsearch
from elasticsearch.client import IndicesClient
from elasticsearch import helpers

from nyaa import create_app, models
from nyaa.extensions import db

app = create_app('config')
es = Elasticsearch(timeout=30)
ic = IndicesClient(es)


def pad_bytes(in_bytes, size):
    return in_bytes + (b'\x00' * max(0, size - len(in_bytes)))


# turn into thing that elasticsearch indexes. We flatten in
# the stats (seeders/leechers) so we can order by them in es naturally.
# we _don't_ dereference uploader_id to the user's display name however,
# instead doing that at query time. I _think_ this is right because
# we don't want to reindex all the user's torrents just because they
# changed their name, and we don't really want to FTS search on the user anyway.
# Maybe it's more convenient to derefence though.