示例#1
0
  def test_read_file_exists(self):
    uri = 'http://www.jeuxvideo.com/'
    filename = _url_to_filename(uri)
    path = os.path.join(CACHEDIR, filename)
    expected = '{data}'

    # mock open with some data and check it was called
    with patch('franck.io.cache.open', mock_open(read_data=expected), create=True) as m:
      actual = read(uri)
      m.assert_called_once_with(path)
      self.assertEqual(actual, expected)
示例#2
0
  def test_write_file(self):
    uri = 'http://www.jeuxvideo.com/'
    filename = _url_to_filename(uri)
    path = os.path.join(CACHEDIR, filename)
    expected = '{data}'

    # mock open with some data and check it was called
    with patch('franck.io.cache.open', mock_open(read_data=expected), create=True) as m:
      write(uri, expected)
      m.assert_called_once_with(path, 'w+')
      handle = m()
      handle.write.assert_called_once_with(expected)
示例#3
0
 def test_url_to_filename_homepage(self):
   expected = 'http%3A%2F%2Fwww.jeuxvideo.com%2F'
   actual = _url_to_filename('http://www.jeuxvideo.com/')
   self.assertEqual(actual, expected)
示例#4
0
 def test_url_to_filename_normal_url(self):
   expected = 'toutes-les-videos%2Fmachine-10%2Fgenre-2240%2F'
   actual = _url_to_filename('http://www.jeuxvideo.com/toutes-les-videos/machine-10/genre-2240/')
   self.assertEqual(actual, expected)