test_anafoauth.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. '''Created 6 Jul 2022 Levi'''
  2. # coding: UTF-8
  3. import platform
  4. import unittest
  5. import os
  6. from anafapi.anafoauth import Anafoauth, Efactoauth
  7. from anafapi import utils
  8. if platform.system() == 'Linux':
  9. token_file_path = '/home/deeejas/git/anafapi/anafapi/{}'
  10. elif platform.system() == 'Windows':
  11. token_file_path = 'c:/Users/levi/git/anafapi/anafapi/{}'
  12. class oauthTest(unittest.TestCase):
  13. anoauth = Anafoauth(
  14. client_id='16cbef8754bef0bcf015529353427e8a7e3ee71d56879565',
  15. client_secret='c6aa66d89002f36461f93facd990e6bf5bc706e1df897e8a7e3ee71d56879565',
  16. redirect_uri='https://www.anaf.ro/oauth2callback',
  17. )
  18. def test_is_valid(self):
  19. self.anoauth.load_token_file(token_file_path.format('efact.json'))
  20. # print(self.anoauth.to)
  21. print(self.anoauth.is_valid)
  22. def test_browser_redirect(self):
  23. print(self.anoauth._browser_redirect())
  24. def test_get_token(self):
  25. self.anoauth.get_token()
  26. self.anoauth.save_token(token_file_path.format('efact.json'))
  27. def test_revive_token(self):
  28. self.anoauth.load_token_file(token_file_path.format('efact.json'))
  29. self.anoauth.revive_token()
  30. self.anoauth.save_token(token_file_path.format('efact_refreshed.json'))
  31. class efactTest(unittest.TestCase):
  32. efactoauth = Efactoauth(
  33. client_id='16cbef8754bef0bcf015529353427e8a7e3ee71d56879565',
  34. client_secret='c6aa66d89002f36461f93facd990e6bf5bc706e1df897e8a7e3ee71d56879565',
  35. redirect_uri='https://www.anaf.ro/oauth2callback',
  36. )
  37. efactoauth.load_token_file(token_file_path.format('efact.json'))
  38. efactoauth.load_session()
  39. def test_add_invoice(self):
  40. # self.efactoauth.validate_invoice('C:/Users/DECEL/FACT1/MZK/2023_06/MZK2321602.xml', env='prod')
  41. self.efactoauth.add_invoice('17259191', 'C:/Users/DECEL/FACT1/MZK/2023_06/MZK2321602.xml', env='prod')
  42. def test_transform_to_pdf(self):
  43. self.efactoauth.transform_to_pdf('c:/Users/DECEL/FACT1/MZK/2023_01_03/MZK2414.xml')
  44. def test_get_all_messages(self):
  45. self.efactoauth.get_all_messages('17259191', env='prod', extract=True)
  46. def test_pretty_messages(self):
  47. self.efactoauth.pretty_messages('17259191', env='prod')
  48. def test_download_invoice(self):
  49. self.efactoauth.download_invoice('3105899770', path='C:/Users/DECEL/FACT1/MZK/2023_06', env='prod')
  50. def test_getxml_to_erp(self):
  51. # self.efactoauth.getxml_from_zip(path='../efact/3016038776.zip', dest_f='')
  52. # latest = self.efactoauth.get_latest_invoice('efact')
  53. inv_files = utils.get_not_booked('efact')
  54. for latest in inv_files:
  55. if 'booked' not in latest:
  56. inv = self.efactoauth.parse_inv(invoice=latest)
  57. print(inv.seller_party.name, inv.invoice_id, inv.issue_date.date())
  58. # for line in inv.lines:
  59. # print(line.tax)
  60. self.efactoauth.addinvoice_tonextup(invoice=inv,
  61. kind='service',
  62. template=32,
  63. exp_plan=370,
  64. warehouse_code=80)
  65. os.rename(latest, latest.replace('.xml'.lower(), '_booked.xml'))
  66. # os.remove(latest)
  67. def test_verify_invoice(self):
  68. self.efactoauth.verify_invoice('4075641152', env='prod')
  69. def test_isvalid(self):
  70. self.efactoauth.load_token_file(token_file_path.format('efact.json'))
  71. print(self.efactoauth.is_valid)
  72. def test_get_latest_invoice(self):
  73. latest = self.efactoauth.get_latest_invoice('efact')
  74. print(latest)
  75. # os.replace(latest, latest.replace('.xml'.lower(), '_booked.xml'))
  76. def test_validate_invoice(self):
  77. # print(os.listdir('c:/Users/DECEL/FACT1/MZK/2023.01.03/'))
  78. # for root, dir, files in os.walk('c:/Users/DECEL/FACT1/MZK/2023_01_03/'):
  79. # for file in files:
  80. # print(file)
  81. # self.efactoauth.validate_invoice(os.path.join(root, file))
  82. self.efactoauth.validate_invoice('c:/Users/DECEL/FACT1/MZK/2023_01_03/MZK2414.xml')
  83. if __name__ == "__main__":
  84. # unittest.main()
  85. # efactTest().test_add_invoice()
  86. efactTest().test_get_all_messages()
  87. # anoauth = Anafoauth()
  88. # anoauth.get_token()