Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
yurnov committed Jul 19, 2024
1 parent eee204b commit 0730869
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install linters
run: |
python -m pip install black==24.3.0
python -m pip install black~=24.4
- name: Lint Python code with black
run: |
Expand All @@ -41,4 +41,5 @@ jobs:
- name: Run tests
run: |
cd app
python test.py
pwd
python test_qrgen.py
Binary file added app/__pycache__/qrgen.cpython-310.pyc
Binary file not shown.
Binary file added app/qr_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions app/qrgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import argparse


def create_qr(account, edrpo, recipient, amount, purpose):
def create_qr(account, edrpo, recipient, amount, purpose, output_file):
# Construct the data string for version 002 of QR code, reference https://bank.gov.ua/ua/legislation/Resolution_01022021_11
# Elements of string are separated by LF (line feed) character:
# 1. Empty element without any separator
Expand Down Expand Up @@ -32,11 +32,12 @@ def create_qr(account, edrpo, recipient, amount, purpose):

# Generate the QR code
qr = qrcode.make(qr_url)
qr.save("/output/qr_code.png")
qr.save(output_file)

# return the URL, it's used for testing
return qr_url


def main():

parser = argparse.ArgumentParser(description="Generate a QR code for a Ukrainian payment")
Expand Down Expand Up @@ -77,7 +78,9 @@ def main():
purpose = input("Enter the purpose of the payment: ")

# Create QR code
create_qr(account, edrpo, recipient, amount, purpose)
output_file = "/output/qr_code.png"
create_qr(account, edrpo, recipient, amount, purpose, output_file)


if __name__ == "__main__":
main()
main()
7 changes: 5 additions & 2 deletions app/test_qrgen.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import unittest
from qrgen import create_qr


class TestCreateQR(unittest.TestCase):
def test_create_qr(self):
account = "UA683052990000026004026814882"
edrpo = "44327069"
recipient = "ОСББ ТРИПІЛЛЯ-ПАТРІОТИКА"
amount = "UAH3000.00"
purpose = "Добровільний внесок на генератор, квартира XXX"
output_file = "/workspaces/payment-qr-generator/app/qr_code.png"
test_url = "https://bank.gov.ua/qr/QkNCCjAwMgoxClVDVAoK0J7QodCR0JEg0KLQoNCY0J_QhtCb0JvQry3Qn9CQ0KLQoNCG0J7QotCY0JrQkApVQTY4MzA1Mjk5MDAwMDAyNjAwNDAyNjgxNDg4MgpVQUgzMDAwLjAwCjQ0MzI3MDY5CgoK0JTQvtCx0YDQvtCy0ZbQu9GM0L3QuNC5INCy0L3QtdGB0L7QuiDQvdCwINCz0LXQvdC10YDQsNGC0L7RgCwg0LrQstCw0YDRgtC40YDQsCBYWFgK"

# Call the function
url = create_qr(account, edrpo, recipient, amount, purpose)
url = create_qr(account, edrpo, recipient, amount, purpose, output_file)

# Assert that the QR code is generated successfully
self.assertEqual(url, test_url)

# You can add additional assertions here if needed
self.assertTrue(True)


if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit 0730869

Please sign in to comment.