# Path: ice/gridproviders/consolegrid_provider.py
# class ConsoleGridProvider(grid_image_provider.GridImageProvider):
#   def api_url():
#   def is_enabled():
#   def consolegrid_top_picture_url(self, rom):
#   def find_url_for_rom(self, rom):
#   def download_image(self, url):
#   def image_for_rom(self, rom):


import os
import unittest
from mockito import *
from urllib2 import URLError
from ice.gridproviders import consolegrid_provider

    rom = mock()
    rom.name = rom_name
    rom.console = console
    return rom

  def test_is_enabled_returns_true(self):
    self.assertTrue(self.provider.is_enabled())

  def test_consolegrid_top_picture_url(self):
    rom = self.create_mock_rom("Megaman")
    url = self.provider.consolegrid_top_picture_url(rom)
    self.assertIn("consolegrid.com", url)
    self.assertIn("game=Megaman", url)
    self.assertIn("console=Test", url)

  def test_consolegrid_top_picture_url_quotes_special_characters(self):
    rom = self.create_mock_rom("Dankey Kang#Country")
    url = self.provider.consolegrid_top_picture_url(rom)
    self.assertNotIn("Dankey Kang#Country", url)
    self.assertIn("Dankey%20Kang%23Country", url)

  def test_find_url_returns_none_on_204(self):
    rom = self.create_mock_rom("Megaman")
    consolegrid_provider.urllib2.urlopen = self.dummy_urlopen_function(204)
    self.assertIsNone(self.provider.find_url_for_rom(rom))

  def test_find_url_returns_none_on_urlerror(self):
    rom = self.create_mock_rom("Megaman")
    err = URLError("")

# Path: ice/gridproviders/consolegrid_provider.py
# class ConsoleGridProvider(grid_image_provider.GridImageProvider):
#   def api_url():
#   def is_enabled():
#   def consolegrid_top_picture_url(self, rom):
#   def find_url_for_rom(self, rom):
#   def download_image(self, url):
#   def image_for_rom(self, rom):


# Path: tests/consolegrid_provider_tests.py
import os
import unittest
from mockito import *
from urllib2 import URLError
from ice.gridproviders import consolegrid_provider


    rom = mock()
    rom.name = rom_name
    rom.console = console
    return rom

  def test_is_enabled_returns_true(self):
    self.assertTrue(self.provider.is_enabled())

  def test_consolegrid_top_picture_url(self):
    rom = self.create_mock_rom("Megaman")
    url = self.provider.consolegrid_top_picture_url(rom)
    self.assertIn("consolegrid.com", url)
    self.assertIn("game=Megaman", url)
    self.assertIn("console=Test", url)

  def test_consolegrid_top_picture_url_quotes_special_characters(self):
    rom = self.create_mock_rom("Dankey Kang#Country")
    url = self.provider.consolegrid_top_picture_url(rom)
    self.assertNotIn("Dankey Kang#Country", url)
    self.assertIn("Dankey%20Kang%23Country", url)

  def test_find_url_returns_none_on_204(self):
    rom = self.create_mock_rom("Megaman")
    consolegrid_provider.urllib2.urlopen = self.dummy_urlopen_function(204)
    self.assertIsNone(self.provider.find_url_for_rom(rom))

  def test_find_url_returns_none_on_urlerror(self):
    rom = self.create_mock_rom("Megaman")
    err = URLError("")

    consolegrid_provider.urllib2.urlopen = self.dummy_urlopen_function(err=err)