Beispiel #1
0
  def test_notification_from_headers(self):
    headers = {
        'X-GoOG-CHANNEL-ID': 'myid',
        'X-Goog-MESSAGE-NUMBER': '1',
        'X-Goog-rESOURCE-STATE': 'sync',
        'X-Goog-reSOURCE-URI': 'http://example.com/',
        'X-Goog-resOURCE-ID': 'http://example.com/resource_1',
        }

    ch = channel.Channel('web_hook', 'myid', 'mytoken',
                         'http://example.org/callback',
                         expiration=0,
                         params={'extra': 'info'},
                         resource_id='the_resource_id',
                         resource_uri='http://example.com/resource_1')

    # Good test case.
    n = channel.notification_from_headers(ch, headers)
    self.assertEqual('http://example.com/resource_1', n.resource_id)
    self.assertEqual('http://example.com/', n.resource_uri)
    self.assertEqual('sync', n.state)
    self.assertEqual(1, n.message_number)

    # Detect id mismatch.
    ch.id = 'different_id'
    try:
      n = channel.notification_from_headers(ch, headers)
      self.fail('Should have raised exception')
    except errors.InvalidNotificationError:
      pass

    # Set the id back to a correct value.
    ch.id = 'myid'
    def test_basic(self):
        ch = channel.Channel(
            "web_hook",
            "myid",
            "mytoken",
            "http://example.org/callback",
            expiration=0,
            params={"extra": "info"},
            resource_id="the_resource_id",
            resource_uri="http://example.com/resource_1",
        )

        # Converting to a body.
        body = ch.body()
        self.assertEqual("http://example.org/callback", body["address"])
        self.assertEqual("myid", body["id"])
        self.assertEqual("missing", body.get("expiration", "missing"))
        self.assertEqual("info", body["params"]["extra"])
        self.assertEqual("the_resource_id", body["resourceId"])
        self.assertEqual("http://example.com/resource_1", body["resourceUri"])
        self.assertEqual("web_hook", body["type"])

        # Converting to a body with expiration set.
        ch.expiration = 1
        body = ch.body()
        self.assertEqual(1, body.get("expiration", "missing"))

        # Converting to a body after updating with a response body.
        ch.update(
            {
                "resourceId": "updated_res_id",
                "resourceUri": "updated_res_uri",
                "some_random_parameter": 2,
            }
        )

        body = ch.body()
        self.assertEqual("http://example.org/callback", body["address"])
        self.assertEqual("myid", body["id"])
        self.assertEqual(1, body.get("expiration", "missing"))
        self.assertEqual("info", body["params"]["extra"])
        self.assertEqual("updated_res_id", body["resourceId"])
        self.assertEqual("updated_res_uri", body["resourceUri"])
        self.assertEqual("web_hook", body["type"])
    def test_basic(self):
        ch = channel.Channel('web_hook',
                             'myid',
                             'mytoken',
                             'http://example.org/callback',
                             expiration=0,
                             params={'extra': 'info'},
                             resource_id='the_resource_id',
                             resource_uri='http://example.com/resource_1')

        # Converting to a body.
        body = ch.body()
        self.assertEqual('http://example.org/callback', body['address'])
        self.assertEqual('myid', body['id'])
        self.assertEqual('missing', body.get('expiration', 'missing'))
        self.assertEqual('info', body['params']['extra'])
        self.assertEqual('the_resource_id', body['resourceId'])
        self.assertEqual('http://example.com/resource_1', body['resourceUri'])
        self.assertEqual('web_hook', body['type'])

        # Converting to a body with expiration set.
        ch.expiration = 1
        body = ch.body()
        self.assertEqual(1, body.get('expiration', 'missing'))

        # Converting to a body after updating with a response body.
        ch.update({
            'resourceId': 'updated_res_id',
            'resourceUri': 'updated_res_uri',
            'some_random_parameter': 2,
        })

        body = ch.body()
        self.assertEqual('http://example.org/callback', body['address'])
        self.assertEqual('myid', body['id'])
        self.assertEqual(1, body.get('expiration', 'missing'))
        self.assertEqual('info', body['params']['extra'])
        self.assertEqual('updated_res_id', body['resourceId'])
        self.assertEqual('updated_res_uri', body['resourceUri'])
        self.assertEqual('web_hook', body['type'])
Beispiel #4
0
    def test_notification_from_headers(self):
        headers = {
            "X-GoOG-CHANNEL-ID": "myid",
            "X-Goog-MESSAGE-NUMBER": "1",
            "X-Goog-rESOURCE-STATE": "sync",
            "X-Goog-reSOURCE-URI": "http://example.com/",
            "X-Goog-resOURCE-ID": "http://example.com/resource_1",
        }

        ch = channel.Channel(
            "web_hook",
            "myid",
            "mytoken",
            "http://example.org/callback",
            expiration=0,
            params={"extra": "info"},
            resource_id="the_resource_id",
            resource_uri="http://example.com/resource_1",
        )

        # Good test case.
        n = channel.notification_from_headers(ch, headers)
        self.assertEqual("http://example.com/resource_1", n.resource_id)
        self.assertEqual("http://example.com/", n.resource_uri)
        self.assertEqual("sync", n.state)
        self.assertEqual(1, n.message_number)

        # Detect id mismatch.
        ch.id = "different_id"
        try:
            n = channel.notification_from_headers(ch, headers)
            self.fail("Should have raised exception")
        except errors.InvalidNotificationError:
            pass

        # Set the id back to a correct value.
        ch.id = "myid"