Exemplo n.º 1
0
def test_gcis_client_init_modes(monkeypatch, capsys):
    test_user = '******'
    test_apikey = 'testkey'

    monkeypatch.setattr(__builtin__, 'raw_input', lambda u: test_user)
    monkeypatch.setattr('getpass.getpass', lambda k: test_apikey)

    #Test no args
    gcis = GcisClient()

    out, err = capsys.readouterr()
    assert gcis.base_url == 'http://data.globalchange.gov'
    assert gcis.s.auth == (test_user, test_apikey)

    #Test one arg (url) mode
    gcis = GcisClient('http://data.gcis-dev-front.joss.ucar.edu')
    assert gcis.base_url == 'http://data.gcis-dev-front.joss.ucar.edu'
    assert gcis.s.auth == (test_user, test_apikey)

    #Test invalid mode
    gcis = GcisClient('http://data.globalchange.gov', 'garbage')
    assert gcis.base_url == 'http://data.globalchange.gov'

    #assert garbage was ignored
    assert gcis.s.auth == (test_user, test_apikey)

    #Test all three args mode
    gcis = GcisClient('http://data.globalchange.gov', test_user, test_apikey)
    assert gcis.base_url == 'http://data.globalchange.gov'
    assert gcis.s.auth == (test_user, test_apikey)

    #Test trailing slash in base URL
    gcis = GcisClient('http://data.globalchange.gov/', test_user, test_apikey)
    assert gcis.base_url == 'http://data.globalchange.gov'
Exemplo n.º 2
0
def test_get_credentials_modes(monkeypatch):
    test_user = '******'
    test_apikey = 'testkey'

    monkeypatch.setattr(__builtin__, 'raw_input', lambda u: test_user)
    monkeypatch.setattr('getpass.getpass', lambda k: test_apikey)

    #Test environment variable mode
    monkeypatch.setenv('GCIS_USER', '*****@*****.**')
    monkeypatch.setenv('GCIS_KEY', 'env.apikey')
    assert getenv('GCIS_USER') == '*****@*****.**'

    #Force __init__ to reread mock env variables
    reload(gcis_clients)

    gcis = GcisClient('http://data.globalchange.gov')
    assert gcis.base_url == 'http://data.globalchange.gov'
    assert gcis.s.auth == ('*****@*****.**', 'env.apikey')
Exemplo n.º 3
0
from gcis_clients import Nca3Client, GcisClient, gcis_stage_auth, gcis_dev_auth
import pickle
import json
import requests
import bs4
from bs4 import BeautifulSoup

nca3_url = 'https://nca3.cicsnc.org'
nca3 = Nca3Client(nca3_url,
                  'andrew.buddenberg',
                  'Nz9O^00I',
                  http_basic_user='******',
                  http_basic_pass='******')

gcis_url = 'https://data-stage.globalchange.gov'
gcis = GcisClient(gcis_url, *gcis_stage_auth)
# gcis = GcisClient('http://data.gcis-dev-front.joss.ucar.edu', *gcis_dev_auth)


def main():
    print gcis.test_login()
    for idx, list_item in enumerate([
            i for i in sorted(nca3.get_all_captions().json(),
                              key=lambda f: f['Ordinal'])
            if i['Ordinal'] and i['Metadata URI'] and i['Caption']
    ]):
        ordinal = list_item['Ordinal']
        gcis_fig_id = list_item['Metadata URI'].split('/')[-1]

        stripped_caption = strip_tags(list_item['Caption']['value'])
Exemplo n.º 4
0
__author__ = 'abuddenberg'

from gcis_clients import GcisClient, SurveyClient, survey_token, gcis_dev_auth, gcis_stage_auth
from gcis_clients.domain import Report, Chapter
from sync_utils import realize_parents, realize_contributors

from collections import OrderedDict

import pickle
import sys

gcis = GcisClient('http://data.gcis-dev-front.joss.ucar.edu', *gcis_dev_auth)
# gcis = GcisClient('https://data-stage.globalchange.gov', *gcis_stage_auth)

surveys = SurveyClient('https://healthresources.cicsnc.org', survey_token)

sync_metadata_tree = {
    'usgcrp-climate-human-health-assessment-2016':
    OrderedDict([
        ('front-matter', [
            ('/metadata/figures/3931',
             'understanding-the-exposure-pathway-diagrams'),
        ]),
        ('executive-summary',
         [('/metadata/figures/3906',
           'examples-of-climate-impacts-on-human-health'),
          ('/metadata/figures/3832', 'es-climate-change-and-health'),
          ('/metadata/figures/3833',
           'es-projected-changes-in-deaths-in-us-cities-by-season'),
          ('/metadata/figures/3834',
           'es-projected-change-in-temperature-ozone-and-ozone-related-premature-deaths-in-2030'
Exemplo n.º 5
0
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

from gcis_clients import GcisClient, SurveyClient, survey_token, gcis_dev_auth, gcis_stage_auth
from domain import Report, Chapter
from sync_utils import realize_parents, realize_contributors
from states import sync_metadata_tree

import pickle
import sys
import re
import traceback

# gcis = GcisClient('https://data-stage.globalchange.gov', *gcis_stage_auth)
gcis = GcisClient('https://data-review.globalchange.gov', *gcis_stage_auth)
surveys = SurveyClient('https://state-resources.cicsnc.org', survey_token)


def main():
    print(gcis.test_login())

    cssr = Report({
        'identifier': 'climate-science-special-report',
        'report_type_identifier': 'report',
        'title': 'Climate Science Special Report',
        # 'url': 'https://statesummaries.cicsnc.org/',
        'publication_year': '2017',
        'contact_email': ''
    })