コード例 #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)
コード例 #2
0
 def __read_file(self, input_file):
     contents = []
     with open(input_file) as f:
         for line in f:
             contents.append(line.strip().split())
     LOGGER.info('Done! %d lines are read from file %s' % (len(contents), input_file))
     return contents
コード例 #3
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)
コード例 #4
0
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)
コード例 #5
0
ファイル: test_host_free.py プロジェクト: AcbarAcrobat/ragro
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)
コード例 #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)
コード例 #7
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)
コード例 #8
0
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", "Школенко Дмитрий Сергеевич")
コード例 #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")
コード例 #10
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", "🇺🇸🇷🇺🇸 🇦🇫🇦🇲🇸")
コード例 #11
0
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)
コード例 #12
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")
コード例 #13
0
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)
コード例 #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)
コード例 #15
0
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)
コード例 #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)
コード例 #17
0
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)
コード例 #18
0
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)
コード例 #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)
コード例 #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)
コード例 #21
0
def test_guest_start_unload():
    device_id = "AC35EE26450B"
    url = TD.url85() + '/guest/start_unload'
    body = {"device_id": device_id}

    mqtt.req83(ename="DEVICE_ID", etype="text", evalue=device_id)

    with allure.step("Начало выгрузки"):
        r = requests.post(TD.url85().guest.start.unload.perf(),
                          json=body,
                          headers=TD.headers())

    LOGGER.debug(r.json())
    LOGGER.debug(r.status_code)

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

    with allure.step('Validate schema'):
        pass
コード例 #22
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)
コード例 #23
0
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
                                                                                             })
コード例 #24
0
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()))
コード例 #25
0
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", "Школенко Дмитрий Сергеевич")
コード例 #26
0
def handler(event, context):
    evt_lst = json.loads(event)
    creds = context.credentials
    auth = oss2.StsAuth(creds.access_key_id, creds.access_key_secret,
                        creds.security_token)

    evt = evt_lst['events'][0]
    bucket_name = evt['oss']['bucket']['name']
    # local debug
    # endpoint = 'oss-' + evt['region'] + '.aliyuncs.com'
    endpoint = 'oss-' + evt['region'] + '-internal.aliyuncs.com'
    bucket = oss2.Bucket(auth, endpoint, bucket_name)
    object_name = evt['oss']['object']['key']

    if "ObjectCreated:PutSymlink" == evt['eventName']:
        object_name = bucket.get_symlink(object_name).target_key
    if object_name == "":
        raise RuntimeError('{} is invalid symlink file'.format(
            evt['oss']['object']['key']))

    lst = object_name.split("/")
    file_name = lst[-1]
    PROCESSED_DIR = os.environ.get("PROCESSED_DIR", "")
    if PROCESSED_DIR and PROCESSED_DIR[-1] != "/":
        PROCESSED_DIR += "/"
    newKey = PROCESSED_DIR + file_name
    open_mode = "r"
    if object_name.endswith(".tar.gz"):
        open_mode = "r:gz"
        newKey = newKey.replace(".tar.gz", "/")

    elif object_name.endswith(".tgz"):
        open_mode = "r:gz"
        newKey = newKey.replace(".tgz", "/")

    elif object_name.endswith(".tar.bz2"):
        open_mode = "r:bz2"
        newKey = newKey.replace(".tar.bz2", "/")

    elif object_name.endswith(".tar.xz"):
        open_mode = "r:xz"
        newKey = newKey.replace(".tar.xz", "/")

    elif object_name.endswith(".tar"):
        open_mode = "r:"
        newKey = newKey.replace(".tar", "/")

    else:
        raise RuntimeError(
            '{} filetype is not in  [".tar.gz", ".tgz", ".tar.bz2", ".tar.xz", ".tar"]'
            .format(object_name))

    LOGGER.info("start to decompress tar file = {}".format(object_name))

    oss_file_obj = OssStreamFileLikeObject(bucket, object_name)
    with tarfile.open(fileobj=oss_file_obj, mode=open_mode) as tf:
        for entry in tf.getmembers():
            if not entry.isfile():
                continue
            LOGGER.debug("extract {} ...".format(entry.name))
            file_obj = tf.extractfile(entry)
            bucket.put_object(newKey + entry.name, file_obj)
コード例 #27
0
 def wrapper(*args, **kwargs):
     local_time = time.time()
     ret = func(*args, **kwargs)
     LOGGER.info('current Function [%s] excute time is %.2f' %
                 (func.__name__, time.time() - local_time))
     return ret