'Test download_result'

@patch(u'sickrage.providers.GenericProvider.download_file')
@patch(u'sickrage.providers.GenericProvider.remove_file_failed')
def test_download_file(self, remove_file_mock, df_mock):

    domain = u'domain'
    filename = u'TestFilename.nzb'
    urls = [u'http://{0}/{1}.torrentNO_DOWNLOAD_NAME'.format(domain, filename), u'http://{0}/{1}.torrent'.format(domain, filename)]
    gp1 = GenericProvider(u'Test    Provider    1')
    login_mock = MagicMock()
    login_mock.return_value = False
    with patch.object(gp1, u'login', login_mock):
        self.assertFalse(gp1.download_result(u'result    1'))
        self.assertTrue(login_mock.called)
    gp2 = GenericProvider(u'Test    Provider    2')
    make_url_mock = MagicMock()
    make_url_mock.return_value = (urls, filename)
    df_mock.return_value = True
    with patch.object(gp2, u'_make_url', make_url_mock):
        resp = gp2.download_result(u'result    2')
        self.assertTrue(resp)
        self.assertTrue((u'Referer' in gp2.headers))
        self.assertTrue((domain in gp2.headers[u'Referer']))
        self.assertTrue(df_mock.called)
    gp3 = GenericProvider(u'Test    Provider    3')
    make_url_mock = MagicMock()
    make_url_mock.return_value = (urls, filename)
    verify_download_mock = MagicMock()
    verify_download_mock.return_value = False
    df_mock.return_value = True
    with patch.object(gp3, u'_make_url', make_url_mock):
        with patch.object(gp3, u'_verify_download', verify_download_mock):
            resp = gp3.download_result(u'result    3')
            self.assertFalse(resp)
            self.assertTrue(remove_file_mock.called)
