コード例 #1
0
 def test_invalid_calls(self) -> None:
     storage = StateHandler(self.bot_profile)
     storage.marshal = lambda obj: obj
     storage.demarshal = lambda obj: obj
     serializable_obj = {'foo': 'bar', 'baz': [42, 'cux']}
     with self.assertRaisesMessage(StateError, "Value type is <class 'dict'>, but should be str."):
         storage.put('some key', serializable_obj)  # type: ignore[arg-type] # We intend to test an invalid type.
     with self.assertRaisesMessage(StateError, "Key type is <class 'dict'>, but should be str."):
         storage.put(serializable_obj, 'some value')  # type: ignore[arg-type] # We intend to test an invalid type.
コード例 #2
0
 def test_invalid_calls(self) -> None:
     storage = StateHandler(self.bot_profile)
     storage.marshal = lambda obj: obj
     storage.demarshal = lambda obj: obj
     serializable_obj = {'foo': 'bar', 'baz': [42, 'cux']}
     with self.assertRaisesMessage(StateError, "Value type is <class 'dict'>, but should be str."):
         storage.put('some key', serializable_obj)  # type: ignore # We intend to test an invalid type.
     with self.assertRaisesMessage(StateError, "Key type is <class 'dict'>, but should be str."):
         storage.put(serializable_obj, 'some value')  # type: ignore # We intend to test an invalid type.
コード例 #3
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: 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')
コード例 #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: 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_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")