コード例 #1
0
def test_questions_for_written_answer_answered_in_range():
    """questions_for_written_answer_answered_in_range works as expected
    """
    for _start in [_random_date(datetime.datetime(2008, 1, 1), datetime.datetime(2014, 1, 1))]:
        _end = _start + datetime.timedelta(days=365)
        r = niaopendata.questions_for_written_answer_answered_in_range(_start, _end)
        _check_valid_list_response(r)
    for term in ["", "asdlkj", 21408]:
        r = niaopendata.questions_for_written_answer_answered_in_range(term, term)
        _check_invalid_list_response(r)
コード例 #2
0
def test_written_answer_html():
    """written_answer_html works as expected
    """
    for _start in [_random_date(datetime.datetime(2008, 1, 1), datetime.datetime(2014, 1, 1))]:
        _end = _start + datetime.timedelta(days=365)
        questions = niaopendata.questions_for_written_answer_answered_in_range(_start, _end)
        rand_smpl = [questions[i] for i in sorted(random.sample(range(len(questions)), 3))]
        for question in rand_smpl:
            html = niaopendata.written_answer_html(question['DocumentId'])
            # use beautifulsoup to validate that the returned string is actually HTML
            assert bool(BeautifulSoup(html, "html.parser").find())
コード例 #3
0
def test_written_answer_open_xml():
    """written_answer_open_xml works as expected
    """
    for _start in [_random_date(datetime.datetime(2008, 1, 1), datetime.datetime(2014, 1, 1))]:
        _end = _start + datetime.timedelta(days=365)
        questions = niaopendata.questions_for_written_answer_answered_in_range(_start, _end)
        rand_smpl = [questions[i] for i in sorted(random.sample(range(len(questions)), 3))]
        for question in rand_smpl:
            open_xml = niaopendata.written_answer_open_xml(question['DocumentId'])
            # use ElementTree to validate that the returned string is actually XML
            try:
                etree.fromstring(open_xml)
            except Exception as e:
                assert e is None