# Path: examples/anime_names.py
# ANN_REPORTS_URL = 'http://www.animenewsnetwork.com/encyclopedia/reports.xml'
# ANN_DETAILS_URL = 'http://cdn.animenewsnetwork.com/encyclopedia/api.xml'
# ANN_ANIME_RATINGS_REPORT_ID = 172
# TRAILING_KIND_RE = re.compile(r'\s+\([^)]+\)$')
# def get_top_n_shows(n):
# def _extract_item_name(item):
# def list_characters(shows):
# def _extract_anime_characters(root):
# def print_csv(field_items, fileobj=sys.stdout, fields=None):


import requests
import mocks
from examples import anime_names
# -*- coding: utf-8 -*-


def test_top_n_shows(monkeypatch):
    for report, expected in [
            (two_shows, [
                {'id': '11770', 'name': 'Steins;Gate'},
                {'id': '10216', 'name': 'Fullmetal Alchemist: Brotherhood'}]),
            (no_shows, []),
    ]:
        monkeypatch.setattr(requests, 'get', mocks.mock_get(report))
        shows = anime_names.get_top_n_shows(100)
        assert shows['items'] == expected


def test_list_characters(monkeypatch):
    for xml, expected in [
            (two_details, [
                {'anime_id': '11770', 'anime_name': 'Steins;Gate', 'name': 'Mayuri Shiina'},
                {'anime_id': '9701', 'anime_name': 'Clannad After Story', 'name': 'Fuuko Ibuki'},
            ]),
            (no_details, [])
    ]:
        monkeypatch.setattr(requests, 'get', mocks.mock_get(xml))
        shows = {
            'fields': ['show'],
            'items': [{'id': '11770'}, {'id': '10216'}],
        }

# Path: examples/anime_names.py
# ANN_REPORTS_URL = 'http://www.animenewsnetwork.com/encyclopedia/reports.xml'
# ANN_DETAILS_URL = 'http://cdn.animenewsnetwork.com/encyclopedia/api.xml'
# ANN_ANIME_RATINGS_REPORT_ID = 172
# TRAILING_KIND_RE = re.compile(r'\s+\([^)]+\)$')
# def get_top_n_shows(n):
# def _extract_item_name(item):
# def list_characters(shows):
# def _extract_anime_characters(root):
# def print_csv(field_items, fileobj=sys.stdout, fields=None):


# Path: tests/test_examples_anime_names.py
import requests
import mocks
from examples import anime_names

# -*- coding: utf-8 -*-


def test_top_n_shows(monkeypatch):
    for report, expected in [
            (two_shows, [
                {'id': '11770', 'name': 'Steins;Gate'},
                {'id': '10216', 'name': 'Fullmetal Alchemist: Brotherhood'}]),
            (no_shows, []),
    ]:
        monkeypatch.setattr(requests, 'get', mocks.mock_get(report))
        shows = anime_names.get_top_n_shows(100)
        assert shows['items'] == expected


def test_list_characters(monkeypatch):
    for xml, expected in [
            (two_details, [
                {'anime_id': '11770', 'anime_name': 'Steins;Gate', 'name': 'Mayuri Shiina'},
                {'anime_id': '9701', 'anime_name': 'Clannad After Story', 'name': 'Fuuko Ibuki'},
            ]),
            (no_details, [])
    ]:
        monkeypatch.setattr(requests, 'get', mocks.mock_get(xml))
        shows = {
            'fields': ['show'],
            'items': [{'id': '11770'}, {'id': '10216'}],
        }

        characters = anime_names.list_characters(shows)['items']