123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- '''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='82e0a1c84f2973ec23cf7f6238bb0023e996dd82b9f3a162',
- client_secret='c227aa241f3bdf49f9c978a4a152926ee850ba64371f0023e996dd82b9f3a162',
- 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='82e0a1c84f2973ec23cf7f6238bb0023e996dd82b9f3a162',
- client_secret='c227aa241f3bdf49f9c978a4a152926ee850ba64371f0023e996dd82b9f3a162',
- 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'))
- if __name__ == "__main__":
- # unittest.main()
- # efactTest().test_add_invoice()
- efactTest().test_get_all_messages()
- # anoauth = Anafoauth()
- # anoauth.get_token()
|