added unittest for seeding api

added get_material_deliveries to seeding api
started working on de api test
This commit is contained in:
DuSack1220 2022-10-01 17:37:24 +02:00
parent 6946ce9957
commit c325a2c7c2
2 changed files with 38 additions and 6 deletions

View file

@ -17,6 +17,7 @@ if api_override != "":
API_URL_GET_HEU = API_URL + "getHeuballen"
API_URL_GET_LOGISTIC_PLAN = API_URL + "getLogisticPlan"
API_URL_GET_MATERIAL_DELIVERIES = API_URL + "getMaterialDeliveries"
API_URL_GET_ROBOT_STATE = API_URL + "getRobotState"
@ -25,19 +26,19 @@ class Seeding:
"""
@staticmethod
def get_heu() -> Tuple[Dict, int]:
def get_heuballen() -> int:
"""Makes the /api/getHeuballen call to the api.
:return: Json Object and status code as returned by the api.
:rtype: Tuple[Dict, int]
:return: hueballencode as int.
:rtype: int
"""
res = requests.get(API_URL_GET_HEU)
result = json.loads(res.content)
logger.debug(f"Seeding.get_heu = {result}, status code = {res.status_code}")
return result
logger.debug(f"Seeding.get_heuballen = {result}, status code = {res.status_code}")
return result["heuballen"]
@staticmethod
def get_logistic_plan() -> Tuple[Dict, int]:
def get_logistic_plan() -> List:
"""Makes the /api/getLogisticPlan call to the api.
:return: Json Object and status code as returned by the api.
@ -48,6 +49,18 @@ class Seeding:
logger.debug(f"Seeding.get_logistic_plan = {result}, status code = {res.status_code}")
return result
@staticmethod
def get_material_deliveries() -> List:
"""Makes the /api/getMaterialDeliveries call to the api.
:return: Json Object and status code as returned by the api.
:rtype: List
"""
res = requests.get(API_URL_GET_LOGISTIC_PLAN)
result = json.loads(res.content)
logger.debug(f"Seeding.get_material_deliveries = {result}, status code = {res.status_code}")
return result
@staticmethod
def get_robot_state() -> Tuple[Dict, int]:
res = requests.get(API_URL_GET_ROBOT_STATE)

View file

@ -1,5 +1,8 @@
import os
import unittest
import compLib.Seeding as Seeding
import compLib.Api as SeedingApi
import compLib.DoubleElimination as De
class SeedingTest(unittest.TestCase):
@ -13,5 +16,21 @@ class SeedingTest(unittest.TestCase):
self.assertEqual(gamestate.get_material_deliveries(), [[3, 1], [0, 3], [3, 1], [3, 1]])
class SeedingApiTest(unittest.TestCase):
def test_api_seeding(self):
gamestate = Seeding.Gamestate(0)
seeding_api = SeedingApi.Seeding()
self.assertEqual(seeding_api.get_heuballen(), gamestate.get_heuballen())
self.assertEqual(seeding_api.get_logistic_plan(), gamestate.get_logistic_plan())
#self.assertEqual(seeding_api.get_material_deliveries(), gamestate.get_material_deliveries())
class DeApiTest(unittest.TestCase):
def test_api_de(self):
de = De.DoubleElim()
print(de.get_goal())
#self.assertEqual(de.get_goal(), )
if __name__ == '__main__':
unittest.main()