def test_equality(self):
        a = WebhookInfo(
            url=self.url,
            has_custom_certificate=self.has_custom_certificate,
            pending_update_count=self.pending_update_count,
            last_error_date=self.last_error_date,
            max_connections=self.max_connections,
        )
        b = WebhookInfo(
            url=self.url,
            has_custom_certificate=self.has_custom_certificate,
            pending_update_count=self.pending_update_count,
            last_error_date=self.last_error_date,
            max_connections=self.max_connections,
        )
        c = WebhookInfo(
            url="http://github.com",
            has_custom_certificate=True,
            pending_update_count=78,
            last_error_date=0,
            max_connections=1,
        )
        d = LoginUrl("text.com")

        assert a == b
        assert hash(a) == hash(b)
        assert a is not b

        assert a != c
        assert hash(a) != hash(c)

        assert a != d
        assert hash(a) != hash(d)
    def test_de_json(self, bot):
        json_dict = {
            "url": self.url,
            "has_custom_certificate": self.has_custom_certificate,
            "pending_update_count": self.pending_update_count,
            "last_error_date": self.last_error_date,
            "max_connections": self.max_connections,
            "allowed_updates": self.allowed_updates,
            "ip_address": self.ip_address,
            "last_synchronization_error_date": self.last_synchronization_error_date,
        }
        webhook_info = WebhookInfo.de_json(json_dict, bot)

        assert webhook_info.url == self.url
        assert webhook_info.has_custom_certificate == self.has_custom_certificate
        assert webhook_info.pending_update_count == self.pending_update_count
        assert isinstance(webhook_info.last_error_date, datetime)
        assert webhook_info.last_error_date == from_timestamp(self.last_error_date)
        assert webhook_info.max_connections == self.max_connections
        assert webhook_info.allowed_updates == self.allowed_updates
        assert webhook_info.ip_address == self.ip_address
        assert isinstance(webhook_info.last_synchronization_error_date, datetime)
        assert webhook_info.last_synchronization_error_date == from_timestamp(
            self.last_synchronization_error_date
        )

        none = WebhookInfo.de_json(None, bot)
        assert none is None
Пример #3
0
def webhook_info():
    return WebhookInfo(
        url=TestWebhookInfo.url,
        has_custom_certificate=TestWebhookInfo.has_custom_certificate,
        pending_update_count=TestWebhookInfo.pending_update_count,
        last_error_date=TestWebhookInfo.last_error_date,
        max_connections=TestWebhookInfo.max_connections,
        allowed_updates=TestWebhookInfo.allowed_updates,
    )
Пример #4
0
async def test_shadow_webhook_secret(mocker):
    info_unsafe = WebhookInfo(
        url="http://localhost/webhook/secret/",
        has_custom_certificate=False,
        pending_update_count=0,
    )

    mocker.patch("telegram.util.settings.webhook_secret", "secret")
    info_safe = shadow_webhook_secret(info_unsafe)

    assert info_safe.url == "http://localhost/webhook/"