Exemple #1
0
    def test_get_initial_request_attributes(self):
        session = Session()
        request_envelope = RequestEnvelope(
            version=None, session=session, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope)

        assert attributes_manager.request_attributes == {}, (
            "AttributesManager fails to set the initial request attributes "
            "to be {}")
Exemple #2
0
    def test_set_request_attributes(self):
        session = Session()
        request_envelope = RequestEnvelope(
            version=None, session=session, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope)
        attributes_manager.request_attributes = {"key": "value"}

        assert attributes_manager.request_attributes == {"key": "value"}, (
            "AttributesManager fails to set the request attributes")
Exemple #3
0
    def test_get_persistent_attributes(self):
        session = Session()
        request_envelope = RequestEnvelope(
            version=None, session=session, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope,
            persistence_adapter=MockPersistenceAdapter())

        assert attributes_manager.persistent_attributes == {
            "key_1": "v1", "key_2": "v2"}, (
            "AttributesManager fails to get persistent attributes from "
            "persistent adapter")
Exemple #4
0
    def test_get_default_session_attributes_from_new_session_request_envelope(self):
        session = Session(
            new=True, session_id=None, user=None,
            attributes=None, application=None)
        request_envelope = RequestEnvelope(
            version=None, session=session, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope)

        assert attributes_manager.session_attributes == {}, (
            "AttributesManager fails to get default session attributes from "
            "new session request envelope")
Exemple #5
0
    def test_get_session_attributes_from_out_of_session_request_envelope(self):
        request_envelope = RequestEnvelope(
            version=None, session=None, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope)

        attributes_manager._request_envelope.session = None
        with self.assertRaises(AttributesManagerException) as exc:
            test_session_attributes = attributes_manager.session_attributes

        assert "Cannot get SessionAttributes from out of session request!" in str(exc.exception), (
            "AttributesManager should raise error when trying to get session "
            "attributes from out of session envelope")
Exemple #6
0
    def test_get_session_attributes_from_in_session_request_envelope(self):
        session = Session(
            new=None, session_id=None, user=None,
            attributes={"mockKey": "mockValue"}, application=None)
        request_envelope = RequestEnvelope(
            version=None, session=session, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope)

        assert attributes_manager.session_attributes == {
            "mockKey": "mockValue"}, (
            "AttributesManager fails to get session attributes from in "
            "session request envelope")
Exemple #7
0
    def test_set_persistent_attributes_without_persistence_adapter(self):
        session = Session()
        request_envelope = RequestEnvelope(
            version=None, session=session, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope)

        with self.assertRaises(AttributesManagerException) as exc:
            attributes_manager.persistent_attributes = {"key": "value"}

        assert "Cannot set PersistentAttributes without persistence adapter!" in str(exc.exception), (
            "AttributesManager should raise error when trying to set "
            "persistent attributes without persistence adapter")
Exemple #8
0
    def test_set_persistent_attributes(self):
        session = Session()
        request_envelope = RequestEnvelope(
            version=None, session=session, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope,
            persistence_adapter=MockPersistenceAdapter())

        attributes_manager.persistent_attributes = {"key": "value"}

        assert attributes_manager.persistent_attributes == {
            "key": "value"}, (
            "AttributesManager fails to set the persistent attributes")
Exemple #9
0
    def test_set_session_attributes_to_out_of_session_request_envelope(self):
        request_envelope = RequestEnvelope(
            version=None, session=None, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope)

        attributes_manager._request_envelope.session = None
        with self.assertRaises(AttributesManagerException) as exc:
            attributes_manager.session_attributes = {"key": "value"}

        assert "Cannot set SessionAttributes to out of session request!" in str(exc.exception), (
            "AttributesManager should raise error when trying to set session "
            "attributes to out of session request")
Exemple #10
0
    def test_delete_persistent_attributes(self):
        session = Session()
        request_envelope = RequestEnvelope(
            version=None, session=session, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope,
            persistence_adapter=MockPersistenceAdapter())

        attributes_manager.persistent_attributes = {"key": "value"}
        attributes_manager.delete_persistent_attributes()

        assert attributes_manager._persistence_adapter.attributes == {}, (
            "AttributesManager fails to delete persistent attributes via "
            "persistence adapter")
Exemple #11
0
    def test_save_persistent_attributes_without_changing_persistent_attributes(self):
        session = Session()
        request_envelope = RequestEnvelope(
            version=None, session=session, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope,
            persistence_adapter=MockPersistenceAdapter())

        attributes_manager.save_persistent_attributes()

        assert attributes_manager._persistence_adapter.attributes == {
            "key_1": "v1", "key_2": "v2"}, (
            "AttributesManager should do nothing if persistent attributes "
            "has not been changed")
Exemple #12
0
    def test_set_session_attributes(self):
        session = Session(
            new=None, session_id=None, user=None,
            attributes={"mockKey": "mockValue"}, application=None)
        request_envelope = RequestEnvelope(
            version=None, session=session, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope)

        attributes_manager.session_attributes = {
            "mockKey": "updatedMockValue"}

        assert attributes_manager.session_attributes == {
            "mockKey": "updatedMockValue"}, (
            "AttributesManager fails to set the session attributes")
    def test_save_persistent_attributes_without_persistence_adapter(self):
        request_envelope = RequestEnvelope(version=None,
                                           session=None,
                                           context=None,
                                           request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope)

        with self.assertRaises(AttributesManagerException) as exc:
            attributes_manager.save_persistent_attributes()

        assert "Cannot save PersistentAttributes without persistence adapter!" in str(
            exc.exception), (
                "AttributesManager should raise error when trying to save "
                "persistent attributes without persistence adapter")
Exemple #14
0
    def test_get_persistent_attributes_with_calling_get_persistent_attributes_multiple_times(self):
        session = Session()
        request_envelope = RequestEnvelope(
            version=None, session=session, context=None, request=None)
        attributes_manager = AttributesManager(
            request_envelope=request_envelope,
            persistence_adapter=MockPersistenceAdapter())

        attributes_manager.persistent_attributes
        attributes_manager.persistent_attributes
        attributes_manager.persistent_attributes
        attributes_manager.persistent_attributes

        assert attributes_manager._persistence_adapter.get_count == 1, (
            "AttributesManager should make only 1 get_attributes call "
            "during multiple get_persistent_attributes calls")