diff --git a/.github/workflows/main_hamalertspotbot.yml b/.github/workflows/main_hamalertspotbot.yml index 75bb477..27a4bf5 100644 --- a/.github/workflows/main_hamalertspotbot.yml +++ b/.github/workflows/main_hamalertspotbot.yml @@ -34,7 +34,8 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt - # Optional: Add step to run tests here + - name: Run Python unit tests + run: python -u -m unittest test.py - name: Zip artifact for deployment run: zip release.zip ./* -r diff --git a/function_app.py b/function_app.py index 8c5373f..4c56ce0 100644 --- a/function_app.py +++ b/function_app.py @@ -10,7 +10,6 @@ def spotbot(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') req_body = {} - logging.info(f"Received this: {req}") try: req_body = req.get_json() @@ -19,6 +18,10 @@ def spotbot(req: func.HttpRequest) -> func.HttpResponse: logging.error('Invalid JSON received') return func.HttpResponse("Invalid JSON", status_code=400) + content = create_content + return call_target(content) + +def create_content(req_body): fullCallsign = req_body.get('fullCallsign', 'Unknown') source = req_body.get('source', 'Unknown') frequency = req_body.get('frequency', 'Unknown') @@ -27,7 +30,9 @@ def spotbot(req: func.HttpRequest) -> func.HttpResponse: wwffRef = req_body.get('wwffRef', '') content = {"content": f"{fullCallsign} | {source} | freq: {frequency} | mode: {mode} | loc: {summitRef}{wwffRef}"} + return content +def call_target(content): target_url = os.getenv('TARGET_URL') response = requests.post(target_url, json=content) return func.HttpResponse(response.text, status_code=response.status_code) \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..24c809e --- /dev/null +++ b/test.py @@ -0,0 +1,19 @@ +import unittest +import function_app + +class TestSpotBot(unittest.TestCase): + + def test_function_app_basic(self): + req_body = {"fullCallsign": "KI7HSG", "source": "POTA", "frequency": "14.074", "mode": "FT8", "wwffRef":"US-0052"} + content = function_app.create_content(req_body) + expected = {'content': 'KI7HSG | POTA | freq: 14.074 | mode: FT8 | loc: US-0052'} + self.assertDictEqual(content, expected) + + def test_function_app(self): + req_body = {"fullCallsign": "KI7HSG", "source": "sotawatch", "frequency": "14.074", "mode": "FT8", "summitRef": "ABCD"} + content = function_app.create_content(req_body) + expected = {'content': 'KI7HSG | sotawatch | freq: 14.074 | mode: FT8 | loc: ABCD'} + self.assertDictEqual(content, expected) + +if __name__ == '__main__': + unittest.main()