Пример #1
0
def run(team: str,
        src_dir: str,
        build_dir: str,
        year=date.today().year,
        silence_warnings=False,
        poster_mode=False):
    '''
    Runs iGEM-WikiSync and uploads all files to iGEM servers
    while replacing relative URLs with those on the iGEM server.

    Mandatory Arguments:
        team: iGEM Team Name
        src_dir: Path to the folder where the source files are present
        build_dir: Path to the folder where the built files will be stored before uploading

    Optional Arguments:
        year: Subdomain for igem.org. Current year by default.
        silence_warnings: Broken link warnings are not printed to console if true. The log still contains everything.
        poster_mode: Run WikiSync in poster mode.
            * Renames files to T--[TeamName]--Poster_[filename].extension
            * Adds the poster template the HTML file
            * Fails if any other HTML/CSS/JS file is provided

    Returns:
        1: Incorrect input in function call.
        2: Connection problem.
        3: Invalid upload map.
        4: Failed to write/upload file.
    '''

    # * 1. CHECK AND FORMAT INPUTS
    if team is None or not isinstance(team, str):
        logger.critical('Please specify your team name.')
        sys.exit(1)

    if src_dir is None or not isinstance(src_dir, str):
        logger.critical('Please specify where your code is stored ' +
                        'using the src_dir argument.')
        sys.exit(1)

    if build_dir is None or not isinstance(build_dir, str):
        logger.critical(
            'Please specify where your code should be temporarily stored ' +
            'using the build_dir argument.')
        sys.exit(1)

    if not isinstance(year, int) or len(str(year)) > 4:
        logger.critical('Year should be a four digit integer.')
        sys.exit(1)

    if not isinstance(silence_warnings, bool):
        logger.critical('silence_warnings must have a boolean value.')
        sys.exit(1)

    config = {
        'team': team,
        'src_dir': src_dir,
        'build_dir': build_dir,
        'year': str(year),
        'silence_warnings': silence_warnings,
        'poster_mode': poster_mode
    }

    # * 2. Load or create upload_map
    upload_map = get_upload_map()

    # * 3. Create build directory
    if not os.path.isdir(build_dir):
        os.mkdir(build_dir)
        # ? error handling here?

    # * 4. Get iGEM credentials from environment variables
    credentials = {
        'username': os.environ.get('IGEM_USERNAME'),
        'password': os.environ.get('IGEM_PASSWORD')
    }

    # * 5. Load/create cookie file
    browser, cookiejar = get_browser_with_cookies()

    # * 6. Login to iGEM
    login = iGEM_login(browser, credentials, config)
    if not login:
        message = 'Failed to login.'
        logger.critical(message)
        sys.exit(2)

    # # * 7. Save cookies
    # # TODO: check if this works, might not
    # cookiejar.save()

    # * 8. Cache files
    files = cache_files(upload_map, config)

    # * 9. Upload all assets and create a map
    uploaded_assets = upload_and_write_assets(files['other'], browser,
                                              upload_map, config)

    # * 10. write upload map just in case
    # things go wrong while dealing with code
    write_upload_map(upload_map)

    # * 11. Build files and upload changed files
    uploaded_code = build_and_upload(files, browser, config, upload_map)

    # * 12. Write final upload map
    write_upload_map(upload_map)

    print_summary(uploaded_assets, uploaded_code)
Пример #2
0
def test_check_login_after(credentials, config, caplog):
    # Check that once we're logged in, it doesn't login again
    assert iGEM_login(pytest.browser, credentials, config)
    assert 'Already logged in' in caplog.text
Пример #3
0
def test_iGEM_login_invalid_password(credentials, config, caplog):
    credentials['password'] = '******'

    browser = mechanicalsoup.StatefulBrowser()
    assert not iGEM_login(browser, credentials, config)
    assert 'the password is not' in caplog.text
Пример #4
0
def test_iGEM_login(credentials, config, caplog):
    # Login for the first time
    assert iGEM_login(pytest.browser, credentials, config)
    assert 'Successfully logged in' in caplog.text
Пример #5
0
def test_iGEM_login_invalid_username(credentials, config, caplog):
    credentials['username'] = '******'

    browser = mechanicalsoup.StatefulBrowser()
    assert not iGEM_login(browser, credentials, config)
    assert 'username is invalid' in caplog.text