Exemple #1
0
def test_get_dictionary_vehicle_states():
    with allure.step("Send request to the server"):
        r = requests.get(TD.url83() + "/get/dictionary/vehicle_states")

    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)

    with allure.step("Assert status code is 200"):
        AssertThat(r.status_code).IsEqualTo(200)

    with allure.step("Validate server response according to our scheme"):
        validate(instance=r.json(), schema=schema)

    with allure.step("Assert Contains Items in r.json()['result']"):
        AssertThat(r.json()["result"]).ContainsItem(
            "HOST_SEARCH_UNLOAD_PERSONALLY", 4)
        AssertThat(r.json()["result"]).ContainsItem("IDLE_ROTATE", 7)
        AssertThat(r.json()["result"]).ContainsItem("WAITING_FOR_SECURITY", -3)
        AssertThat(r.json()["result"]).ContainsItem("NO_IGNITION", -2)
        AssertThat(r.json()["result"]).ContainsItem("GUEST_START_UNLOAD", 6)
        AssertThat(r.json()["result"]).ContainsItem("HOST_ACCEPT_UNLOAD", 1)
        AssertThat(r.json()["result"]).ContainsItem(
            "HOST_SEARCH_UNLOAD_PERSONALLY", 4)
        AssertThat(r.json()["result"]).ContainsItem("WAITING_FOR_INIT_END", -4)
        AssertThat(r.json()["result"]).ContainsItem("DEFAULT", 0)
        AssertThat(r.json()["result"]).ContainsItem("NO_DRIVER", -1)
        AssertThat(r.json()["result"]).ContainsItem("GUEST_ACCEPT_UNLOAD", 5)
        AssertThat(r.json()["result"]).ContainsItem("HOST_SEARCH_UNLOAD", 3)
        AssertThat(r.json()["result"]).ContainsItem("TURN_OFF", -5)
Exemple #2
0
def test_host_search_start_unload_remove():
    with allure.step("Send request to the server"):
        r = requests.post(TD.url83() + "/host/search/start_unload/remove", headers=TD.headers())
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert status code is 200"):
        AssertThat(r.status_code).IsEqualTo(200)
def test_guest_accept_unload():
    device_id = "AC35EE26450B"

    mqtt.req83(ename="DEVICE_ID", etype="text", evalue=device_id)
    mqtt.req83(ename="RFID_1", etype="text", evalue="94594156156156")
    mqtt.req83(ename="RFID_2", etype="text", evalue="777")
    mqtt.req83(ename="bunker_level", etype="value", evalue="81")

    req = Post(TD.url83()).host.search.start_unload.perf()
    LOGGER.debug(r'\n*** host.search.start_unload :: ' + str(req.json()))

    mqtt.req83(ename="unloader_bypass", etype="switch", evalue="1")
    req = Get(TD.url83()).get.status.perf()
    LOGGER.debug(r'\n*** get.status ::' +
                 str(req.json()))  # state=-3, bypass=True

    req = Post(TD.url85()).guest.accept_unload.body(device_id=device_id).perf()
    mqtt.req85(ename="RFID_2", etype="text", evalue="777")
    LOGGER.debug(r'\n*** guest.accept_unload ::' + str(req.json()))
def test_post_guest_accept_unload():
    with allure.step("Send request to the server"):
        r = requests.post(TD.url83() + "/guest/accept_unload",
                          headers=TD.headers(),
                          json={"device_id": "15"})
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert status code is 200"):
        AssertThat(r.status_code).IsEqualTo(200)
Exemple #5
0
def test_host_free():
    with allure.step("Send request to the server"):
        req = Post(TD.url83()).host.free.perf()

    with allure.step("LOGGER get info"):
        LOGGER.info(req.json())
        LOGGER.info(req.status_code)

    with allure.step("Assert status code is 200"):
        AssertThat(req.status_code).IsEqualTo(200)
Exemple #6
0
def test_host_guest_accept_unload_remove():
    with allure.step("Send request to the server"):
        req = Post(TD.url83()).host.guest.accept_unload.remove.body(device_id='15').perf()


    with allure.step("LOGGER get info"):
        LOGGER.info(req.json())
        LOGGER.info(req.status_code)

    with allure.step("Assert status code is 200"):
        AssertThat(req.status_code).IsEqualTo(200)
def test_case_RFID_1():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="RFID_1", etype="text", evalue="94594156156156")
        # we wait DEVICE_ID in response
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert Contains Item"):
        with allure.step("RFID_1 should have fio Школенко Дмитрий Сергеевич"):
            AssertThat(r.json()["result"]["driver"]).ContainsItem("fio", "Школенко Дмитрий Сергеевич")
Exemple #8
0
def test_case_no_driver():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="RFID_1", etype="text", evalue="No Card")
        time.sleep(8)
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert Contains Item"):
        with allure.step("State should be -1"):
            AssertThat(r.json()["result"]).ContainsItem("state", -1)
Exemple #9
0
def test_case_device_id():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="DEVICE_ID", etype="text",
                   evalue='AC35EE2644F0')  # we wait DEVICE_ID in response
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert Contains Item"):
        with allure.step("DEVICE_ID should be AC35EE2644F0"):
            AssertThat(r.json()["result"]).ContainsItem(
                "device_id", "AC35EE2644F0")
Exemple #10
0
def test_case_RFID_2():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="RFID_2", etype="text", evalue="99296465799940")
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert Contains Item"):
        with allure.step("RFID_2 should have name САМОСВАЛ КАМАЗ 55102"):
            AssertThat(r.json()["result"]["guest"]).ContainsItem(
                "name", "САМОСВАЛ КАМАЗ 55102")
            AssertThat(r.json()["result"]["guest"]).ContainsItem(
                "card_uid", "99296465799940")
def test_case_loader_rotate():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="DEVICE_ID", etype="text", evalue='AC35EE2644DA')
        mqtt.req83(ename="loader_rotate", etype="switch", evalue="1")
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert Contains Item"):
        with allure.step("reaper should have rotate True"):
            AssertThat(
                r.json()["result"]["mechanization"]["reaper"]).ContainsItem(
                    "rotate", True)
Exemple #12
0
def test_case_bunker_sap_id():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="BUNKER_SAP_ID", etype="text", evalue='🇺🇸🇷🇺🇸 🇦🇫🇦🇲🇸')
        # we wait sap_id in response
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert Contains Item"):
        with allure.step("sap_id should be 🇺🇸🇷🇺🇸 🇦🇫🇦🇲🇸"):
            AssertThat(
                r.json()["result"]["mechanization"]["bunker"]).ContainsItem(
                    "sap_id", "🇺🇸🇷🇺🇸 🇦🇫🇦🇲🇸")
def test_case_bunker_lvl():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="bunker_level", etype="value", evalue="81")

    with allure.step("Send GET request to the server"):
        # req = requests.get(TD.url83() + "/get/status")
        req = Get(TD.url83()).get.status.perf()

    with allure.step("LOGGER get info"):
        LOGGER.info(req.json())
        LOGGER.info(req.status_code)
        
    with allure.step("Assert Contains Item"):
        with allure.step("bunker_level should have value 999"):
            AssertThat(req.json()["result"]["mechanization"]["bunker"]).ContainsItem("percentage", 81)
Exemple #14
0
def test_send_gpsd_tpv():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="GPSD_TPV", etype="json",
                   evalue=json.dumps({"class": "TPV", "time": "2020-03-31T04:50:20.10Z", "ept": 0.005,
                                      "lat": 46.498204497, "lon": 7.568061439, "alt": 1327.689,
                                      "epx": 15.319, "epy": 17.054, "epv": 124.484, "track": 10.3797,
                                      "speed": 0.091, "climb": -0.085, "eps": 34.11, "mode": 3}))
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert Contains Item"):
        with allure.step("GPSD_TPV should be True"):
            AssertThat(r.json()["result"]["availability"]).ContainsItem("GPS", True)
def test_host_start_unload():
    with allure.step("Send request to the server"):
        r = requests.post(TD.url83() + "/host/start_unload",
                          headers=TD.headers(),
                          json={
                              "device_id": "AC35EE2644F0",
                              "rfid": "94594156156156",
                              "reason": 1
                          })

    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)

    with allure.step("Assert status code is 200"):
        AssertThat(r.status_code).IsEqualTo(200)
Exemple #16
0
def test_case_dg400():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="DG400",
                   etype="json",
                   evalue=json.dumps({
                       "net": 0.8,
                       "units": "KG"
                   }))
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert Contains Item"):
        with allure.step("DG400 should have net 7891"):
            AssertThat(
                r.json()["result"]["mechanization"]["bunker"]).ContainsItem(
                    "weight", 0.8)
def test_case_unloader_by_pass():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="RFID_1", etype="text", evalue="94594156156156")
        mqtt.req83(ename="unloader_bypass", etype="switch",
                   evalue="1")  # we wait state -3 in response

    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")

    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)

    with allure.step("Assert Contains Item"):
        with allure.step("State should be -3"):
            AssertThat(r.json()["result"]).ContainsItem("state", -3)
            AssertThat(
                r.json()["result"]["mechanization"]["worm"]).ContainsItem(
                    "bypass", True)
def test_get_dictionary_unload_unlock_reasons():
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/dictionary/unload_unlock_reasons")

    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)

    with allure.step("Assert status code is 200"):
        AssertThat(r.status_code).IsEqualTo(200)

    with allure.step("Validate server response according to our scheme"):
        validate(instance=r.json(), schema=schema)

    with allure.step("Assert Contains Item"):
        AssertThat(r.json()["result"]).ContainsItem("KAGAT", 3)
        AssertThat(r.json()["result"]).ContainsItem("RFID", 1)
        AssertThat(r.json()["result"]).ContainsItem("IDLE_ROTATE", 4)
        AssertThat(r.json()["result"]).ContainsItem("NETWORK", 2)
Exemple #19
0
def test_get_dictionary_rfid_states():
    with allure.step("Send request to the server"):
        r = requests.get(TD.url83() + "/get/dictionary/rfid_states")

    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)

    with allure.step("Assert status code is 200"):
        AssertThat(r.status_code).IsEqualTo(200)

    with allure.step("Validate server response according to our scheme"):
        validate(instance=r.json(), schema=schema)

    with allure.step("Assert Contains Items"):
        AssertThat(r.json()["result"]).ContainsItem("BAD_CARD", 2)
        AssertThat(r.json()["result"]).ContainsItem("AUTH_OK", 3)
        AssertThat(r.json()["result"]).ContainsItem("NO_CONNECTION", 0)
        AssertThat(r.json()["result"]).ContainsItem("REMOVE_CARD", -1)
Exemple #20
0
def test_case_default_state():
    with allure.step("Send requests to the MQTT"):

        mqtt.req83(ename="RFID_1", etype="text", evalue="94594156156156")
        mqtt.req83(ename="unloader_bypass", etype="switch", evalue="1")
        mqtt.req83(ename="RFID_2", etype="text",
                   evalue="777")  # we wait state 0 in response
        time.sleep(1)

    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")

    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)

    with allure.step("Assert Contains Item"):
        with allure.step("State should be -0"):
            AssertThat(r.json()["result"]).ContainsItem("state", 0)
def test_get_dictionary_vehicle_types():
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/dictionary/vehicle_types")

    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)

    with allure.step("Assert status code is 200"):
        AssertThat(r.status_code).IsEqualTo(200)

    with allure.step("Assert Contsins Items in r.json()[result]"):
        AssertThat(r.json()["result"]).ContainsItem("BEETROOT_HARVESTER", "C030")
        AssertThat(r.json()["result"]).ContainsItem("TRANSPORTER", "C010")
        AssertThat(r.json()["result"]).ContainsItem("REFUELLER", "T090")
        AssertThat(r.json()["result"]).ContainsItem("HARVESTER", "C020")
        AssertThat(r.json()["result"]).ContainsItem("BEETROOT_TRANSPORTER", "C070")

    with allure.step("Validate server response according to our scheme"):
        validate(instance=r.json(), schema=schema)
def test_case_bunker_lvl_sense():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="bunker_level_sens", etype="json", evalue=json.dumps({"1": True,
                                                                               "2": False,
                                                                               "3": False,
                                                                               "4": True,
                                                                               "5": False
                                                                               }))
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")
        # req = Get(TD.url83().get.status.perf())
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert Contains Item"):
        with allure.step("bunker_level_sens should have values True, False, False, True, False"):
            AssertThat(r.json()["result"]["mechanization"]["bunker"]).ContainsItem("sense", {"1": True,
                                                                                             "2": False,
                                                                                             "3": False,
                                                                                             "4": True,
                                                                                             "5": False
                                                                                             })
def test_get_neighbors():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="DEVICE_ID", etype="text", evalue="AC35EE2644F0")
        mqtt.req83(ename="bunker_level", etype="value", evalue="999")
        mqtt.req83(ename="RFID_1", etype="text", evalue="94594156156156")
        time.sleep(2)
    with allure.step("Send request to the server"):
        r = requests.get(TD.url83() + "/get/neighbors")
        r85 = requests.get(TD.url85() + "/get/neighbors")
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("LOGGER get info 85"):
        LOGGER.info(r85.json())
    with allure.step("Assert status code is 200"):
        AssertThat(r.status_code).IsEqualTo(200)
    with allure.step("Assert contains items in json response"):
        AssertThat(r85.json()["result"]).ContainsKey("C010")
        AssertThat(r85.json()["result"]["C010"][0]).ContainsItem(
            "bunker_percentage", 999)
        AssertThat(r85.json()["result"]["C010"][0]["driver"]).ContainsItem(
            "fio", "Школенко Дмитрий Сергеевич")
Exemple #24
0
import paho.mqtt.client as mqtt
from support import test_data2 as TD


# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected with result code " + str(rc))

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe("/devices/vehicle/controls/#")


# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    print(msg.topic, msg.payload)


# host = str(sys.argv[1])
host = TD.url83()
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.connect(host, 1883, 60)
# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.
client.loop_forever()