Пример #1
0
    def test_check_string(self):
        # type: () -> None
        x = "hello"  # type: Any
        self.assertEqual(check_string('x', x), None)

        x = 4
        self.assertEqual(check_string('x', x), 'x is not a string')
Пример #2
0
    def test_check_string(self):
        # type: () -> None
        x = "hello"  # type: Any
        self.assertEqual(check_string('x', x), None)

        x = 4
        self.assertEqual(check_string('x', x), 'x is not a string')
Пример #3
0
 def get_streams(self, user_profile: UserProfile) -> List[str]:
     """
     Helper function to get the stream names for a user
     """
     subs = get_stream_subscriptions_for_user(user_profile).filter(
         active=True,
     )
     return [check_string("recipient", get_display_recipient(sub.recipient)) for sub in subs]
Пример #4
0
    def test_storage_limit(self) -> None:
        storage = StateHandler(self.bot_profile)

        # Disable marshaling for storing a string whose size is
        # equivalent to the size of the stored object.
        storage.marshal = lambda obj: check_string("obj", obj)
        storage.demarshal = lambda obj: obj

        key = 'capacity-filling entry'
        storage.put(key, 'x' * (settings.USER_STATE_SIZE_LIMIT - len(key)))

        with self.assertRaisesMessage(StateError, "Request exceeds storage limit by 32 characters. "
                                                  "The limit is 100 characters."):
            storage.put('too much data', 'a few bits too long')

        second_storage = StateHandler(self.second_bot_profile)
        second_storage.put('another big entry', 'x' * (settings.USER_STATE_SIZE_LIMIT - 40))
        second_storage.put('normal entry', 'abcd')
Пример #5
0
    def test_check_string(self):
        x = "hello"
        self.assertEqual(check_string('x', x), None)

        x = 4
        self.assertEqual(check_string('x', x), 'x is not a string')
Пример #6
0
    def test_check_string(self):
        x = "hello"
        self.assertEqual(check_string('x', x), None)

        x = 4
        self.assertEqual(check_string('x', x), 'x is not a string')