# Path: partify/config.py
# def set_config_value(field, value):
#     """Sets the configuration value specified in ``field`` to the value given in
#     ``value``. ``value`` should be able to be converted to a string, as it is
#     stored that way internally and transformed on the way out (see :func:load_config_from_db).
# 
#     :param field: The configuration field to change
#     :type field: string
#     :param value: The new value of ``field``
#     :type value: string
#     """
#     config_field = ConfigurationField.query.filter_by(field_name=field).first()
#     
#     if config_field is None:
#         config_field = ConfigurationField(field_name=field, field_value=value)
#         db.session.add(config_field)
#         db.session.commit()
#     else:
#         config_field.field_value = value
#         
#     db.session.commit()
# 
# Path: testing/partify_test_case.py
# class PartifyTestCase(TestCase):
#     @class_setup
#     def _prepare(self):
#         self.db_fd = tempfile.mkstemp() 
#         app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///%s" % self.db_fd[1]
#         init_db()
#         set_config_value("TESTING", True)
#         on_startup()
#         app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///%s" % self.db_fd[1]
#         app.config['TESTING'] = True
#         from partify.database import db
#         self.db = db
# 
#     @class_teardown
#     def _cleanup(self):
#         #os.close(self.db_fd[0])
#         #os.unlink(self.db_fd[1])
#         pass
# 
#     @setup
#     def _setup(self):
#         self.app = app.test_client()
#     
#     @teardown
#     def _teardown(self):
#         pass
# 
#     def create_test_user(self):
#         """Creates a test user with the same username as password."""
#         r = random.Random()
#         uid = r.randint(0,1000000)
#         user = User(name='test_user_%d' % uid,
#             username='%d' % uid,
#             password='%d' % uid)
#         db.session.add(user)
#         db.session.commit()
#         return user
# 
#     def assert_endpoint_works(self, endpoint):
#         response = self.app.get(endpoint, follow_redirects=True)
#         assert response.status_code == 200
#         return response
# 
#     def assert_endpoint_fails(self, endpoint):
#         response = self.app.get(endpoint, follow_redirects=False)
#         assert response.status_code != 200
#         return response


from testify import *
from partify.config import set_config_value
from testing.partify_test_case import PartifyTestCase
# Copyright 2011 Fred Hatfull
#
# This file is part of Partify.
#
# Partify is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Partify 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 General Public License
# along with Partify.  If not, see <http://www.gnu.org/licenses/>.



class LoggedInUserTestCase(PartifyTestCase):
    """A base test case for features that just need a logged in user."""

    @setup
    def _setup_logged_in_user(self):

# Path: partify/config.py
# def set_config_value(field, value):
#     """Sets the configuration value specified in ``field`` to the value given in
#     ``value``. ``value`` should be able to be converted to a string, as it is
#     stored that way internally and transformed on the way out (see :func:load_config_from_db).
# 
#     :param field: The configuration field to change
#     :type field: string
#     :param value: The new value of ``field``
#     :type value: string
#     """
#     config_field = ConfigurationField.query.filter_by(field_name=field).first()
#     
#     if config_field is None:
#         config_field = ConfigurationField(field_name=field, field_value=value)
#         db.session.add(config_field)
#         db.session.commit()
#     else:
#         config_field.field_value = value
#         
#     db.session.commit()
# 
# Path: testing/partify_test_case.py
# class PartifyTestCase(TestCase):
#     @class_setup
#     def _prepare(self):
#         self.db_fd = tempfile.mkstemp() 
#         app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///%s" % self.db_fd[1]
#         init_db()
#         set_config_value("TESTING", True)
#         on_startup()
#         app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///%s" % self.db_fd[1]
#         app.config['TESTING'] = True
#         from partify.database import db
#         self.db = db
# 
#     @class_teardown
#     def _cleanup(self):
#         #os.close(self.db_fd[0])
#         #os.unlink(self.db_fd[1])
#         pass
# 
#     @setup
#     def _setup(self):
#         self.app = app.test_client()
#     
#     @teardown
#     def _teardown(self):
#         pass
# 
#     def create_test_user(self):
#         """Creates a test user with the same username as password."""
#         r = random.Random()
#         uid = r.randint(0,1000000)
#         user = User(name='test_user_%d' % uid,
#             username='%d' % uid,
#             password='%d' % uid)
#         db.session.add(user)
#         db.session.commit()
#         return user
# 
#     def assert_endpoint_works(self, endpoint):
#         response = self.app.get(endpoint, follow_redirects=True)
#         assert response.status_code == 200
#         return response
# 
#     def assert_endpoint_fails(self, endpoint):
#         response = self.app.get(endpoint, follow_redirects=False)
#         assert response.status_code != 200
#         return response


# Path: testing/logged_in_user_test_case.py
from testify import *
from partify.config import set_config_value
from testing.partify_test_case import PartifyTestCase

# Copyright 2011 Fred Hatfull
#
# This file is part of Partify.
#
# Partify is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Partify 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 General Public License
# along with Partify.  If not, see <http://www.gnu.org/licenses/>.



class LoggedInUserTestCase(PartifyTestCase):
    """A base test case for features that just need a logged in user."""

    @setup
    def _setup_logged_in_user(self):

        set_config_value("TESTING", True)