Ejemplo n.º 1
0
    def test_post_and_get_storage(self):
        print "\nPOST /storage/data1 - GET /storage/data1\n"
        args = ("/storage/data1",)
        kwargs = {}
        path = args[0]
        req = Request()
        for key in kwargs:
            o = Option()
            o.number = defines.inv_options[key]
            o.value = kwargs[key]
            req.add_option(o)

        req.code = defines.inv_codes['POST']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.payload = "Created"
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.responses["CREATED"]
        expected.token = None
        expected.payload = None
        option = Option()
        option.number = defines.inv_options["Location-Path"]
        option.value = "/storage/data1"
        expected.add_option(option)

        self.current_mid += 1

        self._test(req, expected)

        req = Request()
        for key in kwargs:
            o = Option()
            o.number = defines.inv_options[key]
            o.value = kwargs[key]
            req.add_option(o)

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.responses["CONTENT"]
        expected.token = None
        expected.payload = "Created"

        self.current_mid += 1

        self._test(req, expected)
Ejemplo n.º 2
0
    def _create_test_sequence(self, bValidResponse=True):
        exchange = list()
        req = Request()
        req.code = defines.Codes.POST.number
        req.uri_path = "/storage/new_res?id=1"
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.payload = "test"
        req.add_if_none_match()

        if bValidResponse:
            expected = Response()
            expected.type = defines.Types["ACK"]
            expected._mid = self.current_mid
            expected.code = defines.Codes.CREATED.number
            expected.token = None
            expected.payload = None
            expected.location_path = "storage/new_res"
            expected.location_query = "id=1"
        else:
            expected = None

        exchange.append((req, expected))
        self.current_mid += 1

        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = "/storage/new_res"
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.if_match = ["test", "not"]

        if bValidResponse:
            expected = Response()
            expected.type = defines.Types["ACK"]
            expected._mid = self.current_mid
            expected.code = defines.Codes.CONTENT.number
            expected.token = None
            expected.payload = "test"
        else:
            expected = None

        exchange.append((req, expected))
        self.current_mid += 1

        return exchange
Ejemplo n.º 3
0
    def test_long(self):
        print "\nGET /long\n"
        args = ("/long",)
        kwargs = {}
        path = args[0]
        req = Request()
        for key in kwargs:
            o = Option()
            o.number = defines.inv_options[key]
            o.value = kwargs[key]
            req.add_option(o)

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None
        expected.payload = None

        expected2 = Response()
        expected2.type = defines.inv_types["CON"]
        expected2.code = defines.responses["CONTENT"]
        expected2.token = None
        expected2.payload = "Long Time"

        self.current_mid += 1
        self._test_modular([(req, expected), (None, expected2)])
Ejemplo n.º 4
0
    def test_td_coap_core_07(self):
        print "TD_COAP_CORE_07"
        path = "/test"
        req = Request()

        req.code = defines.inv_codes['PUT']
        req.uri_path = path
        req.type = defines.inv_types["NON"]
        o = Option()
        o.number = defines.inv_options["Content-Type"]
        o.value = defines.inv_content_types["application/xml"]
        req.add_option(o)
        req._mid = self.current_mid
        req.destination = self.server_address
        req.payload = "<value>test</value>"

        expected = Response()
        expected.type = defines.inv_types["NON"]
        expected._mid = None
        expected.code = defines.responses["CHANGED"]
        expected.token = None
        expected.payload = None

        self.current_mid += 1
        self._test_plugtest(req, expected)
Ejemplo n.º 5
0
    def test_wrong_ep(self):
        print("Endpoint name already exists")
        client = HelperClient(self.server_address)
        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683&lt=60"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        client.post(path, payload, None, None, **ct)
        client.stop()

        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683"
        req = Request()
        req.code = defines.Codes.POST.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = defines.Content_types["application/link-format"]
        req.payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";' \
                      'anchor="coap://spurious.example.com:5683",</sensors/light>;ct=41;rt="light-lux";if="sensor"'

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.SERVICE_UNAVAILABLE.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 6
0
    def test_lookup_expired_ep(self):
        print("Expired endpoint lookup")
        client = HelperClient(self.server_address)
        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683&lt=60"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        client.post(path, payload, None, None, **ct)
        client.stop()

        path = "rd-lookup/ep?ep=node1&rt=temperature-c"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.content_type = defines.Content_types["application/link-format"]
        expected.payload = None

        self.current_mid += 1
        # After 61 seconds the resource will be expired
        self._test_check([(req, expected)], 61)
Ejemplo n.º 7
0
    def test_delete(self):
        print("Delete")
        client = HelperClient(self.server_address)
        path = "rd?ep=endpoint1&lt=500&con=coap://local-proxy-old.example.com:5683&et=oic.d.sensor"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        response = client.post(path, payload, None, None, **ct)
        loc_path = response.location_path
        client.stop()

        path = loc_path
        req = Request()
        req.code = defines.Codes.DELETE.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.DELETED.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 8
0
    def test_td_coap_core_09(self):
        print "TD_COAP_CORE_09"
        path = "/separate"
        req = Request()

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None
        expected.payload = None

        expected2 = Response()
        expected2.type = defines.inv_types["CON"]
        expected2._mid = None
        expected2.code = defines.responses["CONTENT"]
        expected2.token = None
        expected2.payload = "Separate Resource"

        self.current_mid += 1
        self._test_plugtest_separate(req, expected, expected2)
Ejemplo n.º 9
0
 def discover_remote(self, destination):
     request = Request()
     assert (isinstance(destination, str))
     split = destination.split(":", 1)
     host = split[0]
     port = int(split[1])
     server = (host, port)
     request.destination = (host, port)
     request.type = defines.inv_types["CON"]
     request._mid = (self._currentMID + 1) % (1 << 16)
     request.code = defines.inv_codes["GET"]
     uri = "/" + defines.DISCOVERY_URL
     request.proxy_uri = uri
     client = HelperClient(server, True)
     token = self.generate_token()
     function = client.protocol.get
     args = (uri,)
     kwargs = {"Token": str(token)}
     callback = self.discover_remote_results
     err_callback = self.discover_remote_error
     operations = [(function, args, kwargs, (callback, err_callback))]
     key = hash(str(host) + str(port) + str(token))
     self._forward[key] = request
     key = hash(str(host) + str(port) + str((client.starting_mid + 1) % (1 << 16)))
     self._forward_mid[key] = request
     client.start(operations)
Ejemplo n.º 10
0
 def map(self, request):
     path = request.uri_path
     if request.uri_path == defines.DISCOVERY_URL:
         response = Response()
         response.destination = request.source
         response = self._resource_layer.discover(request, response)
         self.result_forward(response, request)
     server = self.root.find_complete(path)
     if server is not None:
         new_request = Request()
         segments = server.find_path().split("/")
         path = segments[2:]
         path = "/".join(path)
         segments = segments[1].split(":")
         host = segments[0]
         port = int(segments[1])
         # new_request.destination = (host, port)
         new_request.source = request.source
         new_request.type = request.type
         new_request._mid = (self._currentMID + 1) % (1 << 16)
         new_request.code = request.code
         new_request.proxy_uri = "coap://" + str(host) + ":" + str(port) + "/" + path
         new_request.payload = request.payload
         for option in request.options:
             if option.name == defines.inv_options["Uri-Path"]:
                 continue
             if option.name == defines.inv_options["Uri-Query"]:
                 continue
             if option.name == defines.inv_options["Uri-Host"]:
                 continue
             new_request.add_option(option)
         return new_request
     return None
Ejemplo n.º 11
0
    def test_get_not_found(self):
        print "\nGET /not_found\n"
        args = ("/not_found",)
        kwargs = {}
        path = args[0]
        req = Request()
        for key in kwargs:
            o = Option()
            o.number = defines.inv_options[key]
            o.value = kwargs[key]
            req.add_option(o)

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.responses["NOT_FOUND"]
        expected.token = None
        expected.payload = None

        self.current_mid += 1
        self._test(req, expected)
Ejemplo n.º 12
0
    def test_td_coap_obs_01(self):
        print "TD_COAP_OBS_01"
        path = "/obs"
        req = Request()

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.observe = 0

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.responses["CONTENT"]
        expected.token = None
        expected.payload = "Observable Resource"
        expected.observe = 1

        expected2 = Response()
        expected2.type = defines.inv_types["CON"]
        expected2._mid = self.server_mid
        expected2.code = defines.responses["CONTENT"]
        expected2.token = None
        expected2.payload = "Observable Resource"
        expected2.observe = 2

        self.current_mid += 1
        self.server_mid += 1
        self._test_plugtest([(req, expected), (None, expected2)])
Ejemplo n.º 13
0
    def test_retrasnmissions(self):
        print "Retransmissions"
        path = "/separate"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None
        expected.payload = None

        expected2 = Response()
        expected2.type = defines.Types["CON"]
        expected2._mid = self.server_mid
        expected2.code = defines.Codes.CONTENT.number
        expected2.token = None
        expected2.payload = "Separate Resource"

        self.current_mid += 1
        self._test_plugtest([(req, expected), (None, expected2), (None, expected2), (None, expected2)])
Ejemplo n.º 14
0
 def delete(self, client_callback, *args, **kwargs):
     if isinstance(args[0], str):
         path = str(args[0])
         req = Request()
         req.uri_path = path
         if "Token" in kwargs.keys():
             req.token = kwargs.get("Token")
             del kwargs["Token"]
         if "MID" in kwargs.keys():
             req.mid = kwargs.get("MID")
             del kwargs["MID"]
         if "Server" in kwargs.keys():
             req.destination = kwargs.get("Server")
             del kwargs["Server"]
     else:
         req = args[0]
     for key in kwargs:
         try:
             o = Option()
             o.number = defines.inv_options[key]
             o.value = kwargs[key]
             req.add_option(o)
         except KeyError:
             pass
     req.code = defines.inv_codes['DELETE']
     req.type = defines.inv_types["CON"]
     self.send_callback(req, self.delete_results, client_callback)
Ejemplo n.º 15
0
    def test_get_separate(self):
        print "\nGET /separate\n"
        args = ("/separate",)
        kwargs = {}
        path = args[0]
        req = Request()
        for key in kwargs:
            o = Option()
            o.number = defines.inv_options[key]
            o.value = kwargs[key]
            req.add_option(o)

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["CON"]
        expected.code = defines.responses["CONTENT"]
        expected.token = None
        expected.payload = "Separate"

        self.current_mid += 1
        self._test_separate(req, expected)
Ejemplo n.º 16
0
 def discover(self, client_callback, *args, **kwargs):
     req = Request()
     if "Token" in kwargs.keys():
         req.token = kwargs.get("Token")
     req.code = defines.inv_codes['GET']
     req.uri_path = ".well-known/core"
     req.type = defines.inv_types["CON"]
     self.send_callback(req, self.discover_results, client_callback)
Ejemplo n.º 17
0
    def test_td_coap_block_01(self):
        print "TD_COAP_BLOCK_01"
        path = "/large"

        req = Request()
        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.add_block2(0, 0, 1024)

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.responses["CONTENT"]
        expected.token = None
        expected.payload = None
        expected.block2 = (0, 1, 1024)

        exchange1 = (req, expected)
        self.current_mid += 1
        self.server_mid += 1

        req = Request()
        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.add_block2(1, 0, 1024)

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.responses["CONTENT"]
        expected.token = None
        expected.payload = None
        expected.block2 = (1, 0, 1024)

        exchange2 = (req, expected)
        self.current_mid += 1
        self.server_mid += 1

        self._test_plugtest([exchange1, exchange2])
Ejemplo n.º 18
0
    def test_get_multiple(self):
        print "TEST_GET_MULTIPLE"
        path = "/basic"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.proxy_uri = "coap://127.0.0.1:5684/basic"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = "Basic Resource"

        exchange1 = (req, expected)

        self.current_mid += 1

        # PREPARING SECOND EXPECTED RESPONSE (MAX AGE MUST BE CHECKED)
        req2 = Request()
        req2.code = defines.Codes.GET.number
        req2.uri_path = path
        req2.type = defines.Types["CON"]
        req2._mid = self.current_mid
        req2.destination = self.server_address
        req2.proxy_uri = "coap://127.0.0.1:5684/basic"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = "Basic Resource"
        expected.max_age = 61

        exchange2 = (req2, expected)

        self._test_with_client_delayed([exchange1, exchange2])
Ejemplo n.º 19
0
    def test_etag_deserialize(self):
        req = Request()
        req.type = defines.Types["CON"]
        req._mid = 1
        req.etag = bytearray([0xC5])

        serializer = Serializer()
        serialized = serializer.serialize(req)
        received_message = serializer.deserialize(serialized, ("127.0.0.1", 5683))

        self.assertEqual(req.etag, received_message.etag)
Ejemplo n.º 20
0
 def delete(self, client_callback, *args, **kwargs):
     path = args[0]
     req = Request()
     if "Token" in kwargs.keys():
         req.token = kwargs.get("Token")
         del kwargs["Token"]
     for key in kwargs:
         o = Option()
         o.number = defines.inv_options[key]
         o.value = kwargs[key]
         req.add_option(o)
     req.code = defines.inv_codes['DELETE']
     req.uri_path = path
     req.type = defines.inv_types["CON"]
     self.send_callback(req, self.delete_results, client_callback)
Ejemplo n.º 21
0
 def put(self, client_callback, *args, **kwargs):
     path, payload = args
     req = Request()
     if "Token" in kwargs.keys():
         req.token = kwargs.get("Token")
         del kwargs["Token"]
     for key in kwargs:
         o = Option()
         o.number = defines.inv_options[key]
         o.value = kwargs[key]
         req.add_option(o)
     req.code = defines.inv_codes['PUT']
     req.uri_path = path
     req.type = defines.inv_types["CON"]
     req.payload = payload
     self.send_callback(req, self.put_results, client_callback)
Ejemplo n.º 22
0
    def test_td_coap_block_01_client(self):
        print "TD_COAP_BLOCK_01"
        path = "/large"

        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = None
        req.destination = self.server_address
        req.block2 = (0, 0, 1024)

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = None
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = """"Me sabbee plenty"—grunted Queequeg, puffing away at his pipe and sitting up in bed.
"You gettee in," he added, motioning to me with his tomahawk, and throwing the clothes to one side. He really did this
in not only a civil but a really kind and charitable way. I stood looking at him a moment. For all his tattooings
he was on the whole a clean, comely looking cannibal. What's all this fuss I have been making about, thought I to
myself—the man's a human being just as I am: he has just as much reason to fear me, as I have to be afraid of him.
Better sleep with a sober cannibal than a drunken Christian.
"Landlord," said I, "tell him to stash his tomahawk there, or pipe, or whatever you call it; tell him to stop smoking,
in short, and I will turn in with him. But I don't fancy having a man smoking in bed with me. It's dangerous. Besides,
I ain't insured."
This being told to Queequeg, he at once complied, and again politely motioned me to get into bed—rolling over to one
side as much as to say—"I won't touch a leg of ye."
"Good night, landlord," said I, "you may go."
I turned in, and never slept better in my life.
Upon waking next morning about daylight, I found Queequeg's arm thrown over me in the most loving and affectionate
manner. You had almost thought I had been his wife. The counterpane was of patchwork, full of odd little
parti-coloured squares and triangles; and this arm of his tattooed all over with an interminable Cretan labyrinth
of a figure, no two parts of which were of one precise shade—owing I suppose to his keeping his arm at sea
unmethodically in sun and shade, his shirt sleeves irregularly rolled up at various times—this same arm of his,
I say, looked for all the world like a strip of that same patchwork quilt. Indeed, partly lying on it as the arm did
 when I first awoke, I could hardly tell it from the quilt, they so blended their hues together; and it was only by
 the sense of weight and pressure that I could tell that Queequeg was hugging"""
        expected.block2 = (1, 0, 1024)

        exchange1 = (req, expected)
        self.current_mid += 1
        self.server_mid += 1

        self._test_with_client([exchange1])
Ejemplo n.º 23
0
    def test_duplicate(self):
        print "TEST_DUPLICATE"
        path = "/test"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None

        self.current_mid += 1
        self._test_plugtest([(req, expected), (req, expected)])
Ejemplo n.º 24
0
    def test_td_coap_core_12(self):
        print "TD_COAP_CORE_12"
        path = "/seg1/seg2/seg3"
        req = Request()

        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.payload = "Test Resource"

        self.current_mid += 1
        self._test_with_client([(req, expected)])
Ejemplo n.º 25
0
    def test_td_coap_core_12(self):
        print "TD_COAP_CORE_12"
        path = "/seg1/seg2/seg3"
        req = Request()

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.responses["CONTENT"]
        expected.payload = "Test Resource"

        self.current_mid += 1
        self._test_plugtest(req, expected)
Ejemplo n.º 26
0
    def test_td_coap_link_01(self):
        print "TD_COAP_LINK_01"
        path = "/.well-known/core"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.content_type = defines.Content_types["application/link-format"]
        expected.payload = """</separate>;</large-update>;</seg1/seg2/seg3>;rt="Type1",</large>;</seg1/seg2>;rt="Type1",</test>;rt="Type1",</obs>;</long>;</seg1>;rt="Type1",</query>;rt="Type1","""

        self.current_mid += 1
        self._test_with_client([(req, expected)])
Ejemplo n.º 27
0
    def test_td_coap_core_08(self):
        print "TD_COAP_CORE_08"
        path = "/test"
        req = Request()

        req.code = defines.Codes.DELETE.number
        req.uri_path = path
        req.type = defines.Types["NON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["NON"]
        expected._mid = None
        expected.code = defines.Codes.DELETED.number
        expected.token = None
        expected.payload = None

        self.current_mid += 1
        self._test_with_client([(req, expected)])
Ejemplo n.º 28
0
    def test_td_coap_core_08(self):
        print "TD_COAP_CORE_08"
        path = "/test"
        req = Request()

        req.code = defines.inv_codes['DELETE']
        req.uri_path = path
        req.type = defines.inv_types["NON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["NON"]
        expected._mid = None
        expected.code = defines.responses["DELETED"]
        expected.token = None
        expected.payload = None

        self.current_mid += 1
        self._test_plugtest(req, expected)
Ejemplo n.º 29
0
    def test_td_coap_core_13(self):
        print "TD_COAP_CORE_13"
        path = "/query?first=1&second=2&third=3"
        req = Request()

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.responses["CONTENT"]
        expected.token = None
        expected.payload = "Test Resource"

        self.current_mid += 1
        self._test_plugtest(req, expected)
Ejemplo n.º 30
0
    def test_td_coap_obs_03(self):
        print "TD_COAP_OBS_03"
        path = "/obs"
        req = Request()

        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.observe = 0

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = "Observable Resource"
        expected.observe = 1

        self.current_mid += 1

        expected2 = Response()
        expected2.type = defines.Types["CON"]
        expected2._mid = self.server_mid
        expected2.code = defines.Codes.CONTENT.number
        expected2.token = None
        expected2.payload = "Observable Resource"
        expected2.observe = 1

        rst = Response()
        rst.type = defines.Types["RST"]
        rst._mid = self.server_mid
        rst.code = defines.Codes.EMPTY.number
        rst.destination = self.server_address
        rst.token = None
        rst.payload = None

        self.current_mid += 1
        self.server_mid += 1
        self._test_plugtest([(req, expected), (None, expected2), (rst, None)])
Ejemplo n.º 31
0
    def test_td_coap_core_06(self):
        print "TD_COAP_CORE_06"
        path = "/test_post"
        req = Request()

        req.code = defines.Codes.POST.number
        req.uri_path = path
        req.type = defines.Types["NON"]
        req.content_type = defines.Content_types["application/xml"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.payload = "<value>test</value>"

        expected = Response()
        expected.type = defines.Types["NON"]
        expected._mid = None
        expected.code = defines.Codes.CREATED.number
        expected.token = None
        expected.payload = None
        expected.location_path = "/test_post"

        self.current_mid += 1
        self._test_with_client([(req, expected)])
Ejemplo n.º 32
0
    def test_uri_discovery(self):
        print("Uri discovery")
        path = ".well-known/core"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.content_type = defines.Content_types["application/link-format"]
        expected.payload = '</rd-lookup/res>;rt="core.rd-lookup-res";ct=40,</rd>;rt="core.rd";ct=40,' \
                           '</rd-lookup/ep>;rt="core.rd-lookup-ep";ct=40'

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 33
0
    def test_registration(self):
        print("Registration")
        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683"
        req = Request()
        req.code = defines.Codes.POST.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = defines.Content_types["application/link-format"]
        req.payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";' \
                      'anchor="coap://spurious.example.com:5683",</sensors/light>;ct=41;rt="light-lux";if="sensor"'

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CREATED.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 34
0
    def test_wildcard_res(self):
        print("Use wildcard * to find resources")
        client = HelperClient(self.server_address)
        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        client.post(path, payload, None, None, **ct)
        path = "rd?ep=node2&con=coap://[2001:db8:3::123]:61616"
        payload = '</temp>;rt="temperature";anchor="coap://[2001:db8:3::123]:61616"'
        client.post(path, payload, None, None, **ct)
        client.stop()

        path = "rd-lookup/res?rt=temp*"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.content_type = defines.Content_types[
            "application/link-format"]
        expected.payload = '<coap://local-proxy-old.example.com:5683/sensors/temp>;ct=41;rt="temperature-c";' \
                           'if="sensor";anchor="coap://spurious.example.com:5683",' \
                           '<coap://[2001:db8:3::123]:61616/temp>;rt="temperature";' \
                           'anchor="coap://[2001:db8:3::123]:61616"'

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 35
0
    def test_update_expired(self):
        print("Update expired registration resource")
        client = HelperClient(self.server_address)
        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683&lt=60"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        response = client.post(path, payload, None, None, **ct)
        # After 61 seconds the resource will be expired
        sleep(61)

        loc_path = response.location_path
        client.post(loc_path, None)
        client.stop()

        path = "rd-lookup/res?ep=node1&rt=temperature-c"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.content_type = defines.Content_types[
            "application/link-format"]
        expected.payload = '<coap://local-proxy-old.example.com:5683/sensors/temp>;ct=41;rt="temperature-c";' \
                           'if="sensor";anchor="coap://spurious.example.com:5683"'

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 36
0
    def test_duplicate_not_completed(self):
        print("TEST_DUPLICATE_NOT_COMPLETED")
        path = "/long"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None

        expected2 = Response()
        expected2.type = defines.Types["CON"]
        expected2._mid = None
        expected2.code = defines.Codes.CONTENT.number
        expected2.token = None

        self.current_mid += 1
        self._test_plugtest([(req, None), (req, expected), (None, expected2)])
Ejemplo n.º 37
0
    def test_no_response(self):
        print "TEST_NO_RESPONSE"
        path = "/long"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None

        expected2 = Response()
        expected2.type = defines.Types["CON"]
        expected2._mid = None
        expected2.code = defines.Codes.CONTENT.number
        expected2.token = None

        self.current_mid += 1
        self._test_plugtest([(req, expected), (None, expected2), (None, expected2),  (None, expected2)])
Ejemplo n.º 38
0
    def test_td_coap_block_03(self):
        print("TD_COAP_BLOCK_03")
        path = "/large-update"

        req = Request()
        req.code = defines.Codes.PUT.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.payload = """"Me sabbee plenty"—grunted Queequeg, puffing away at his pipe """
        req.block1 = (0, 1, 64)

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTINUE.number
        expected.token = None
        expected.payload = None
        expected.block1 = (0, 1, 64)

        exchange1 = (req, expected)
        self.current_mid += 1
        self.server_mid += 1

        req = Request()
        req.code = defines.Codes.PUT.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.payload = """and sitting up in bed. "You gettee in," he added, motioning"""
        req.block1 = (1, 0, 64)

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CHANGED.number
        expected.token = None
        expected.payload = None

        exchange2 = (req, expected)
        self.current_mid += 1
        self.server_mid += 1

        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = """"Me sabbee plenty"—grunted Queequeg, puffing away at his pipe and sitting up in bed. "You gettee in," he added, motioning"""

        exchange3 = (req, expected)
        self.current_mid += 1

        self._test_plugtest([exchange1, exchange2, exchange3])
Ejemplo n.º 39
0
    def test_td_coap_core_03(self):
        print("TD_COAP_CORE_03")
        path = "/test"
        req = Request()

        req.code = defines.Codes.PUT.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req.content_type = defines.Content_types["application/xml"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.payload = "<value>test</value>"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CHANGED.number
        expected.token = None
        expected.payload = None

        self.current_mid += 1
        exchange1 = (req, expected)

        req = Request()

        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = "Test Resource"

        self.current_mid += 1
        exchange2 = (req, expected)

        req = Request()

        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.accept = defines.Content_types["application/xml"]

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = "<value>test</value>"
        expected.content_type = defines.Content_types["application/xml"]

        self.current_mid += 1
        exchange3 = (req, expected)
        self._test_with_client([exchange1, exchange2, exchange3])
Ejemplo n.º 40
0
def callback():
    try:
        index = listbox.curselection()[0]
        # get the line's text
        server_text = str(listbox.get(index))
        if (server_text == ""):
            print "ERROR : Empty selection"
            return
    except:
        print "ERROR !"
        return AttributeError
    proxy_texter = str(label_proxy.cget("text"))
    text_test = path_text.get("1.0", END)
    path_texter = str(text_test)
    print "Selected : " + str(server_text)
    print "chosen path : " + str(path_texter)
    server_text = "198.199.92.83"
    proxy_texter = "104.236.174.175"
    # Setting up the application
    setup_time_begin = time.time()
    server_address = (str(proxy_texter), 5684)
    current_mid = random.randint(1, 1000)
    client = HelperClient(server_address)
    setup_time_end = time.time()

    print "Starting the first request"
    print "\nRequesting for Resource 1"
    first_request_begin = time.time()
    # Starting first request
    path = "/basic1"
    req = Request()
    req._usecache = use_cache
    req.code = defines.Codes.GET.number
    req.uri_path = path
    req.type = defines.Types["CON"]
    req._mid = current_mid
    req.destination = server_address
    req.proxy_uri = "coap://" + str(server_text) + ":5683/basic1"
    received_message = client.send_request(req)
    first_request_end = time.time()
    time.sleep(21)

    print "Starting the second request"
    print "\nRequesting for Resource 1 again"
    second_request_begin = time.time()
    # Starting second request
    current_mid = current_mid + 1
    req2 = Request()
    req2._usecache = use_cache
    req2.code = defines.Codes.GET.number
    path = "/basic1"
    req2.uri_path = path
    req2.type = defines.Types["CON"]
    req2._mid = current_mid
    req2.destination = server_address
    req2.proxy_uri = "coap://" + server_text + ":5683/basic1"
    received_message = client.send_request(req2)
    second_request_end = time.time()

    time.sleep(5)

    print "Tearing down application"
    # Tearing down application
    print "DONE !"
    print "-------------------"
    print "Printing Analytics"
    print "--------------------"
    print "Build Time : " + str(setup_time_end - setup_time_begin)
    print "First request : " + str(first_request_end - first_request_begin)
    print "Second request : " + str(second_request_end - second_request_begin)
    print "--------------------------"
    print "TOTAL TIME TAKEN : " + str(
        (second_request_end - second_request_begin) +
        (first_request_end - first_request_begin))
    print "--------------------------"
Ejemplo n.º 41
0
def callback():
    try:
        index = listbox.curselection()[0]
        # get the line's text
        server_text = str(listbox.get(index))
        if (server_text == ""):
            print "ERROR : Empty selection"
            return
    except:
        print "ERROR !"
        return AttributeError
    proxy_texter = str(label_proxy.cget("text"))
    text_test = path_text.get("1.0", END)
    path_texter = str(text_test)
    print "Selected : " + str(server_text)
    print "chosen path : " + str(path_texter)
    server_text = "198.199.92.83"
    proxy_texter = "104.236.174.175"
    # Setting up the application
    setup_time_begin = time.time()
    server_address = (str(proxy_texter), 5684)
    current_mid = random.randint(1, 1000)
    client = HelperClient(server_address)
    setup_time_end = time.time()

    print "Starting the first request"
    print "\nRequesting for Resource 1"
    first_request_begin = time.time()
    # Starting first request
    path = "/basic1"
    req = Request()
    req._usecache = use_cache
    req.code = defines.Codes.GET.number
    req.uri_path = path
    req.type = defines.Types["CON"]
    req._mid = current_mid
    req.destination = server_address
    req.proxy_uri = "coap://" + str(server_text) + ":5683/basic1"
    received_message = client.send_request(req)
    first_request_end = time.time()
    time.sleep(5)

    print "Starting the second request"
    print "\nRequesting for Resource 2"
    second_request_begin = time.time()
    # Starting second request
    current_mid = current_mid + 1
    req2 = Request()
    req2._usecache = use_cache
    req2.code = defines.Codes.GET.number
    path = "/basic2"
    req2.uri_path = path
    req2.type = defines.Types["CON"]
    req2._mid = current_mid
    req2.destination = server_address
    req2.proxy_uri = "coap://" + server_text + ":5683/basic2"
    received_message = client.send_request(req2)
    second_request_end = time.time()

    time.sleep(5)

    print "Starting the third request"
    print "\nRequesting for Resource 3"
    third_request_begin = time.time()
    # Starting third request
    current_mid = current_mid + 1
    req3 = Request()
    req3._usecache = use_cache
    req3.code = defines.Codes.GET.number
    path = "/basic3"
    req3.uri_path = path
    req3.type = defines.Types["CON"]
    req3._mid = current_mid
    req3.destination = server_address
    req3.proxy_uri = "coap://" + server_text + ":5683/basic3"
    received_message = client.send_request(req3)
    third_request_end = time.time()
    time.sleep(5)

    print "Starting the fourth request"
    print "\nRequesting for Resource 1 again"
    fourth_request_begin = time.time()
    # Starting first request
    path = "/basic1"
    current_mid = current_mid + 1
    req4 = Request()
    req4._usecache = use_cache
    req4.code = defines.Codes.GET.number
    req4.uri_path = path
    req4.type = defines.Types["CON"]
    req4._mid = current_mid
    req4.destination = server_address
    req4.proxy_uri = "coap://" + server_text + ":5683/basic1"
    received_message = client.send_request(req4)
    fourth_request_end = time.time()
    time.sleep(5)

    print "Starting the fifth request"
    print "\nRequesting for Resource 2 again"
    fifth_request_begin = time.time()
    # Starting second request
    current_mid = current_mid + 1
    req5 = Request()
    req5._usecache = use_cache
    req5.code = defines.Codes.GET.number
    path = "/basic2"
    req5.uri_path = path
    req5.type = defines.Types["CON"]
    req5._mid = current_mid
    req5.destination = server_address
    req5.proxy_uri = "coap://" + server_text + ":5683/basic2"
    received_message = client.send_request(req5)
    fifth_request_end = time.time()
    time.sleep(5)

    print "Starting the sixth request"
    print "\nRequesting for Resource 3 again"
    # Starting third request
    sixth_request_begin = time.time()
    current_mid = current_mid + 1
    req6 = Request()
    req6._usecache = use_cache
    req6.code = defines.Codes.GET.number
    path = "/basic3"
    req6.uri_path = path
    req6.type = defines.Types["CON"]
    req6._mid = current_mid
    req6.destination = server_address
    req6.proxy_uri = "coap://" + server_text + ":5683/basic3"
    received_message = client.send_request(req6)
    sixth_request_end = time.time()
    time.sleep(5)

    print "Starting the seventh request"
    print "\nRequesting for Resource 4"
    seventh_request_begin = time.time()
    # Starting first request
    path = "/basic4"
    current_mid = current_mid + 1
    req7 = Request()
    req7._usecache = use_cache
    req7.code = defines.Codes.GET.number
    req7.uri_path = path
    req7.type = defines.Types["CON"]
    req7._mid = current_mid
    req7.destination = server_address
    req7.proxy_uri = "coap://" + server_text + ":5683/basic4"
    received_message = client.send_request(req7)
    seventh_request_end = time.time()
    time.sleep(5)

    print "Starting the eighth request"
    print "\nRequesting for Resource 5"
    eighth_request_begin = time.time()
    # Starting second request
    current_mid = current_mid + 1
    req8 = Request()
    req8._usecache = use_cache
    req8.code = defines.Codes.GET.number
    path = "/basic5"
    req8.uri_path = path
    req8.type = defines.Types["CON"]
    req8._mid = current_mid
    req8.destination = server_address
    req8.proxy_uri = "coap://" + server_text + ":5683/basic5"
    received_message = client.send_request(req8)
    eighth_request_end = time.time()
    time.sleep(5)

    print "Starting the ninth request"
    print "\nRequesting for Resource 6"
    ninth_request_begin = time.time()
    # Starting third request
    current_mid = current_mid + 1
    req9 = Request()
    req9._usecache = use_cache
    req9.code = defines.Codes.GET.number
    path = "/basic6"
    req9.uri_path = path
    req9.type = defines.Types["CON"]
    req9._mid = current_mid
    req9.destination = server_address
    req9.proxy_uri = "coap://" + server_text + ":5683/basic6"
    received_message = client.send_request(req9)
    ninth_request_end = time.time()
    time.sleep(5)

    print "Starting the tenth request"
    print "\nRequesting for Resource 4 again"
    tenth_request_begin = time.time()
    # Starting third request
    current_mid = current_mid + 1
    req10 = Request()
    req10._usecache = use_cache
    req10.code = defines.Codes.GET.number
    path = "/basic4"
    req10.uri_path = path
    req10.type = defines.Types["CON"]
    req10._mid = current_mid
    req10.destination = server_address
    req10.proxy_uri = "coap://" + server_text + ":5683/basic4"
    received_message = client.send_request(req10)
    tenth_request_end = time.time()
    time.sleep(5)

    print "Starting the eleven request"
    print "\nRequesting for Resource 7"
    eleventh_request_begin = time.time()
    # Starting third request
    current_mid = current_mid + 1
    req11 = Request()
    req11._usecache = use_cache
    req11.code = defines.Codes.GET.number
    path = "/basic7"
    req11.uri_path = path
    req11.type = defines.Types["CON"]
    req11._mid = current_mid
    req11.destination = server_address
    req11.proxy_uri = "coap://" + server_text + ":5683/basic7"
    received_message = client.send_request(req11)
    eleventh_request_end = time.time()
    print "Tearing down application"
    # Tearing down application
    print "DONE !"
    print "-------------------"
    print "Printing Analytics"
    print "--------------------"
    print "Build Time : " + str(setup_time_end - setup_time_begin)
    print "First request : " + str(first_request_end - first_request_begin)
    print "Second request : " + str(second_request_end - second_request_begin)
    print "Third request : " + str(third_request_end - third_request_begin)
    print "Fourth request : " + str(fourth_request_end - fourth_request_begin)
    print "Fifth request : " + str(fifth_request_end - fifth_request_begin)
    print "Sixth request : " + str(sixth_request_end - sixth_request_begin)
    print "Seventh request : " + str(seventh_request_end -
                                     seventh_request_begin)
    print "Eighth request : " + str(eighth_request_end - eighth_request_begin)
    print "Ninth request : " + str(ninth_request_end - ninth_request_begin)
    print "Tenth request : " + str(tenth_request_end - tenth_request_begin)
    print "Eleventh request : " + str(eleventh_request_end -
                                      eleventh_request_begin)
    print "--------------------------"
    print "TOTAL TIME TAKEN : " + str(
        (first_request_end - first_request_begin) +
        (second_request_end - second_request_begin) +
        (third_request_end - third_request_begin) +
        (fourth_request_end - fourth_request_begin) +
        (fifth_request_end - fifth_request_begin) +
        (sixth_request_end - sixth_request_begin) +
        (seventh_request_end - seventh_request_begin) +
        (eighth_request_end - eighth_request_begin) +
        (ninth_request_end - ninth_request_begin) +
        (tenth_request_end - tenth_request_begin) +
        (eleventh_request_end - eleventh_request_begin))
    print "--------------------------"
Ejemplo n.º 42
0
    def test_advanced(self):
        print("TEST_ADVANCED")
        path = "/advanced"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.max_age = 20
        expected.token = None

        exchange1 = (req, expected)

        self.current_mid += 1

        req = Request()
        req.code = defines.Codes.POST.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CREATED.number
        expected.payload = "Response changed through POST"
        expected.token = None

        exchange2 = (req, expected)

        self.current_mid += 1

        req = Request()
        req.code = defines.Codes.PUT.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CHANGED.number
        expected.payload = "Response changed through PUT"
        expected.token = None

        exchange3 = (req, expected)

        self.current_mid += 1

        req = Request()
        req.code = defines.Codes.DELETE.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.DELETED.number
        expected.payload = "Response deleted"
        expected.token = None

        exchange4 = (req, expected)

        self.current_mid += 1
        self._test_with_client([exchange1, exchange2, exchange3, exchange4])
Ejemplo n.º 43
0
    def test_get_delete(self):
        print "TEST_GET_DELETE"
        path = "/basic"

        req2 = Request()
        req2.code = defines.Codes.GET.number
        req2.uri_path = path
        req2.type = defines.Types["CON"]
        req2._mid = self.current_mid
        req2.destination = self.server_address
        req2.proxy_uri = "coap://127.0.0.1:5684/storage/new"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.NOT_FOUND.number
        expected.token = None
        expected.payload = None

        exchange0 = (req2, expected)

        self.current_mid += 1

        req = Request()
        req.code = defines.Codes.POST.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.proxy_uri = "coap://127.0.0.1:5684/storage/new"
        req.payload = "Hello"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CREATED.number
        expected.token = None
        expected.payload = None

        exchange1 = (req, expected)

        self.current_mid += 1

        # PREPARING SECOND EXPECTED RESPONSE
        req2 = Request()
        req2.code = defines.Codes.GET.number
        req2.uri_path = path
        req2.type = defines.Types["CON"]
        req2._mid = self.current_mid
        req2.destination = self.server_address
        req2.proxy_uri = "coap://127.0.0.1:5684/storage/new"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = "Hello"

        exchange2 = (req2, expected)

        self.current_mid += 1

        # PREPARING THIRD EXPECTED RESPONSE
        req3 = Request()
        req3.code = defines.Codes.DELETE.number
        req3.uri_path = path
        req3.type = defines.Types["CON"]
        req3._mid = self.current_mid
        req3.destination = self.server_address
        req3.proxy_uri = "coap://127.0.0.1:5684/storage/new"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.DELETED.number
        expected.token = None
        expected.payload = None

        exchange3 = (req3, expected)

        self.current_mid += 1

        # PREPARING FOURTH EXPECTED RESPONSE
        req4 = Request()
        req4.code = defines.Codes.GET.number
        req4.uri_path = path
        req4.type = defines.Types["CON"]
        req4._mid = self.current_mid
        req4.destination = self.server_address
        req4.proxy_uri = "coap://127.0.0.1:5684/storage/new"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.NOT_FOUND.number
        expected.token = None

        exchange4 = (req4, expected)

        self.current_mid += 1

        self._test_with_client_delayed(
            [exchange0, exchange1, exchange2, exchange3, exchange4])
Ejemplo n.º 44
0
    def test_get_multiple(self):
        print "TEST_GET_MULTIPLE"
        path = "/basic1"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.proxy_uri = "coap://127.0.0.1:5684/basic1"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = "Basic Resource"

        exchange1 = (req, expected)

        self.current_mid += 1

        #PREPARING SECOND EXPECTED RESPONSE (MAX AGE MUST BE CHECKED)
        req2 = Request()
        req2.code = defines.Codes.GET.number
        path = "/basic2"
        req2.uri_path = path
        req2.type = defines.Types["CON"]
        req2._mid = self.current_mid
        req2.destination = self.server_address
        req2.proxy_uri = "coap://127.0.0.1:5684/basic2"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = "Basic Resource"
        expected.max_age = 61

        exchange2 = (req2, expected)
        self.current_mid += 1
        req3 = Request()
        req3.code = defines.Codes.GET.number
        path = "/basic3"
        req3.uri_path = path
        req3.type = defines.Types["CON"]
        req3._mid = self.current_mid
        req3.destination = self.server_address
        req3.proxy_uri = "coap://127.0.0.1:5684/basic3"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = "Basic Resource"
        expected.max_age = 61

        exchange3 = (req3, expected)
        #self._test_with_client_delayed([exchange1,exchange2])
        self._test_with_client_delayed([exchange1, exchange2, exchange3])
Ejemplo n.º 45
0
    def test_not_allowed(self):
        print "TEST_NOT_ALLOWED"
        path = "/void"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.METHOD_NOT_ALLOWED.number
        expected.token = None

        exchange1 = (req, expected)

        self.current_mid += 1

        req = Request()
        req.code = defines.Codes.POST.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.METHOD_NOT_ALLOWED.number
        expected.token = None

        exchange2 = (req, expected)

        self.current_mid += 1

        req = Request()
        req.code = defines.Codes.PUT.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.METHOD_NOT_ALLOWED.number
        expected.token = None

        exchange3 = (req, expected)

        self.current_mid += 1

        req = Request()
        req.code = defines.Codes.DELETE.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.METHOD_NOT_ALLOWED.number
        expected.token = None

        exchange4 = (req, expected)

        self.current_mid += 1
        self._test_with_client([exchange1, exchange2, exchange3, exchange4])
Ejemplo n.º 46
0
    def test_get_etag(self):
        print "TEST_GET_ETAG"
        path = "/etag"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.proxy_uri = "coap://127.0.0.1:5684/etag"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = None

        exchange1 = (req, expected)

        self.current_mid += 1

        # PREPARING SECOND EXPECTED RESPONSE
        req2 = Request()
        req2.code = defines.Codes.GET.number
        req2.uri_path = path
        req2.type = defines.Types["CON"]
        req2._mid = self.current_mid
        req2.destination = self.server_address
        req2.proxy_uri = "coap://127.0.0.1:5684/etag"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.etag = 1
        expected.max_age = 1

        exchange2 = (req2, expected)

        self.current_mid += 1

        # PREPARING THIRD EXPECTED RESPONSE
        req3 = Request()
        req3.code = defines.Codes.POST.number
        req3.uri_path = path
        req3.type = defines.Types["CON"]
        req3._mid = self.current_mid
        req3.destination = self.server_address
        req3.proxy_uri = "coap://127.0.0.1:5684/etag"
        req3.payload = "Hello"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CHANGED.number
        expected.token = None
        expected.payload = None
        expected.etag = 2
        expected.location_path = "etag"

        exchange3 = (req3, expected)

        self.current_mid += 1

        # PREPARING FOURTH EXPECTED RESPONSE
        req4 = Request()
        req4.code = defines.Codes.GET.number
        req4.uri_path = path
        req4.type = defines.Types["CON"]
        req4._mid = self.current_mid
        req4.destination = self.server_address
        req4.proxy_uri = "coap://127.0.0.1:5684/etag"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = "Hello"
        expected.etag = 2

        exchange4 = (req4, expected)

        self.current_mid += 1

        self._test_with_client_delayed(
            [exchange1, exchange2, exchange3, exchange4])