def test_review_response_wrong_argument():

    possible_arguments = [1, 1., [1, 'a'], False]

    for arg in possible_arguments:
        with assert_raises(TypeError):
            al.review_response(arg, 100, 'API')
def test_review_response_wrong_number_type():

    dictionary = {
        'a': 1,
        'entries': [{
            'key1': 1,
            'key2': 2
        }, {
            'key3': 3,
            'key4': 4
        }]
    }
    max_number = 'this is a string'

    with assert_raises(TypeError):
        al.review_response(dictionary, max_number, 'API')
def test_review_response_wrong_number_value():

    dictionary = {
        'a': 1,
        'entries': [{
            'key1': 1,
            'key2': 2
        }, {
            'key3': 3,
            'key4': 4
        }]
    }
    max_numbers = [-1, 0]

    for max_number in max_numbers:
        with assert_raises(ValueError):
            al.review_response(dictionary, max_number, 'API')
def test_review_response_wrong_feed_type():

    dictionary = {
        'a':
        1,
        'b':
        'hi',
        'entries': [{
            'noise': True,
            'title': u'Nice Title',
            'animal': 'Dog',
            'authors': [{
                'name': u'Carlo'
            }],
            'date': u'1992-05-12',
            'link': 'www.hi.com'
        }, {
            'noise': False,
            'animal': 'Frog'
        }]
    }

    with assert_raises(ValueError):
        al.review_response(dictionary, 100, 'WRONG')
def test_review_response_correct_from_link():

    link = 'http://export.arxiv.org/api/query?search_query=au:sparaciari_c+AND+ti:kullback'

    response = al.request_to_arxiv(link)
    time.sleep(3)
    parsed_response = al.parse_response(response)

    result_list = al.review_response(parsed_response, 100, 'API')

    expected_list = {
        'link':
        u'http://arxiv.org/abs/1311.6008v2',
        'authors':
        u"Carlo Sparaciari, Stefano Olivares, Francesco Ticozzi, Matteo G. A. Paris",
        'date':
        datetime.datetime.strptime(u'2013-11-23', '%Y-%m-%d'),
        'title':
        u'Exact and approximate solutions for the quantum minimum-Kullback-entropy estimation problem'
    }

    assert_equal(result_list[0], expected_list,
                 "The obtained response is different from the expected one")
def test_review_response_correct_rss():

    dictionary = {
        'a':
        1,
        'b':
        'hi',
        'entries': [{
            'noise': True,
            'title': u'This is a\n new paper. (arXiv:0000.00000v1 [cat])',
            'animal': 'Dog',
            'author':
            u'<a href="http://webpage.com/Mario">Mario Rossi</a>, <a href="http://webpage.com/Giulio">Giulio Verdi</a>, <a href="http://webpage.com/Mauro">Mauro Bianchi</a>',
            'published': u'1992-05-12T15:44:29Z',
            'link': u'www.hi.com'
        }, {
            'noise': False,
            'title':
            u'This is an old paper. (arXiv:0000.00000v1 [cat] UPDATED)',
            'animal': 'Cat',
            'author':
            u'<a href="http://webpage.com/Mario">Mario Rossi</a>, <a href="http://webpage.com/Giulio">Giulio Verdi</a>, <a href="http://webpage.com/Mauro">Mauro Bianchi</a>',
            'published': u'1992-05-12T15:44:29Z',
            'link': u'www.hello.com'
        }]
    }

    result_list = al.review_response(dictionary, 2, 'RSS')

    expected_list = [{
        'title': u'This is a new paper',
        'authors': u'Mario Rossi, Giulio Verdi, et al.',
        'link': u'www.hi.com'
    }]

    assert_equal(result_list, expected_list,
                 "The obtained response is different from the expected one")
def test_review_response_correct_api():

    dictionary = {
        'a':
        1,
        'b':
        'hi',
        'entries': [{
            'noise': True,
            'title': u'Nice Title',
            'animal': 'Dog',
            'authors': [{
                'name': u'Carlo'
            }],
            'published': u'1992-05-12T15:44:29Z',
            'link': 'www.hi.com'
        }, {
            'noise': False,
            'animal': 'Frog'
        }]
    }

    result_list = al.review_response(dictionary, 100, 'API')

    expected_list = [{
        'title':
        u'Nice Title',
        'authors':
        u'Carlo',
        'date':
        datetime.datetime.strptime(u'1992-05-12', '%Y-%m-%d'),
        'link':
        'www.hi.com'
    }]

    assert_equal(result_list, expected_list,
                 "The obtained response is different from the expected one")
def test_review_response_entries_list_no_dictionary():

    dictionary = {'a': 1, 'b': 'hi', 'entries': [1, 2, 3]}

    with assert_raises(TypeError):
        al.review_response(dictionary, 100, 'API')
def test_review_response_entries_no_list():

    dictionary = {'a': 1, 'b': 'hi', 'entries': 'this is not a list'}

    with assert_raises(TypeError):
        al.review_response(dictionary, 100, 'RSS')
def test_review_response_no_entries():

    dictionary = {'a': 1, 'b': 'hi'}

    with assert_raises(NoArgumentError):
        al.review_response(dictionary, 100, 'API')