예제 #1
0
    def test_get_fallback_only(self):
        request = self.get_request()
        storage = self.storage_class(request)
        cookie_storage = self.get_cookie_storage(storage)
        session_storage = self.get_session_storage(storage)

        # Set initial cookie and session data.
        example_messages = [str(i) for i in range(5)]
        set_cookie_data(cookie_storage, [CookieStorage.not_finished],
                        encode_empty=True)
        set_session_data(session_storage, example_messages)

        # Test that the message actually contains what we expect.
        self.assertEqual(list(storage), example_messages)
예제 #2
0
    def test_offline_message_with_session_messages(self):
        user = self.create_user()
        self.create_offline_message(user)
        # Grab the message before it is delted
        offline_message = OfflineMessage.objects.get()

        storage = OfflineStorageEngine(self.get_request(user))

        test_messages = ['one', 'two']
        session_tests.set_session_data(storage, test_messages)

        all_messages = list(storage)
        self.assertEqual(len(all_messages), 3)
        test_messages.insert(0, offline_message)
        self.assertEqual(all_messages, test_messages)
예제 #3
0
    def test_flush_used_backends(self):
        request = self.get_request()
        storage = self.storage_class(request)
        cookie_storage = self.get_cookie_storage(storage)
        session_storage = self.get_session_storage(storage)

        # Set initial cookie and session data.
        set_cookie_data(cookie_storage, ['cookie', CookieStorage.not_finished])
        set_session_data(session_storage, ['session'])

        # When updating, previously used but no longer needed backends are
        # flushed.
        response = self.get_response()
        list(storage)
        storage.update(response)
        session_storing = self.stored_session_messages_count(storage, response)
        self.assertEqual(session_storing, 0)