Exemplo n.º 1
0
    def test_search(self):
        LOGGER.debug("Test search")
        payload = get_tgbot_payload("/search telegram")
        tgbot_result = get_tgbot_response(payload, configs.get_header())

        if tgbot_result["status"] != 200:
            result = {
                "success":
                False,
                "message":
                "tgbot submit command, failed, error code: {}, error message: {}"
                .format(tgbot_result["status"], tgbot_result["text"])
            }
        else:
            sleep(5)
            last_message = self.r.get("e2e:last-message").decode("utf-8")
            LOGGER.debug("submit command, got message: %s", last_message)
            if "@telegram" in last_message:
                result = {"success": True, "total": tgbot_result["total"]}
            else:
                result = {
                    "success":
                    False,
                    "message":
                    "submit command, got last message: {}".format(last_message)
                }
        self.assert_successful(result)
Exemplo n.º 2
0
 def test_submit(self, exist=True):
     LOGGER.debug("Test submit")
     payload = get_tgbot_payload("/submit knarfeh")
     tgbot_result = get_tgbot_response(payload, configs.get_header())
     if exist is True:
         should_message = "this id already exist"
     else:
         should_message = "Successfully submitted"
     if tgbot_result["status"] != 200:
         result = {
             "success":
             False,
             "message":
             "tgbot submit command, failed, error code: {}, error message: {}"
             .format(tgbot_result["status"], tgbot_result["text"])
         }
     else:
         sleep(10)
         last_message = self.r.get("e2e:last-message").decode("utf-8")
         LOGGER.debug("submit command, got message: %s", last_message)
         if should_message in last_message:
             result = {"success": True, "total": tgbot_result["total"]}
         else:
             result = {
                 "success":
                 False,
                 "message":
                 "submit command, got last message: {}".format(last_message)
             }
     self.assert_successful(result)
     return
Exemplo n.º 3
0
 def test_get(self):
     LOGGER.debug("Test get command")
     payload = get_tgbot_payload("/get knarfeh")
     tgbot_result = get_tgbot_response(payload, configs.get_header())
     if tgbot_result["status"] != 200:
         result = {
             "success":
             False,
             "message":
             "tgbot get command, failed, error code: {}, error message: {}".
             format(tgbot_result["status"], tgbot_result["text"])
         }
     else:
         sleep(3)
         last_message = self.r.get("e2e:last-message").decode("utf-8")
         LOGGER.debug("Start command, got message: %s", last_message)
         if "@knarfeh" in last_message:
             result = {"success": True, "total": tgbot_result["total"]}
         else:
             result = {
                 "success":
                 False,
                 "message":
                 "get command, got last message: {}".format(last_message)
             }
     self.assert_successful(result)
     return
Exemplo n.º 4
0
 def test_echo(self):
     LOGGER.debug("Test echo command")
     echo_message = "Use echo command to test echo"
     payload = get_tgbot_payload("/echo {}".format(echo_message))
     tgbot_result = get_tgbot_response(payload, configs.get_header())
     if tgbot_result["status"] != 200:
         result = {
             "success":
             False,
             "message":
             "tgbot echo command failed, error code: {}, error message: {}".
             format(tgbot_result["status"], tgbot_result["text"])
         }
     else:
         last_message = self.r.get("e2e:last-message").decode("utf-8")
         if last_message == echo_message:
             result = {"success": True, "total": tgbot_result["total"]}
         else:
             result = {
                 "success":
                 False,
                 "message":
                 "echo command, got last message: {}, should be: {}".format(
                     last_message, echo_message)
             }
     self.assert_successful(result)
     return
Exemplo n.º 5
0
 def test_ping(self):
     LOGGER.debug("test ping command")
     payload = get_tgbot_payload("/ping")
     tgbot_result = get_tgbot_response(payload, configs.get_header())
     if tgbot_result["status"] != 200:
         result = {
             "success":
             False,
             "message":
             "tgbot ping failed, error code: {}, error message: {}".format(
                 tgbot_result["status"], tgbot_result["text"])
         }
     else:
         last_message = self.r.get("e2e:last-message").decode("utf-8")
         if last_message == "pong ":
             result = {"success": True, "total": tgbot_result["total"]}
         else:
             result = {
                 "success":
                 False,
                 "message":
                 "ping command, got last message: {}, should be: {}".format(
                     last_message, "pong")
             }
     self.assert_successful(result)
     return
Exemplo n.º 6
0
    def test_delete(self):
        LOGGER.debug("Test delete command")
        payload = get_tgbot_payload("/delete knarfeh")
        tgbot_result = get_tgbot_response(payload, configs.get_header())
        if tgbot_result["status"] != 200:
            result = {
                "success":
                False,
                "message":
                "tgbot delete command, failed, error code: {}, error message: {}"
                .format(tgbot_result["status"], tgbot_result["text"])
            }
        else:
            result = {"success": True, "total": tgbot_result["total"]}
        self.assert_successful(result)

        print("Wait for redis delete pipeline, sleep 5 seconds")
        sleep(5)
        payload = get_tgbot_payload("/get knarfeh")
        tgbot_result = get_tgbot_response(payload, configs.get_header())
        if tgbot_result["status"] != 200:
            result = {
                "success":
                False,
                "message":
                "tgbot get command, failed, error code: {}, error message: {}".
                format(tgbot_result["status"], tgbot_result["text"])
            }
        else:
            sleep(10)
            last_message = self.r.get("e2e:last-message").decode("utf-8")
            LOGGER.debug(
                "After delete command, try test command, get last_message: %s",
                last_message)
            if "this id does not exist" in last_message:
                result = {"success": True, "total": tgbot_result["total"]}
            else:
                result = {
                    "success":
                    False,
                    "message":
                    "After delete, try get command, got last message: {}".
                    format(last_message)
                }
        self.assert_successful(result)
        return
Exemplo n.º 7
0
    def tgbot_test__othercommand(self):
        payload = get_tgbot_payload("/delete knarfeh")
        get_tgbot_response(payload, configs.get_header())

        print("Sleep 5 seconds \n")
        sleep(5)
        print("Tesing submit \n")
        self.test_submit(exist=False)

        print("Sleep 5 seconds \n")
        sleep(5)
        print("Tesing ping \n")
        self.test_ping()

        print("Sleep 5 seconds \n")
        sleep(5)
        print("Tesing echo \n")
        self.test_echo()

        print("Sleep 5 seconds \n")
        sleep(5)
        print("Tesing start \n")
        self.test_start()

        print("Sleep 5 seconds \n")
        sleep(5)
        print("Tesing get \n")
        self.test_get()

        print("Sleep 5 seconds \n")
        sleep(5)
        print("Tesing submit exist \n")
        self.test_submit(exist=True)

        print("Sleep 5 seconds \n")
        sleep(5)
        print("Tesing stats \n")
        self.test_stats()

        print("Sleep 10 seconds \n")
        sleep(10)
        print("Tesing delete \n")
        self.test_delete()

        print("Sleep 3 seconds")
        sleep(3)
        print("Tesing search \n")
        self.test_search()
Exemplo n.º 8
0
def main():
    """
    Main function to start testing
    """
    test = ApiTest(name="api",
                   environment="dev",
                   workers=4,
                   timeout=60 * 60,
                   log=True)
    test.set_up()

    LOGGER.info("Starting test...")
    test.start()

    LOGGER.info("End of test...")
    result_data = test.end()

    LOGGER.info("Tear down")
    test.tear_down()
    LOGGER.info("Done! \n")
    print('=================RESULT===================')
    print('Result of test.end: ' + json.dumps(result_data))
    result_status = result_data['status']
    print('Result status: ' + result_status)

    sleep(10)
    payload = get_tgbot_payload(
        "/echo e2e tests result: {}".format(result_status))
    get_tgbot_response(payload, configs.get_header())

    e2e_start_time = mktime(
        strptime(result_data['started'][0:-6], "%Y-%m-%dT%H:%M:%S.%f"))
    print('e2e_start_time: {}'.format(e2e_start_time))
    e2e_end_time = mktime(
        strptime(result_data['ended'][0:-6], "%Y-%m-%dT%H:%M:%S.%f"))
    print('e2e_end_time: {}'.format(e2e_end_time))
    total_time = e2e_end_time - e2e_start_time
    print('total_time: {}'.format(total_time))

    case_name = []
    case_details = []
    case_nums_failed_db = []
    cases_time = []
    cases = result_data['cases']
    cases_flags = []
    total_case_num = len(cases)
    failed_cases_num = 0

    for i in range(len(cases)):
        caseflag = cases[i]['status']
        print("Running cases name: " + cases[i]['name'])
        case_start_time = mktime(
            strptime(cases[i]['started'][0:-6], "%Y-%m-%dT%H:%M:%S.%f"))
        print('Case start time: {}'.format(case_start_time))
        case_end_time = mktime(
            strptime(cases[i]['ended'][0:-6], "%Y-%m-%dT%H:%M:%S.%f"))
        print('Case end time : {}'.format(case_end_time))
        case_total_time = case_end_time - case_start_time
        print('Case total time : {}'.format(case_total_time))

        case_details.append(json.dumps(cases[i]['details']))
        case_name.append(cases[i]['name'])
        cases_flags.append(caseflag)
        cases_time.append(case_total_time)

        if caseflag == "failed":
            failed_cases_num = failed_cases_num + 1
            print(cases[i])

        case_nums_failed_db.append(get_case_num_db(cases[i]['name'], caseflag))

    print('Total failed cases number : {}'.format(failed_cases_num))

    html = "Run {} cases, Pass {} cases, Fail {} cases, ".format(total_case_num, total_case_num - failed_cases_num, failed_cases_num) + "\n" + \
           "e2e starts at {}, ".format(result_data['started'][0:-13]) + "\n" + \
           "ends at {}, ".format(result_data['ended'][0:-13]) + "\n" + \
           "Total time {}s ".format(total_time) + "\n"

    html = html + '<table border="1">\n' \
                  '<thead>\n' \
                  '<tr>\n' \
                  '<td>Case name</td>\n' \
                  '<td>Case flag</td>\n' \
                  '<td>Case details</td>\n' \
                  '<td>Case time</td>\n' \
                  '<td>Case failed times (today)</td>' \
                  '\n</tr>\n' \
                  '</thead>\n' \
                  '<tbody>'

    for i in range(len(case_name)):
        if cases_flags[i] == 'failed':
            html = html + '\n<tr>\n' \
                          '<td>{}</td>'.format(case_name[i]) + \
                    '\n<td style="color:red;">{}</td>'.format(cases_flags[i]) + \
                   '\n<td style="color:red;">{}</td>'.format(case_details[i]) + \
                   '\n<td style="color:red;">{}s</td>'.format(cases_time[i]) + \
                   '\n<td style="color:red;">{}</td>'.format(case_nums_failed_db[i]) + '\n</tr>'
        else:
            html = html + '\n<tr>\n<td>{}</td>'.format(case_name[i]) + \
                   '\n<td style="color:green;">{}</td>'.format(cases_flags[i]) + \
                   '\n<td style="color:green;">{}</td>'.format(case_details[i]) + \
                   '\n<td style="color:green;">{}s</td>'.format(cases_time[i]) + \
                   '\n<td style="color:green;">{}</td>'.format(case_nums_failed_db[i]) + '\n</tr>'

    html = html + '\n</tbody>\n</table>'

    # =========send email=============
    # send_email(
    #     "[{}] ({}) End-to-End Test".format(result_status.upper(), configs.ENV),
    #     html,
    #     configs.EMAIL_CONFIG['recipient'])

    # print case results in console
    print("--------------------- Case results -------------------")
    print(html)
    print("--------------------- Case results -------------------")

    f = open("/usr/share/nginx/html/index.html", 'w+')
    f.write(html)
    f.close()

    payload = get_tgbot_payload(
        "/echo check out: https://e2e.searchtelegram.com")
    get_tgbot_response(payload, configs.get_header())
Exemplo n.º 9
0
 def tgbot_tear_down(self):
     LOGGER.debug("tgbot tear down")
     payload = get_tgbot_payload("/echo End testing tgbot")
     get_tgbot_response(payload, configs.get_header())
Exemplo n.º 10
0
 def tgbot_set_up(self):
     LOGGER.debug("Set up tgbot test ...")
     payload = get_tgbot_payload("/echo Start testing tgbot ...")
     get_tgbot_response(payload, configs.get_header())
     sleep(5)