Esempio n. 1
0
def test_post_request_multi(file, index):
    body = str(index)
    h = http("http://localhost/" + file, 8080)
    h.setType('post')
    h.setData(body)
    h.addHeader("Content-Type", "application/json")
    h.addHeader("Content-Length", str(len(body)))
    h.constructContent()
    reply = h.send()
Esempio n. 2
0
 def test_post_request(self):
     body = '{"Assignment":"2", "name":"bar"}'
     h = http("http://localhost/bar", 8080)
     h.setType('post')
     h.setData(body)
     h.addHeader("Content-Type", "application/json")
     h.addHeader("Content-Length", str(len(body)))
     h.constructContent()
     reply = h.send()
     print(reply.headMap)
     print(reply.body)
     self.assertEqual(reply.state, '200')
Esempio n. 3
0
def test_get_file(file, self):
    h = http("http://localhost/" + file, 8080)
    h.setType('get')
    h.constructContent()
    reply = h.send()
Esempio n. 4
0
    def check_string(self):
        #print("inside check string")
        flaggetpost = ""
        verflag = False
        headerval = ""
        bodyvalue = ""
        fileflag = ""
        fileloc = ""
        inline_flag = False
        flag_g = False
        flag_p = False
        d_flag = False
        f_flag = False
        is_write = False
        output_file = ""
        URL = ""


        for i in range(0,len(self.inputlist)):

            if(self.inputlist[i]=='get'):
                flag_g = True

            elif (self.inputlist[i] == 'post'):
                flag_p = True

        #print(self.inputlist)

        if (not flag_p) and flag_g:
            flaggetpost = "get"
            self.inputlist.remove("get")
        elif flag_p and not flag_g:
            flaggetpost = "post"
            self.inputlist.remove("post")
        elif flag_g and flag_p:
            print("\n\n Command contains both get and post. Exiting the program!")
            exit()
        elif not flag_g and not flag_p:
            print("\n\n Command contains neither get nor post. Exiting the program!")
            exit()


        for i in range(0, len(self.inputlist)):
            if (self.inputlist[i] == '-d'):
                d_flag = True
            if (self.inputlist[i] == '-f'):
                f_flag = True

        if flaggetpost == "get" and (d_flag or f_flag):
            print("Wrong Command! get can be used neither with -d nor with -f")
            exit()

        if flaggetpost == "post" and d_flag and f_flag:
            print("Wrong Command! post can be used either with -d or with -f and not with both of them")
            exit()


        #print(self.inputlist)

        for i in range(0, len(self.inputlist)):
            if (self.inputlist[i] == '-h'):
                self.header_dic(i, self.inputlist)
                #print(self.remove_index)

            if (self.inputlist[i] == '-v'):
                verflag = True
                self.remove_index.append(i)

            if (self.inputlist[i] == '-o'):
                is_write = True
                output_file = self.inputlist[i+1]
                self.remove_index.extend((i,i+1))

            if (flaggetpost =='post' and self.inputlist[i] == '-f'):
                fileflag = True
                fileloc = self.inputlist[i+1]
                self.remove_index.extend((i, i + 1))

            if (flaggetpost =='post' and self.inputlist[i] == '-d'):
                fileflag = False
                inline_flag = True
                #bodyvalue = self.inputlist[i+1]
                self.remove_index.append(i)

        self.remove_index.sort(reverse=True)
        #print(self.remove_index)
        for i in self.remove_index:
            self.inputlist.remove(self.inputlist[i])

        #print(self.inputlist)

        for i in range(0, len(self.inputlist)):
            string_u = str(self.inputlist[i])
            if string_u.startswith('http://') or string_u.startswith('https://') or string_u.startswith('www.'):
                #print("url found")
                URL = string_u
                #print("URL is:" + URL)
                self.inputlist.remove(URL)
                break

        if inline_flag:
            string_m = ""
            for i in range(0, len(self.inputlist)):
                string_m += str(self.inputlist[i]) + " "
            #print("Body is" + string_m)
            bodyvalue = string_m.strip()


        #print(self.inputlist)
        #print("flaggetpost value: " + flaggetpost)
        #print("header dictionary")
        #print(self.headerdict)

        if(flaggetpost=='get'):
            #print("inside get command")
            header_string = self.create_header(self.headerdict, bodyvalue)
            http(URL, bodyvalue, header_string, verflag, is_write, output_file, flaggetpost).get_request()

        elif(flaggetpost=='post'):
            #print("inside post command")
            if fileflag:
                file = open(fileloc, "r")
                bodyvalue = file.read()
                file.close()
            header_string = self.create_header(self.headerdict, bodyvalue)
            http(URL, bodyvalue, header_string, verflag, is_write, output_file, flaggetpost).post_request()
Esempio n. 5
0
 def test_get(self):
     h = http("http://localhost", 8080)
     h.setType('get')
     h.constructContent()
     reply = h.send()
     self.assertEqual(reply.state, '200')
Esempio n. 6
0
 def test_get_no_file(self):
     h = http("http://localhost/foo_no", 8080)
     h.setType('get')
     h.constructContent()
     reply = h.send()
     self.assertEqual(reply.state, '404')