def test_rfc(self): import os import tempfile from admincfdi.pyutil import DescargaSAT def no_op(*args): pass seccion = self.config['rfc_emisor'] rfc_emisor = seccion['rfc_emisor'] año = seccion['año'] mes = seccion['mes'] día = seccion['día'] expected = int(seccion['expected']) descarga = DescargaSAT(status_callback=no_op, download_callback=no_op) with tempfile.TemporaryDirectory() as tempdir: destino = os.path.join(tempdir, 'cfdi-descarga') profile = descarga.get_firefox_profile(destino) descarga.connect(profile, rfc=self.rfc, ciec=self.ciec) docs = descarga.search(año=año, mes=mes, día=día, rfc_emisor=rfc_emisor) descarga.download(docs) descarga.disconnect() self.assertEqual(expected, len(os.listdir(destino)))
def test_disconnect_not_connected(self): from admincfdi.pyutil import DescargaSAT from selenium import webdriver descarga = DescargaSAT(status_callback=self.status) descarga.disconnect() self.assertEqual(0, self.status.call_count)
def test_get_firefox_profile(self): from admincfdi.pyutil import DescargaSAT from selenium import webdriver descarga = DescargaSAT() profile = descarga.get_firefox_profile('carpeta_destino') self.assertIsInstance(profile, webdriver.FirefoxProfile)
def test_search_not_connected(self): from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() descarga = DescargaSAT(status_callback=self.status) results = descarga.search(uuid='uuid') self.assertEqual(0, len(results))
def test_connect(self): from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() descarga = DescargaSAT(status_callback=self.status) profile = descarga.connect(profile, rfc='x', ciec='y') self.assertEqual(3, self.status.call_count)
def test_disconnect(self): from unittest.mock import Mock from admincfdi.pyutil import DescargaSAT from selenium import webdriver descarga = DescargaSAT(status_callback=self.status) descarga.browser = Mock() descarga.disconnect() self.assertEqual(2, self.status.call_count)
def test_search_mes_ne_día(self): from unittest.mock import MagicMock from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() descarga = DescargaSAT(status_callback=self.status) descarga.browser = MagicMock() results = descarga.search(día='01', mes='02') self.assertEqual(0, len(results))
def test_search_facturas_emitidas(self): from unittest.mock import MagicMock from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() descarga = DescargaSAT(status_callback=self.status) descarga.browser = MagicMock() results = descarga.search(facturas_emitidas=True, año=1, mes=1) self.assertEqual(0, len(results))
def test_download(self): from unittest.mock import MagicMock from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() descarga = DescargaSAT(status_callback=self.status, download_callback=self.transfer) descarga.browser = MagicMock() docs = [MagicMock()] descarga.download(docs)
def test_search_not_found_exception(self): from unittest.mock import MagicMock from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() descarga = DescargaSAT(status_callback=self.status) descarga.browser = MagicMock() c = MagicMock() descarga.browser.find_elements_by_class_name.side_effect = Exception() results = descarga.search() self.assertEqual(0, len(results))
def test_search_mes_completo_por_día(self): from unittest.mock import MagicMock, Mock from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() descarga = DescargaSAT(status_callback=self.status) descarga.browser = MagicMock() descarga._download_sat_month = Mock(return_value=[]) results = descarga.search(día='00', mes_completo_por_día=True) self.assertEqual(0, len(results))
def test_connect_fail(self): from unittest.mock import Mock from admincfdi.pyutil import DescargaSAT from admincfdi.pyutil import WebDriverWait from selenium import webdriver from selenium.common.exceptions import TimeoutException self.wait.until.side_effect = TimeoutException profile = webdriver.FirefoxProfile() descarga = DescargaSAT(status_callback=self.status) profile = descarga.connect(profile, rfc='x', ciec='y') self.assertRaises(TimeoutException)
def test_search_minuto_final_cero(self): from unittest.mock import MagicMock from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() descarga = DescargaSAT(status_callback=self.status) descarga.browser = MagicMock() results = descarga.search(día='01', mes='02', minuto_final='0') expected = "document.getElementById('ctl00_MainContent_CldFecha_DdlMinutoFin').value='0';" descarga.browser.execute_script.assert_any_call(expected)
def test_connect_fail(self): from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() def no_op(*args): pass descarga = DescargaSAT(status_callback=no_op) status = descarga.connect(profile, rfc='x', ciec='y') self.assertFalse(status) descarga.browser.close()
def test_connect_disconnect(self): from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() def no_op(*args): pass descarga = DescargaSAT(status_callback=no_op) status = descarga.connect(profile, rfc=self.rfc, ciec=self.ciec) self.assertTrue(status) descarga.disconnect()
def test_search_not_found(self): from unittest.mock import MagicMock from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() descarga = DescargaSAT(status_callback=self.status) descarga.g.SAT['found'] = 'no' descarga.browser = MagicMock() c = MagicMock() descarga.browser.find_elements_by_class_name.return_value = [c] c.get_attribute.return_value = 'x no x' c.is_displayed.return_value = True results = descarga.search() self.assertEqual(0, len(results))
def test_search_mes_eq_día(self): from unittest.mock import MagicMock from admincfdi.pyutil import DescargaSAT from selenium import webdriver profile = webdriver.FirefoxProfile() descarga = DescargaSAT(status_callback=self.status) descarga.browser = MagicMock() link = MagicMock() descarga.browser.find_elements_by_link_text.return_value = [link] combo = descarga.browser.find_element_by_id.return_value combo.get_attribute.return_value = 'sb' r = link.find_element_by_xpath.return_value p = r.find_element_by_xpath.return_value p.get_attribute.return_value = 'sb2' results = descarga.search(día='01', mes='01') self.assertEqual(0, len(results))
def test_uuid(self): import os import tempfile from admincfdi.pyutil import DescargaSAT def no_op(*args): pass seccion = self.config['uuid'] uuid = seccion['uuid'] expected = int(seccion['expected']) descarga = DescargaSAT(status_callback=no_op, download_callback=no_op) with tempfile.TemporaryDirectory() as tempdir: destino = os.path.join(tempdir, 'cfdi-descarga') profile = descarga.get_firefox_profile(destino) descarga.connect(profile, rfc=self.rfc, ciec=self.ciec) docs = descarga.search(uuid=uuid, día='00') descarga.download(docs) descarga.disconnect() self.assertEqual(expected, len(os.listdir(destino)))
def test_search_uuid(self): import os import tempfile from admincfdi.pyutil import DescargaSAT def no_op(*args): pass seccion = self.config['uuid'] uuid = seccion['uuid'] expected = int(seccion['expected']) descarga = DescargaSAT(status_callback=no_op, download_callback=no_op) profile = descarga.get_firefox_profile('destino') descarga.connect(profile, rfc=self.rfc, ciec=self.ciec) result = descarga.search(uuid=uuid, día='00') descarga.disconnect() self.assertEqual(expected, len(result))