예제 #1
0
    def test_equality(self):
        a = OrderInfo(
            'name', 'number', 'mail',
            ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1'))
        b = OrderInfo(
            'name', 'number', 'mail',
            ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1'))
        c = OrderInfo(
            'name', 'number', 'mail',
            ShippingAddress('GB', '', 'London', '13 Grimmauld Place', '',
                            'WC1'))
        d = OrderInfo(
            'name', 'number', 'e-mail',
            ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1'))
        e = ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1')

        assert a == b
        assert hash(a) == hash(b)

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

        assert a != d
        assert hash(a) != hash(d)

        assert a != e
        assert hash(a) != hash(e)
예제 #2
0
class TestOrderInfo(object):
    name = 'name'
    phone_number = 'phone_number'
    email = 'email'
    shipping_address = ShippingAddress('GB', '', 'London',
                                       '12 Grimmauld Place', '', 'WC1')

    def test_de_json(self, bot):
        json_dict = {
            'name': TestOrderInfo.name,
            'phone_number': TestOrderInfo.phone_number,
            'email': TestOrderInfo.email,
            'shipping_address': TestOrderInfo.shipping_address.to_dict()
        }
        order_info = OrderInfo.de_json(json_dict, bot)

        assert order_info.name == self.name
        assert order_info.phone_number == self.phone_number
        assert order_info.email == self.email
        assert order_info.shipping_address == self.shipping_address

    def test_to_dict(self, order_info):
        order_info_dict = order_info.to_dict()

        assert isinstance(order_info_dict, dict)
        assert order_info_dict['name'] == order_info.name
        assert order_info_dict['phone_number'] == order_info.phone_number
        assert order_info_dict['email'] == order_info.email
        assert order_info_dict[
            'shipping_address'] == order_info.shipping_address.to_dict()
예제 #3
0
def shipping_address():
    return ShippingAddress(TestShippingAddress.country_code,
                           TestShippingAddress.state,
                           TestShippingAddress.city,
                           TestShippingAddress.street_line1,
                           TestShippingAddress.street_line2,
                           TestShippingAddress.post_code)
예제 #4
0
    def de_json(cls, data, bot):
        if not data:
            return cls()

        data = super(OrderInfo, cls).de_json(data, bot)

        data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)

        return cls(**data)
예제 #5
0
    def de_json(cls, data, bot):
        if not data:
            return cls()

        data = super(OrderInfo, cls).de_json(data, bot)

        data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)

        return cls(**data)
def shiping_query():
    return Update(
        1,
        shipping_query=ShippingQuery(
            42,
            User(1, 'test user', False),
            'invoice_payload',
            ShippingAddress('EN', 'my_state', 'my_city', 'steer_1', '', 'post_code'),
        ),
    )
예제 #7
0
    def test_equality(self):
        a = ShippingAddress(
            self.country_code,
            self.state,
            self.city,
            self.street_line1,
            self.street_line2,
            self.post_code,
        )
        b = ShippingAddress(
            self.country_code,
            self.state,
            self.city,
            self.street_line1,
            self.street_line2,
            self.post_code,
        )
        d = ShippingAddress('', self.state, self.city, self.street_line1,
                            self.street_line2, self.post_code)
        d2 = ShippingAddress(self.country_code, '', self.city,
                             self.street_line1, self.street_line2,
                             self.post_code)
        d3 = ShippingAddress(self.country_code, self.state, '',
                             self.street_line1, self.street_line2,
                             self.post_code)
        d4 = ShippingAddress(self.country_code, self.state, self.city, '',
                             self.street_line2, self.post_code)
        d5 = ShippingAddress(self.country_code, self.state, self.city,
                             self.street_line1, '', self.post_code)
        d6 = ShippingAddress(self.country_code, self.state, self.city,
                             self.street_line1, self.street_line2, '')

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

        assert a != d
        assert hash(a) != hash(d)

        assert a != d2
        assert hash(a) != hash(d2)

        assert a != d3
        assert hash(a) != hash(d3)

        assert a != d4
        assert hash(a) != hash(d4)

        assert a != d5
        assert hash(a) != hash(d5)

        assert a != d6
        assert hash(6) != hash(d6)
예제 #8
0
    def de_json(cls, data: Optional[JSONDict], bot: 'Bot') -> Optional['ShippingQuery']:
        data = cls.parse_data(data)

        if not data:
            return None

        data['from_user'] = User.de_json(data.pop('from'), bot)
        data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)

        return cls(bot=bot, **data)
예제 #9
0
    def de_json(cls, data, bot):
        if not data:
            return None

        data = super(ShippingQuery, cls).de_json(data, bot)

        data['from_user'] = User.de_json(data.pop('from'), bot)
        data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)

        return cls(**data)
예제 #10
0
    def test_equality(self):
        a = OrderInfo(
            "name",
            "number",
            "mail",
            ShippingAddress("GB", "", "London", "12 Grimmauld Place", "",
                            "WC1"),
        )
        b = OrderInfo(
            "name",
            "number",
            "mail",
            ShippingAddress("GB", "", "London", "12 Grimmauld Place", "",
                            "WC1"),
        )
        c = OrderInfo(
            "name",
            "number",
            "mail",
            ShippingAddress("GB", "", "London", "13 Grimmauld Place", "",
                            "WC1"),
        )
        d = OrderInfo(
            "name",
            "number",
            "e-mail",
            ShippingAddress("GB", "", "London", "12 Grimmauld Place", "",
                            "WC1"),
        )
        e = ShippingAddress("GB", "", "London", "12 Grimmauld Place", "",
                            "WC1")

        assert a == b
        assert hash(a) == hash(b)

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

        assert a != d
        assert hash(a) != hash(d)

        assert a != e
        assert hash(a) != hash(e)
예제 #11
0
    def de_json(cls, data: Optional[JSONDict], bot: 'Bot') -> Optional['OrderInfo']:
        """See :meth:`telegram.TelegramObject.de_json`."""
        data = cls._parse_data(data)

        if not data:
            return cls()

        data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)

        return cls(**data)
예제 #12
0
    def de_json(cls, data, bot):
        if not data:
            return None

        data = super(ShippingQuery, cls).de_json(data, bot)

        data['from_user'] = User.de_json(data.pop('from'), bot)
        data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)

        return cls(**data)
예제 #13
0
class TestShippingQuery(object):
    id = 5
    invoice_payload = 'invoice_payload'
    from_user = User(0, '', False)
    shipping_address = ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '', 'WC1')

    def test_de_json(self, bot):
        json_dict = {
            'id': TestShippingQuery.id,
            'invoice_payload': TestShippingQuery.invoice_payload,
            'from': TestShippingQuery.from_user.to_dict(),
            'shipping_address': TestShippingQuery.shipping_address.to_dict()
        }
        shipping_query = ShippingQuery.de_json(json_dict, bot)

        assert shipping_query.id == self.id
        assert shipping_query.invoice_payload == self.invoice_payload
        assert shipping_query.from_user == self.from_user
        assert shipping_query.shipping_address == self.shipping_address

    def test_to_dict(self, shipping_query):
        shipping_query_dict = shipping_query.to_dict()

        assert isinstance(shipping_query_dict, dict)
        assert shipping_query_dict['id'] == shipping_query.id
        assert shipping_query_dict['invoice_payload'] == shipping_query.invoice_payload
        assert shipping_query_dict['from'] == shipping_query.from_user.to_dict()
        assert shipping_query_dict['shipping_address'] == shipping_query.shipping_address.to_dict()

    def test_answer(self, monkeypatch, shipping_query):
        def test(*args, **kwargs):
            return args[1] == shipping_query.id

        monkeypatch.setattr('telegram.Bot.answer_shipping_query', test)
        assert shipping_query.answer()

    def test_equality(self):
        a = ShippingQuery(self.id, self.from_user, self.invoice_payload, self.shipping_address)
        b = ShippingQuery(self.id, self.from_user, self.invoice_payload, self.shipping_address)
        c = ShippingQuery(self.id, None, '', None)
        d = ShippingQuery(0, self.from_user, self.invoice_payload, self.shipping_address)
        e = Update(self.id)

        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)

        assert a != e
        assert hash(a) != hash(e)
예제 #14
0
    def de_json(cls, data: Optional[JSONDict],
                bot: 'Bot') -> Optional['OrderInfo']:
        data = cls.parse_data(data)

        if not data:
            return cls()

        data['shipping_address'] = ShippingAddress.de_json(
            data.get('shipping_address'), bot)

        return cls(**data)
def shiping_query():
    return Update(
        1,
        shipping_query=ShippingQuery(
            42,
            User(1, "test user", False),
            "invoice_payload",
            ShippingAddress("EN", "my_state", "my_city", "steer_1", "",
                            "post_code"),
        ),
    )
예제 #16
0
    def de_json(cls, data: Optional[JSONDict],
                bot: 'Bot') -> Optional['ShippingQuery']:
        """See :meth:`telegram.TelegramObject.de_json`."""
        data = cls._parse_data(data)

        if not data:
            return None

        data['from_user'] = User.de_json(data.pop('from'), bot)
        data['shipping_address'] = ShippingAddress.de_json(
            data.get('shipping_address'), bot)

        return cls(bot=bot, **data)
예제 #17
0
    def de_json(data, bot):
        """
        Args:
            data (dict):
            bot (telegram.Bot):

        Returns:
            telegram.OrderInfo:
        """
        if not data:
            return OrderInfo()

        data = super(OrderInfo, OrderInfo).de_json(data, bot)

        data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)

        return OrderInfo(**data)
    def test_de_json(self, bot):
        json_dict = {
            "country_code": self.country_code,
            "state": self.state,
            "city": self.city,
            "street_line1": self.street_line1,
            "street_line2": self.street_line2,
            "post_code": self.post_code,
        }
        shipping_address = ShippingAddress.de_json(json_dict, bot)

        assert shipping_address.country_code == self.country_code
        assert shipping_address.state == self.state
        assert shipping_address.city == self.city
        assert shipping_address.street_line1 == self.street_line1
        assert shipping_address.street_line2 == self.street_line2
        assert shipping_address.post_code == self.post_code
예제 #19
0
    def test_de_json(self, bot):
        json_dict = {
            'country_code': self.country_code,
            'state': self.state,
            'city': self.city,
            'street_line1': self.street_line1,
            'street_line2': self.street_line2,
            'post_code': self.post_code
        }
        shipping_address = ShippingAddress.de_json(json_dict, bot)

        assert shipping_address.country_code == self.country_code
        assert shipping_address.state == self.state
        assert shipping_address.city == self.city
        assert shipping_address.street_line1 == self.street_line1
        assert shipping_address.street_line2 == self.street_line2
        assert shipping_address.post_code == self.post_code
예제 #20
0
    def de_json(data, bot):
        """
        Args:
            data (dict):
            bot (telegram.Bot):

        Returns:
            telegram.OrderInfo:
        """
        if not data:
            return OrderInfo()

        data = super(OrderInfo, OrderInfo).de_json(data, bot)

        data['shipping_address'] = ShippingAddress.de_json(
            data.get('shipping_address'), bot)

        return OrderInfo(**data)
예제 #21
0
    def de_json(data, bot):
        """
        Args:
            data (dict):
            bot (telegram.Bot):

        Returns:
            telegram.ShippingQuery:
        """
        if not data:
            return None

        data = super(ShippingQuery, ShippingQuery).de_json(data, bot)

        data['from_user'] = User.de_json(data.pop('from'), bot)
        data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)

        return ShippingQuery(**data)
예제 #22
0
class TestOrderInfo:
    name = 'name'
    phone_number = 'phone_number'
    email = 'email'
    shipping_address = ShippingAddress('GB', '', 'London',
                                       '12 Grimmauld Place', '', 'WC1')

    def test_de_json(self, bot):
        json_dict = {
            'name': TestOrderInfo.name,
            'phone_number': TestOrderInfo.phone_number,
            'email': TestOrderInfo.email,
            'shipping_address': TestOrderInfo.shipping_address.to_dict(),
        }
        order_info = OrderInfo.de_json(json_dict, bot)

        assert order_info.name == self.name
        assert order_info.phone_number == self.phone_number
        assert order_info.email == self.email
        assert order_info.shipping_address == self.shipping_address

    def test_to_dict(self, order_info):
        order_info_dict = order_info.to_dict()

        assert isinstance(order_info_dict, dict)
        assert order_info_dict['name'] == order_info.name
        assert order_info_dict['phone_number'] == order_info.phone_number
        assert order_info_dict['email'] == order_info.email
        assert order_info_dict[
            'shipping_address'] == order_info.shipping_address.to_dict()

    def test_equality(self):
        a = OrderInfo(
            'name',
            'number',
            'mail',
            ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1'),
        )
        b = OrderInfo(
            'name',
            'number',
            'mail',
            ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1'),
        )
        c = OrderInfo(
            'name',
            'number',
            'mail',
            ShippingAddress('GB', '', 'London', '13 Grimmauld Place', '',
                            'WC1'),
        )
        d = OrderInfo(
            'name',
            'number',
            'e-mail',
            ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1'),
        )
        e = ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1')

        assert a == b
        assert hash(a) == hash(b)

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

        assert a != d
        assert hash(a) != hash(d)

        assert a != e
        assert hash(a) != hash(e)
예제 #23
0
class TestShippingQuery:
    id_ = 5
    invoice_payload = 'invoice_payload'
    from_user = User(0, '', False)
    shipping_address = ShippingAddress('GB', '', 'London',
                                       '12 Grimmauld Place', '', 'WC1')

    def test_slot_behaviour(self, shipping_query, recwarn, mro_slots):
        inst = shipping_query
        for attr in inst.__slots__:
            assert getattr(inst, attr,
                           'err') != 'err', f"got extra slot '{attr}'"
        assert not inst.__dict__, f"got missing slot(s): {inst.__dict__}"
        assert len(mro_slots(inst)) == len(set(
            mro_slots(inst))), "duplicate slot"
        inst.custom, inst.id = 'should give warning', self.id_
        assert len(recwarn) == 1 and 'custom' in str(
            recwarn[0].message), recwarn.list

    def test_de_json(self, bot):
        json_dict = {
            'id': TestShippingQuery.id_,
            'invoice_payload': TestShippingQuery.invoice_payload,
            'from': TestShippingQuery.from_user.to_dict(),
            'shipping_address': TestShippingQuery.shipping_address.to_dict(),
        }
        shipping_query = ShippingQuery.de_json(json_dict, bot)

        assert shipping_query.id == self.id_
        assert shipping_query.invoice_payload == self.invoice_payload
        assert shipping_query.from_user == self.from_user
        assert shipping_query.shipping_address == self.shipping_address
        assert shipping_query.bot is bot

    def test_to_dict(self, shipping_query):
        shipping_query_dict = shipping_query.to_dict()

        assert isinstance(shipping_query_dict, dict)
        assert shipping_query_dict['id'] == shipping_query.id
        assert shipping_query_dict[
            'invoice_payload'] == shipping_query.invoice_payload
        assert shipping_query_dict['from'] == shipping_query.from_user.to_dict(
        )
        assert shipping_query_dict[
            'shipping_address'] == shipping_query.shipping_address.to_dict()

    def test_answer(self, monkeypatch, shipping_query):
        def make_assertion(*_, **kwargs):
            return kwargs['shipping_query_id'] == shipping_query.id

        assert check_shortcut_signature(ShippingQuery.answer,
                                        Bot.answer_shipping_query,
                                        ['shipping_query_id'], [])
        assert check_shortcut_call(shipping_query.answer, shipping_query.bot,
                                   'answer_shipping_query')
        assert check_defaults_handling(shipping_query.answer,
                                       shipping_query.bot)

        monkeypatch.setattr(shipping_query.bot, 'answer_shipping_query',
                            make_assertion)
        assert shipping_query.answer(ok=True)

    def test_equality(self):
        a = ShippingQuery(self.id_, self.from_user, self.invoice_payload,
                          self.shipping_address)
        b = ShippingQuery(self.id_, self.from_user, self.invoice_payload,
                          self.shipping_address)
        c = ShippingQuery(self.id_, None, '', None)
        d = ShippingQuery(0, self.from_user, self.invoice_payload,
                          self.shipping_address)
        e = Update(self.id_)

        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)

        assert a != e
        assert hash(a) != hash(e)
예제 #24
0
class TestOrderInfo:
    name = 'name'
    phone_number = 'phone_number'
    email = 'email'
    shipping_address = ShippingAddress('GB', '', 'London',
                                       '12 Grimmauld Place', '', 'WC1')

    def test_slot_behaviour(self, order_info, mro_slots, recwarn):
        for attr in order_info.__slots__:
            assert getattr(order_info, attr,
                           'err') != 'err', f"got extra slot '{attr}'"
        assert not order_info.__dict__, f"got missing slot(s): {order_info.__dict__}"
        assert len(mro_slots(order_info)) == len(set(
            mro_slots(order_info))), "duplicate slot"
        order_info.custom, order_info.name = 'should give warning', self.name
        assert len(recwarn) == 1 and 'custom' in str(
            recwarn[0].message), recwarn.list

    def test_de_json(self, bot):
        json_dict = {
            'name': TestOrderInfo.name,
            'phone_number': TestOrderInfo.phone_number,
            'email': TestOrderInfo.email,
            'shipping_address': TestOrderInfo.shipping_address.to_dict(),
        }
        order_info = OrderInfo.de_json(json_dict, bot)

        assert order_info.name == self.name
        assert order_info.phone_number == self.phone_number
        assert order_info.email == self.email
        assert order_info.shipping_address == self.shipping_address

    def test_to_dict(self, order_info):
        order_info_dict = order_info.to_dict()

        assert isinstance(order_info_dict, dict)
        assert order_info_dict['name'] == order_info.name
        assert order_info_dict['phone_number'] == order_info.phone_number
        assert order_info_dict['email'] == order_info.email
        assert order_info_dict[
            'shipping_address'] == order_info.shipping_address.to_dict()

    def test_equality(self):
        a = OrderInfo(
            'name',
            'number',
            'mail',
            ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1'),
        )
        b = OrderInfo(
            'name',
            'number',
            'mail',
            ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1'),
        )
        c = OrderInfo(
            'name',
            'number',
            'mail',
            ShippingAddress('GB', '', 'London', '13 Grimmauld Place', '',
                            'WC1'),
        )
        d = OrderInfo(
            'name',
            'number',
            'e-mail',
            ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1'),
        )
        e = ShippingAddress('GB', '', 'London', '12 Grimmauld Place', '',
                            'WC1')

        assert a == b
        assert hash(a) == hash(b)

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

        assert a != d
        assert hash(a) != hash(d)

        assert a != e
        assert hash(a) != hash(e)
예제 #25
0
class TestShippingQuery:
    id_ = 5
    invoice_payload = 'invoice_payload'
    from_user = User(0, '', False)
    shipping_address = ShippingAddress('GB', '', 'London',
                                       '12 Grimmauld Place', '', 'WC1')

    def test_de_json(self, bot):
        json_dict = {
            'id': TestShippingQuery.id_,
            'invoice_payload': TestShippingQuery.invoice_payload,
            'from': TestShippingQuery.from_user.to_dict(),
            'shipping_address': TestShippingQuery.shipping_address.to_dict(),
        }
        shipping_query = ShippingQuery.de_json(json_dict, bot)

        assert shipping_query.id == self.id_
        assert shipping_query.invoice_payload == self.invoice_payload
        assert shipping_query.from_user == self.from_user
        assert shipping_query.shipping_address == self.shipping_address
        assert shipping_query.bot is bot

    def test_to_dict(self, shipping_query):
        shipping_query_dict = shipping_query.to_dict()

        assert isinstance(shipping_query_dict, dict)
        assert shipping_query_dict['id'] == shipping_query.id
        assert shipping_query_dict[
            'invoice_payload'] == shipping_query.invoice_payload
        assert shipping_query_dict['from'] == shipping_query.from_user.to_dict(
        )
        assert shipping_query_dict[
            'shipping_address'] == shipping_query.shipping_address.to_dict()

    def test_answer(self, monkeypatch, shipping_query):
        answer_shipping_query = shipping_query.bot.answer_shipping_query

        def make_assertion(*_, **kwargs):
            return kwargs[
                'shipping_query_id'] == shipping_query.id and check_shortcut_call(
                    kwargs, answer_shipping_query)

        assert check_shortcut_signature(ShippingQuery.answer,
                                        Bot.answer_shipping_query,
                                        ['shipping_query_id'], [])

        monkeypatch.setattr(shipping_query.bot, 'answer_shipping_query',
                            make_assertion)
        assert shipping_query.answer(ok=True)

    def test_equality(self):
        a = ShippingQuery(self.id_, self.from_user, self.invoice_payload,
                          self.shipping_address)
        b = ShippingQuery(self.id_, self.from_user, self.invoice_payload,
                          self.shipping_address)
        c = ShippingQuery(self.id_, None, '', None)
        d = ShippingQuery(0, self.from_user, self.invoice_payload,
                          self.shipping_address)
        e = Update(self.id_)

        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)

        assert a != e
        assert hash(a) != hash(e)
예제 #26
0
class TestOrderInfo:
    name = "name"
    phone_number = "phone_number"
    email = "email"
    shipping_address = ShippingAddress("GB", "", "London",
                                       "12 Grimmauld Place", "", "WC1")

    def test_slot_behaviour(self, order_info, mro_slots):
        for attr in order_info.__slots__:
            assert getattr(order_info, attr,
                           "err") != "err", f"got extra slot '{attr}'"
        assert len(mro_slots(order_info)) == len(set(
            mro_slots(order_info))), "duplicate slot"

    def test_de_json(self, bot):
        json_dict = {
            "name": TestOrderInfo.name,
            "phone_number": TestOrderInfo.phone_number,
            "email": TestOrderInfo.email,
            "shipping_address": TestOrderInfo.shipping_address.to_dict(),
        }
        order_info = OrderInfo.de_json(json_dict, bot)

        assert order_info.name == self.name
        assert order_info.phone_number == self.phone_number
        assert order_info.email == self.email
        assert order_info.shipping_address == self.shipping_address

    def test_to_dict(self, order_info):
        order_info_dict = order_info.to_dict()

        assert isinstance(order_info_dict, dict)
        assert order_info_dict["name"] == order_info.name
        assert order_info_dict["phone_number"] == order_info.phone_number
        assert order_info_dict["email"] == order_info.email
        assert order_info_dict[
            "shipping_address"] == order_info.shipping_address.to_dict()

    def test_equality(self):
        a = OrderInfo(
            "name",
            "number",
            "mail",
            ShippingAddress("GB", "", "London", "12 Grimmauld Place", "",
                            "WC1"),
        )
        b = OrderInfo(
            "name",
            "number",
            "mail",
            ShippingAddress("GB", "", "London", "12 Grimmauld Place", "",
                            "WC1"),
        )
        c = OrderInfo(
            "name",
            "number",
            "mail",
            ShippingAddress("GB", "", "London", "13 Grimmauld Place", "",
                            "WC1"),
        )
        d = OrderInfo(
            "name",
            "number",
            "e-mail",
            ShippingAddress("GB", "", "London", "12 Grimmauld Place", "",
                            "WC1"),
        )
        e = ShippingAddress("GB", "", "London", "12 Grimmauld Place", "",
                            "WC1")

        assert a == b
        assert hash(a) == hash(b)

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

        assert a != d
        assert hash(a) != hash(d)

        assert a != e
        assert hash(a) != hash(e)
예제 #27
0
class TestShippingQuery:
    id_ = 5
    invoice_payload = "invoice_payload"
    from_user = User(0, "", False)
    shipping_address = ShippingAddress("GB", "", "London",
                                       "12 Grimmauld Place", "", "WC1")

    def test_slot_behaviour(self, shipping_query, mro_slots):
        inst = shipping_query
        for attr in inst.__slots__:
            assert getattr(inst, attr,
                           "err") != "err", f"got extra slot '{attr}'"
        assert len(mro_slots(inst)) == len(set(
            mro_slots(inst))), "duplicate slot"

    def test_de_json(self, bot):
        json_dict = {
            "id": TestShippingQuery.id_,
            "invoice_payload": TestShippingQuery.invoice_payload,
            "from": TestShippingQuery.from_user.to_dict(),
            "shipping_address": TestShippingQuery.shipping_address.to_dict(),
        }
        shipping_query = ShippingQuery.de_json(json_dict, bot)

        assert shipping_query.id == self.id_
        assert shipping_query.invoice_payload == self.invoice_payload
        assert shipping_query.from_user == self.from_user
        assert shipping_query.shipping_address == self.shipping_address
        assert shipping_query.get_bot() is bot

    def test_to_dict(self, shipping_query):
        shipping_query_dict = shipping_query.to_dict()

        assert isinstance(shipping_query_dict, dict)
        assert shipping_query_dict["id"] == shipping_query.id
        assert shipping_query_dict[
            "invoice_payload"] == shipping_query.invoice_payload
        assert shipping_query_dict["from"] == shipping_query.from_user.to_dict(
        )
        assert shipping_query_dict[
            "shipping_address"] == shipping_query.shipping_address.to_dict()

    async def test_answer(self, monkeypatch, shipping_query):
        async def make_assertion(*_, **kwargs):
            return kwargs["shipping_query_id"] == shipping_query.id

        assert check_shortcut_signature(ShippingQuery.answer,
                                        Bot.answer_shipping_query,
                                        ["shipping_query_id"], [])
        assert await check_shortcut_call(shipping_query.answer,
                                         shipping_query._bot,
                                         "answer_shipping_query")
        assert await check_defaults_handling(shipping_query.answer,
                                             shipping_query._bot)

        monkeypatch.setattr(shipping_query._bot, "answer_shipping_query",
                            make_assertion)
        assert await shipping_query.answer(ok=True)

    def test_equality(self):
        a = ShippingQuery(self.id_, self.from_user, self.invoice_payload,
                          self.shipping_address)
        b = ShippingQuery(self.id_, self.from_user, self.invoice_payload,
                          self.shipping_address)
        c = ShippingQuery(self.id_, None, "", None)
        d = ShippingQuery(0, self.from_user, self.invoice_payload,
                          self.shipping_address)
        e = Update(self.id_)

        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)

        assert a != e
        assert hash(a) != hash(e)