コード例 #1
0
def venue():
    return Venue(
        TestVenue.location,
        TestVenue.title,
        TestVenue.address,
        foursquare_id=TestVenue.foursquare_id,
        foursquare_type=TestVenue.foursquare_type,
    )
コード例 #2
0
    def test_equality(self):
        a = Venue(Location(0, 0), self.title, self.address)
        b = Venue(Location(0, 0), self.title, self.address)
        c = Venue(Location(0, 0), self.title, '')
        d = Venue(Location(0, 1), self.title, self.address)
        d2 = Venue(Location(0, 0), '', self.address)

        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 != d2
        assert hash(a) != hash(d2)
コード例 #3
0
    def test_venue(self):
        ven = Venue(Location(1.0, 1.0), "some place", "somewhere")
        u = self.mg.get_message(venue=ven)
        self.assertEqual(u.message.venue.title, ven.title)

        u = self.mg.get_message(venue=True)
        self.assertIsInstance(u.message.venue, Venue)

        with self.assertRaisesRegexp(BadMessageException, r"telegram\.Venue"):
            self.mg.get_message(venue="Venue")
コード例 #4
0
 },
 {
     'video_note': VideoNote('video_note_id', 'unique_id', 20, 12)
 },
 {
     'new_chat_members': [User(55, 'new_user', False)]
 },
 {
     'contact': Contact('phone_numner', 'contact_name')
 },
 {
     'location': Location(-23.691288, 46.788279)
 },
 {
     'venue':
     Venue(Location(-23.691288, 46.788279), 'some place', 'right here')
 },
 {
     'left_chat_member': User(33, 'kicked', False)
 },
 {
     'new_chat_title': 'new title'
 },
 {
     'new_chat_photo': [PhotoSize('photo_id', 'unique_id', 50, 50)]
 },
 {
     'delete_chat_photo': True
 },
 {
     'group_chat_created': True
コード例 #5
0
 def _get_venue(self):
     loc = self._get_location()
     address = "somewherestreet 23"
     name = "Awesome place"
     return Venue(loc, name, address)
コード例 #6
0
 def _handle_attachments(
         self,
         audio,
         contact,
         document,
         location,
         photo,
         sticker,
         user,
         venue,
         video,
         voice,
         caption,
 ):
     attachments = [
         x
         for x in [
             photo,
             venue,
             location,
             contact,
             voice,
             video,
             sticker,
             document,
             audio,
         ]
         if x
     ]
     if caption and not attachments:
         raise BadMessageException("Can't have a caption without attachment")
     if len(attachments) > 1:
         raise BadMessageException("can't add more than one attachment")
     if photo:
         if isinstance(photo, list):
             if all([isinstance(x, PhotoSize) for x in photo]):
                 pass
             else:
                 raise BadMessageException(
                     "photo must either be True or list(telegram.PhotoSize)"
                 )
         elif isinstance(photo, bool):
             photo = self._get_photosize()
         else:
             raise BadMessageException(
                 "photo must either be True or list(telegram.PhotoSize)"
             )
     if location:
         if isinstance(location, Location):
             pass
         elif isinstance(location, dict):
             location = Location(**location)
         elif isinstance(location, bool):
             location = self._get_location()
         else:
             raise BadMessageException(
                 "location must either be True or telegram.Location"
             )
     if venue:
         if isinstance(venue, Venue):
             pass
         elif isinstance(venue, bool):
             venue = self._get_venue()
         elif isinstance(venue, dict):
             venue["location"] = Location(**venue)
             venue = Venue(**venue)
         else:
             raise BadMessageException("venue must either be True or telegram.Venue")
     if contact:
         if isinstance(contact, Contact):
             pass
         elif isinstance(contact, dict):
             contact = Contact(**contact)
         elif isinstance(contact, bool):
             contact = self._get_contact(user)
         else:
             raise BadMessageException(
                 "contact must either be True or telegram.Contact"
             )
     if voice:
         if isinstance(voice, Voice):
             pass
         elif isinstance(voice, bool):
             voice = self._get_voice()
         elif isinstance(voice, dict):
             voice = Voice(**voice)
         else:
             raise BadMessageException("voice must either be True or telegram.Voice")
     if video:
         if isinstance(video, Video):
             pass
         elif isinstance(video, bool):
             video = self._get_video()
         elif isinstance(video, dict):
             video = self._get_video(data=video)
         else:
             raise BadMessageException("video must either be True or telegram.Video")
     if sticker:
         if isinstance(sticker, Sticker):
             pass
         elif isinstance(sticker, bool):
             sticker = self._get_sticker()
         elif isinstance(sticker, dict):
             sticker = self._get_sticker(sticker)
         else:
             raise BadMessageException(
                 "sticker must either be True or telegram.Sticker"
             )
     if document:
         if isinstance(document, Document):
             pass
         elif isinstance(document, dict):
             document = Document(**document)
         elif isinstance(document, bool):
             document = self._get_document()
         else:
             raise BadMessageException(
                 "document must either be True or telegram.Document"
             )
     if audio:
         if isinstance(audio, Audio):
             pass
         elif isinstance(audio, bool):
             audio = self._get_audio()
         elif isinstance(audio, dict):
             audio = Audio(**audio)
         else:
             raise BadMessageException("audio must either be True or telegram.Audio")
     return audio, contact, document, location, photo, sticker, venue, video, voice