Пример #1
0
def test_static_avatar():
    # For this test we use an existing contributor with no avatar as they should be assigned one on initial load
    static_url = get_config('2020').get('contributors').get(
        'michelleoconnor').get('avatar_url')
    assert static_url is not None and static_url.startswith(
        '/static/images/avatars/')
Пример #2
0
from server.api import create_app
from server import config
from server.db import api as db_api

app = create_app(config.get_config())

with app.app_context():
    db_api.create_all()
def test_get_invalid_chapter_config():
    chapter_config = get_chapter_config(get_config('2019'), 'random')
    assert chapter_config is None
def test_get_chapter_config_hero_dir():
    chapter_config = get_chapter_config(get_config('2020'), 'jamstack')
    assert chapter_config.get('hero_dir') == '2020'
def test_get_chapter_nextprev_mid_chapter():
    nextprev = get_chapter_nextprev(get_config('2019'), 'css')
    prev_slug = nextprev[0]['slug']
    next_slug = nextprev[1]['slug']
    assert next_slug == 'markup' and prev_slug == 'javascript'
def test_get_chapter_nextprev_unknown_chapter():
    nextprev = get_chapter_nextprev(get_config('2019'), 'random')
    prev_slug = nextprev[0]
    next_slug = nextprev[1]
    assert prev_slug is None and next_slug is None
Пример #7
0
def test_get_languages_good_and_bad():
    languages = [
        str(language) for language in get_languages(get_config('2019'))
    ]
    assert 'English' in languages
    assert 'random' not in languages
    add_footnote_links, year_live, strip_accents, accentless_sort, render_template, render_error_template, \
    get_ebook_methodology, plural_ru
from server.config import get_config, SUPPORTED_LANGUAGES, SUPPORTED_YEARS, get_entries_from_json
from server.language import _Language
from server import app
from flask import request
import re
import pytest


MIN_DATE = "2019-11-01T00:00:00.000Z"

# Get all configured ebooks across all years - used to test all ebook sizes are correct later
all_ebooks = []
for year in SUPPORTED_YEARS:
    ebook_languages = get_entries_from_json(get_config(year), 'settings', 'ebook_languages')[0]
    for ebook_language in ebook_languages:
        year_lang = [ebook_language, year]
        all_ebooks.append(year_lang)


def test_render_template_success():
    with app.test_request_context():
        render_call = render_template('en/2019/index.html', lang='en', year='2019')
        # Check it's a decent size with 'Web Almanac' somewhere in there
        assert len(render_call) > 3000 and 'Web Almanac' in render_call


def test_render_template_no_chapter():
    # Note normally this would be caught by validate before render_template is called
    with app.test_request_context():
Пример #9
0
def test_get_chapters_bad_chapter():
    assert 'random' not in get_chapters(get_config('2019'))
Пример #10
0
def test_get_languages_for_all_supported_languages():
    for year in SUPPORTED_YEARS:
        for language in get_languages(get_config(year)):
            assert language in SUPPORTED_LANGUAGES[year]
Пример #11
0
def test_get_chapters_good_chapter():
    assert 'javascript' in get_chapters(get_config('2019'))
Пример #12
0
def test_get_chapters_for_all_supported_chapters():
    for year in SUPPORTED_YEARS:
        for chapter in get_chapters(get_config(year)):
            assert chapter in SUPPORTED_CHAPTERS[year]
Пример #13
0
def test_get_config_for_all_supported_years():
    for year in SUPPORTED_YEARS:
        assert get_config(year) is not None
Пример #14
0
from flask import Flask
from flask.ext.script import Manager

from server import config
from server.db.models import Book
from server.db.models import Book_library
from server.db.models import Book_store
from server.db.models import Library
from server.db.models import Store
from server.db.models import db

def create_app(config_obj):
    app = Flask(__name__)
    app.config.from_object(config_obj)
    db.init_app(app)
    return app

manager = Manager(create_app(config.get_config()))

@manager.command
def create():
    db.create_all()

if __name__ == "__main__":
    manager.run()
Пример #15
0
def test_get_config_year():
    assert get_config('2020') is not None
    assert get_config('2019') is not None
    assert get_config('2018') is None
Пример #16
0
from server.api import create_app
from server import config
from server.db import api as db_api

app = create_app(config.get_config())


with app.app_context():
    db_api.create_all()
Пример #17
0
def test_get_live_for_all_supported_years():
    for year in SUPPORTED_YEARS:
        assert get_live(get_config(year)) is True
Пример #18
0
def test_get_chapter_nextprev_1st_chapter():
    nextprev = get_chapter_nextprev(get_config('2019'), 'javascript')
    prev_slug = nextprev[0]
    next_slug = nextprev[1]['slug']
    assert next_slug == 'css' and prev_slug is None
Пример #19
0
def test_get_live_for_known_years():
    assert get_live(get_config('2019')) is True
    assert get_live(get_config('2020')) is True
Пример #20
0
def test_get_chapter_nextprev_last_chapter():
    nextprev = get_chapter_nextprev(get_config('2019'), 'http')
    prev_slug = nextprev[0]['slug']
    next_slug = nextprev[1]
    assert next_slug is None and prev_slug == 'resource-hints'
Пример #21
0
def test_get_live_for_bad_year_raises_error():
    with pytest.raises(TypeError):
        get_live(get_config('2018'))
Пример #22
0
def test_get_valid_chapter_config():
    chapter_config = get_chapter_config(get_config('2019'), 'javascript')
    assert chapter_config is not None
Пример #23
0
                      wait_fixed)

from server.config import (SRC_DIR,
                           get_config)
from server.model import (permissions,
                          users)

logging.basicConfig(level=logging.DEBUG)
_LOGGER = logging.getLogger(__name__)


DSN = "postgresql://{user}:{password}@{host}:{port}/{database}"


USER_CONFIG_PATH = SRC_DIR / 'config' / 'server.yaml'
USER_CONFIG = get_config(['-c', USER_CONFIG_PATH.as_posix()])
USER_DB_URL = DSN.format(**USER_CONFIG['postgres'])
user_engine = create_engine(USER_DB_URL)

TEST_CONFIG_PATH = SRC_DIR / 'config' / 'server-test.yaml'
TEST_CONFIG = get_config(['-c', TEST_CONFIG_PATH.as_posix()])
TEST_DB_URL = DSN.format(**TEST_CONFIG['postgres'])
test_engine = create_engine(TEST_DB_URL)

# FIXME: admin user/passwords and in sync with other host/port configs
ADMIN_DB_URL = DSN.format(
    user='******',
    password='******',
    database='postgres',
    host=USER_CONFIG['postgres']['host'],
    port=5432
Пример #24
0
def test_get_chapter_config_no_hero_dir():
    chapter_config = get_chapter_config(get_config('2020'), 'javascript')
    assert chapter_config.get('hero_dir') is None
Пример #25
0
from aiohttp import web
from server.routes import setup_routes

from server.config import get_config
from server.db import init_db, close_db


app = web.Application()
setup_routes(app)
app['config'] = get_config()

app.on_startup.append(init_db)
app.on_cleanup.append(close_db)

web.run_app(app, host='127.0.0.1', port=8080)
# web.run_app(app, host='192.168.1.138', port=8080)
Пример #26
0
from scrape import *
from server.env import EnvReader
from server.threadpool import ThreadManager, Promise
from server.persistent import PersistentDict, PersistentList
from server.client import user_tokens
from server.config import get_config

HOURLY = 60
DAILY = 60 * 24
WEEKLY = DAILY * 7
MONTHLY = DAILY * 30
ANNUALLY = DAILY * 365
BIANNUALLY = MONTHLY * 6
QUARTERLY = MONTHLY * 3

cfg = get_config('threads')
snippets = get_config('snippets')

env = EnvReader('main.py')
USER = env['BBUSER']
PASS = env['BBPASS']

print('Initializing Chronomancer...')
updater_pool = ThreadManager(cfg.get('n-scrapes'))
updater_pool.launch()
chronomancer = chronos.Chronos(updater_pool.push)
updater_pool.pushf(chronomancer.arkhomai)

Blackbaud = BlackbaudScraper()
Blackbaud.login(USER, PASS)
Sage = SageScraper()
Пример #27
0
from flask import Flask
from server.config import get_config
from server import create_app

debug = __name__ == '__main__'
config = get_config(debug)
app = create_app(config, debug)

if __name__ == '__main__':
    app.run(debug=debug, port=5000)