Skip to content

Commit

Permalink
added api basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
sheenamadan committed Dec 4, 2023
1 parent 28d267c commit fdb13ac
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/api-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run Piaware API Tests

on:
push:
#branches: [ "main" ]
pull_request:

jobs:
build:
runs-on: self-hosted

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install flake8 pytest
if [ -f requirements.txt ]; then pip3 install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
python3 -m pytest -s
39 changes: 39 additions & 0 deletions test/scripts/test_basic_piaware_api_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import requests
import unittest

BASE_URL= "http://172.16.32.89:3000/"

class TestBasicPiawareApi(unittest.TestCase):
def test_api_get_device_info(self):
payload={"request": "get_device_info"}
resp = requests.post(url=BASE_URL+"configurator", json=payload)
assert (resp.status_code == 200), "Status code is not 200. Rather found : " + str(resp.status_code)
data = resp.json()
expected_device_info_res = ['api_version', 'flightfeeder_serial', 'image_type', 'success']
self.assertListEqual(list(data.keys()), expected_device_info_res)
assert data["success"] == True, "success key value is not true"
assert data["image_type"] == 'flightfeeder-combined', "Image type is not flightfeeder combined"
assert data["api_version"] != '', "API version is empty"
assert data["flightfeeder_serial"] != '', "FlighFeeder serial is empty"


def test_api_get_device_state(self):
payload={"request": "get_device_state"}
resp = requests.post(url=BASE_URL+"configurator", json=payload)
assert (resp.status_code == 200), "Status code is not 200. Rather found : " + str(resp.status_code)
data = resp.json()
expected_device_state_res = ['device_location', 'feeder_id', 'is_connected_to_FA', 'is_connected_to_internet', 'is_password_set', 'is_receiver_claimed','network_interface','site_id','wireless-country','wireless-ip','wireless-ssid']
self.assertListEqual(list(data.keys()), expected_device_state_res)
assert isinstance(data["device_location"], list), "'device_location' value is not a list"
assert data['wireless-ip'] == '172.16.32.89', 'wireless ip has changed'
assert data['wireless-ssid'] == 'FlightAware', 'wireless-ssid has changed'

def test_api_get_wifi_networks(self):
payload={"request": "get_wifi_networks"}
resp = requests.post(url=BASE_URL+"configurator", json=payload)
assert (resp.status_code == 200), "Status code is not 200. Rather found : " + str(resp.status_code)
data = resp.json()
expected_wifi_network_res = ['encrypted', 'is_5Ghz', 'signal', 'wifi_cell', 'wireless-ssid']
self.assertListEqual(list(data['wifi_networks'][0].keys()), expected_wifi_network_res)
assert isinstance(data["wifi_networks"], list), "'wifi networks' value is not a list"

0 comments on commit fdb13ac

Please sign in to comment.