Esempio n. 1
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
Esempio 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
Esempio n. 3
0
    def test_edit_resource(self):
        print("TEST_EDIT_RESOURCE")
        path = "/obs"
        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.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
        expected.location_path = "/obs"

        self.current_mid += 1
        self._test_with_client([(req, expected)])
Esempio n. 4
0
    def test_edit_resource(self):
        print "TEST_EDIT_RESOURCE"
        path = "/obs"
        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.payload = "<value>test</value>"

        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 = "/obs"

        self.current_mid += 1
        self._test_with_client([(req, expected)])
Esempio n. 5
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)])
Esempio n. 6
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)])
Esempio n. 7
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])
Esempio n. 8
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
        expected.etag = str(0)

        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 = str(0)
        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 = str(1)
        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 = str(1)

        exchange4 = (req4, expected)

        self.current_mid += 1

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