Пример #1
0
def testEditItem():
    status = False
    r = requests.get("http://localhost:5073/getitems/electronics")

    payload = json.loads(r.text)

    if (payload[0]["Item"] == "brand new stuff"):
        ID = payload[0]["ID"]
    else:
        ID = payload[1]["ID"]

    r = requests.get("http://localhost:5073/getdetails/electronics/" + ID)

    payload = json.loads(r.text)
    payload["Price"] = "$5000"

    # Make sure the editing was successful by checking the item price
    r = requests.post("http://localhost:5073/edititem",
                      data=json.dumps(payload))
    r2 = requests.get("http://localhost:5073/getdetails/electronics/" + ID)
    r3 = requests.get("http://localhost:5073/getuseritems/timmonfette")

    data2 = json.loads(r2.text)
    data3 = json.loads(r3.text)

    if (data2["Price"] == "$5000" and data3[0]["Price"] == "$5000"):
        status = True

    print colorize("Testing endpoint /edititem", status)
Пример #2
0
def testAddCat():
    status = False
    payload = {"name": "testColl"}
    r = requests.post("http://localhost:5073/addcat", data=json.dumps(payload))

    if (r.status_code == 201):
        status = True

    print colorize("Testing endpoint /addcat", status)
Пример #3
0
def testIndex():
    status = False
    r = requests.get("http://localhost:5073/")

    if ("Welcome! This is the API for the Nebula Shopping portal!"
            in r.text) and (r.status_code == 200):
        status = True

    print colorize("Testing endpoint /", status)
Пример #4
0
def testGetCats():
    status = False
    r = requests.get("http://localhost:5073/getcats")

    data = json.loads(r.text)
    correct = ["books", "electronics", "furniture", "music", "testColl"]

    if (data["Categories"] == correct):
        status = True

    print colorize("Testing endpoint /getcats", status)
Пример #5
0
def testUserInfo():
    status = False
    r = requests.get("http://*****:*****@email.com"):
        status = True

    print colorize("Testing endpoint /getuserinfo", status)
Пример #6
0
def testCheckUsername():
    status = False
    r1 = requests.get("http://localhost:5073/checkusername/timmonfette")
    r2 = requests.get("http://localhost:5073/checkusername/tylerbrittin")

    data1 = json.loads(r1.text)
    data2 = json.loads(r2.text)

    if (data1["Taken"] == True) and (data2["Taken"] == False):
        status = True

    print colorize("Testing endpoint /checkusername", status)
Пример #7
0
def testGetItems():
    status = False
    r = requests.get("http://localhost:5073/getitems/furniture")

    data = json.loads(r.text)

    # Test an item from the furniture category
    if (len(data) == 2 and data[0]["Item"] == "New Lamp"
            and data[0]["Category"] == "furniture"
            and data[0]["Model"] == "lamp_mod_username"
            and data[0]["Texture"] == "lamp_tex_username"):
        status = True

    print colorize("Testing endpoint /getitems", status)
Пример #8
0
def testContact():
    status = False
    payload = {
        "username": "******",
        "phone": "testNum",
        "email": "*****@*****.**",
        "message": "Testing contact form"
    }
    r = requests.post("http://localhost:5073/contactus",
                      data=json.dumps(payload))

    if (r.status_code == 201):
        status = True

    print colorize("Testing endpoint /contactus", status)
Пример #9
0
def testAddUser():
    status = False
    payload = {
        "username": "******",
        "password": "******",
        "firstname": "Tim",
        "lastname": "Monfette",
        "email": "*****@*****.**"
    }
    r = requests.post("http://localhost:5073/adduser",
                      data=json.dumps(payload))

    if (r.status_code == 201):
        status = True

    print colorize("Testing endpoint /adduser", status)
Пример #10
0
def testUserItems():
    status = False
    r = requests.get("http://*****:*****@email.com"
            and data[0]["Price"] == "$5000"
            and data[0]["Model"] == "stuffy_mod_timmonfette"
            and data[0]["Texture"] == "stuffy_tex_timmonfette"
            and len(data) == 1):
        status = True

    print colorize("Testing endpoint /getuseritems", status)
Пример #11
0
def testDetails():
    status = False
    r = requests.get("http://*****:*****@lamp.com"
            and data["Price"] == "$30" and data["Model"] == "lamp_mod_username"
            and data["Texture"] == "lamp_tex_username"):
        status = True

    print colorize("Testing endpoint /getdetails", status)
Пример #12
0
def runcmd_unmemoized(cmd, log=True, respond=False):
    if FORCE_LOG:
        log = True
    if log:
        print '  %', output.colorize(cmd, output.WARNING)
    if respond:
        p = os.popen(cmd, 'r')
        l = p.readlines()
        p.close()
        return l
    else:
        os.system(cmd)
Пример #13
0
def testDeleteItem():
    status = False
    r = requests.get("http://localhost:5073/getuseritems/timmonfette")
    data = json.loads(r.text)

    ID = data[0]["ID"]

    payload = {"seller": "timmonfette", "category": "electronics", "id": ID}

    # Delete the item
    r = requests.post("http://localhost:5073/deleteitem",
                      data=json.dumps(payload))
    r2 = requests.get("http://localhost:5073/getuseritems/timmonfette")
    r3 = requests.get("http://localhost:5073/getitems/electronics")

    data3 = json.loads(r3.text)

    # Verify it's deleted on main Nebula side and User item side
    if (r.status_code == 201 and r2.text.strip() == "null"
            and len(data3) == 1):
        status = True

    print colorize("Testing endpoint /deleteitem", status)
Пример #14
0
def testAddItem():
    status = False
    payload = {
        "category": "electronics",
        "seller": "timmonfette",
        "price": "$1000",
        "model": "stuffy_mod_timmonfette",
        "texture": "stuffy_tex_timmonfette",
        "email": "*****@*****.**",
        "item": "brand new stuff",
        "itemdesc": "stuffy stuff"
    }

    r = requests.post("http://localhost:5073/additem",
                      data=json.dumps(payload))
    r2 = requests.get("http://localhost:5073/getitems/electronics")

    data = json.loads(r2.text)

    # Make sure addition was successful
    if (r.status_code == 201 and len(data) == 2):
        status = True

    print colorize("Testing endpoint /additem", status)
Пример #15
0
def runcmd_with_exitcode(cmd, log=True, respond=False, respond_error=False):
    if FORCE_LOG:
        log = True
    if log:
        print '  %', output.colorize(cmd, output.WARNING)
    p = subprocess.Popen(cmd.split(' '), cwd=os.path.abspath('.'), stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    response, response_error = p.communicate()
    exitcode = p.poll()
    if exitcode:
        exitcode = p.wait()
    if not respond and not respond_error:
        return exitcode
    else:
        returned = [exitcode]
        if respond:
            returned.append(response)
        if respond_error:
            returned.append(response_error)
        return returned
Пример #16
0
def cli(min_line: int, max_line: int, logger: [str], no_logger: [str], min_level: str, message: [str], no_message: [str], filename: str):
	if filename == '-':
		file = sys.stdin
	else:
		file = open(filename, 'r')

	patterns = {
		'logger': mkPatterns(logger, no_logger),
		'level': (matcher.LevelPattern(True, min_level),),
		'message': mkPatterns(message, no_message),
	}
	mtr = matcher.Matcher(patterns)
	print(mtr)

	for i, line in enumerate(file):
		if min_line <= i <= max_line:
			record = logparser.parseLine(line)
			(matches, detail) = mtr.match(record)
			if matches:
				print(i, output.colorize(line.strip(), output.logLevelColor(record['level'])))
Пример #17
0
 def ask():
     return raw_input(output.colorize('  %s > ' % prompt, output.WARNING))
Пример #18
0
def finalResults():
    results = getResults()
    failRatio = results[2] / results[0]
    passRatio = results[1] / results[0]

    print colorize("Number of endpoints that Passed: " + str(results[1]), True)
    print colorize("Number of endpoints that Failed: " + str(results[2]),
                   False)

    # 80% passed is a successful regression test
    print
    if (passRatio < .8):
        print colorize("Too many endpoints Failed, Regression Testing Failed.",
                       False)
        print colorize(
            "Percentage of endpoints that Failed: " + str(failRatio * 100) +
            "%", False)
    else:
        print colorize(
            "At least 80% of endpoints Passed, Regression Testing Passed",
            True)
        print colorize(
            "Percentage of endpoints that Passed: " + str(passRatio * 100) +
            "%", True)