# Path: yithlibraryserver/user/analytics.py
# class GoogleAnalytics(object):
# 
#     def __init__(self, request):
#         self.request = request
# 
#     @property
#     def enabled(self):
#         code = self.request.registry.settings['google_analytics_code']
#         return code is not None
# 
#     @property
#     def first_time(self):
#         if self.request.user is None:
#             return USER_ATTR not in self.request.session
#         else:
#             return USER_ATTR not in self.request.user
# 
#     def show_in_session(self):
#         return self.request.session.get(USER_ATTR, False)
# 
#     def show_in_user(self, user):
#         return user.get(USER_ATTR, False)
# 
#     def is_in_session(self):
#         return USER_ATTR in self.request.session
# 
#     def is_stored_in_user(self, user):
#         return USER_ATTR in user
# 
#     @property
#     def show(self):
#         user = self.request.user
#         if user is None:
#             return self.show_in_session()
#         else:
#             return self.show_in_user(user)
# 
#     def clean_session(self):
#         if USER_ATTR in self.request.session:
#             del self.request.session[USER_ATTR]
# 
#     def get_user_attr(self, value):
#         return {USER_ATTR: value}
# 
# Path: yithlibraryserver/user/analytics.py
# def get_google_analytics(request):
#     return GoogleAnalytics(request)
# 
# Path: yithlibraryserver/user/analytics.py
# USER_ATTR = 'allow_google_analytics'


import unittest
from pyramid.testing import DummyRequest
from yithlibraryserver.user.analytics import GoogleAnalytics
from yithlibraryserver.user.analytics import get_google_analytics
from yithlibraryserver.user.analytics import USER_ATTR
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.





class DummyRegistry(object):

    def __init__(self, **kwargs):
        self.settings = kwargs


class GoogleAnalyticsTests(unittest.TestCase):

    def test_enabled(self):
        request = DummyRequest()
        request.session = {}
        request.registry = DummyRegistry(google_analytics_code='1234')

# Path: yithlibraryserver/user/analytics.py
# class GoogleAnalytics(object):
# 
#     def __init__(self, request):
#         self.request = request
# 
#     @property
#     def enabled(self):
#         code = self.request.registry.settings['google_analytics_code']
#         return code is not None
# 
#     @property
#     def first_time(self):
#         if self.request.user is None:
#             return USER_ATTR not in self.request.session
#         else:
#             return USER_ATTR not in self.request.user
# 
#     def show_in_session(self):
#         return self.request.session.get(USER_ATTR, False)
# 
#     def show_in_user(self, user):
#         return user.get(USER_ATTR, False)
# 
#     def is_in_session(self):
#         return USER_ATTR in self.request.session
# 
#     def is_stored_in_user(self, user):
#         return USER_ATTR in user
# 
#     @property
#     def show(self):
#         user = self.request.user
#         if user is None:
#             return self.show_in_session()
#         else:
#             return self.show_in_user(user)
# 
#     def clean_session(self):
#         if USER_ATTR in self.request.session:
#             del self.request.session[USER_ATTR]
# 
#     def get_user_attr(self, value):
#         return {USER_ATTR: value}
# 
# Path: yithlibraryserver/user/analytics.py
# def get_google_analytics(request):
#     return GoogleAnalytics(request)
# 
# Path: yithlibraryserver/user/analytics.py
# USER_ATTR = 'allow_google_analytics'


# Path: yithlibraryserver/user/tests/test_analytics.py
import unittest
from pyramid.testing import DummyRequest
from yithlibraryserver.user.analytics import GoogleAnalytics
from yithlibraryserver.user.analytics import get_google_analytics
from yithlibraryserver.user.analytics import USER_ATTR

#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.





class DummyRegistry(object):

    def __init__(self, **kwargs):
        self.settings = kwargs


class GoogleAnalyticsTests(unittest.TestCase):

    def test_enabled(self):
        request = DummyRequest()
        request.session = {}
        request.registry = DummyRegistry(google_analytics_code='1234')

        ga = GoogleAnalytics(request)