'''Created 6 Jul 2022 Levi''' # coding: UTF-8 import platform import unittest import os import schedule from anafapi.anafoauth import Anafoauth, Efactoauth from anafapi import utils if platform.system() == 'Linux': token_file_path = '/home/deeejas/git/anafapi/anafapi/{}' elif platform.system() == 'Windows': token_file_path = 'c:/Users/levi/git/anafapi/anafapi/{}' class oauthTest(unittest.TestCase): anoauth = Anafoauth( client_id='16cbef8754bef0bcf015529353427e8a7e3ee71d56879565', client_secret='c6aa66d89002f36461f93facd990e6bf5bc706e1df897e8a7e3ee71d56879565', redirect_uri='https://www.anaf.ro/oauth2callback', ) def test_is_valid(self): self.anoauth.load_token_file(token_file_path.format('efact.json')) # print(self.anoauth.to) print(self.anoauth.is_valid) def test_browser_redirect(self): print(self.anoauth._browser_redirect()) def test_get_token(self): self.anoauth.get_token() self.anoauth.save_token(token_file_path.format('efact.json')) def test_revive_token(self): self.anoauth.load_token_file(token_file_path.format('efact.json')) self.anoauth.revive_token() self.anoauth.save_token(token_file_path.format('efact_refreshed.json')) class efactTest(unittest.TestCase): efactoauth = Efactoauth( client_id='16cbef8754bef0bcf015529353427e8a7e3ee71d56879565', client_secret='c6aa66d89002f36461f93facd990e6bf5bc706e1df897e8a7e3ee71d56879565', redirect_uri='https://www.anaf.ro/oauth2callback', ) efactoauth.load_token_file(token_file_path.format('efact.json')) efactoauth.load_session() def test_add_invoice(self): # self.efactoauth.validate_invoice('C:/Users/DECEL/FACT1/MZK/2023_06/MZK2321602.xml', env='prod') self.efactoauth.add_invoice('17259191', 'C:/Users/DECEL/FACT1/MZK/2023_06/MZK2321602.xml', env='prod') def test_transform_to_pdf(self): self.efactoauth.transform_to_pdf('C:/Users/DECEL/FACT1/MZK/2023_06/MZK2321602.xml') def test_get_all_messages(self): self.efactoauth.get_all_messages('17259191', env='prod', extract=True) def test_pretty_messages(self): self.efactoauth.pretty_messages('17259191', env='prod') def test_download_invoice(self): self.efactoauth.download_invoice('3105899770', path='C:/Users/DECEL/FACT1/MZK/2023_06', env='prod') def test_getxml_to_erp(self): # self.efactoauth.getxml_from_zip(path='../efact/3016038776.zip', dest_f='') # latest = self.efactoauth.get_latest_invoice('efact') inv_files = utils.get_not_booked('efact') for latest in inv_files: if 'booked' not in latest: inv = self.efactoauth.parse_inv(invoice=latest) print(inv.seller_party.name, inv.invoice_id, inv.issue_date.date()) # for line in inv.lines: # print(line.tax) self.efactoauth.addinvoice_tonextup(invoice=inv, kind='service', template=32, exp_plan=370, warehouse_code=80) os.rename(latest, latest.replace('.xml'.lower(), '_booked.xml')) # os.remove(latest) def test_verify_invoice(self): self.efactoauth.verify_invoice('4075641152', env='prod') def test_isvalid(self): self.efactoauth.load_token_file(token_file_path.format('efact.json')) print(self.efactoauth.is_valid) def test_get_latest_invoice(self): latest = self.efactoauth.get_latest_invoice('efact') print(latest) # os.replace(latest, latest.replace('.xml'.lower(), '_booked.xml')) def test_validate_invoice(self): # print(os.listdir('c:/Users/DECEL/FACT1/MZK/2023.01.03/')) # for file in os.listdir('c:/Users/DECEL/FACT1/MZK/2023.01.03/'): # self.efactoauth.validate_invoice(os.path.join('c:/Users/DECEL/FACT1/MZK/2023.01.03/', file)) self.efactoauth.validate_invoice('c:/Users/DECEL/FACT1/MZK/2023.01.03/MZK2415.xml') if __name__ == "__main__": # unittest.main() # efactTest().test_add_invoice() efactTest().test_get_all_messages() # anoauth = Anafoauth() # anoauth.get_token()