# Path: tests/base.py
# class TestCase(_TestCase):
#     db = db
# 
#     def create_app(self):
#         app.config.from_object('tests.settings_test')
#         app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
#         return app
# 
#     def setUp(self):
#         db.create_all()
#         self.user = create_admin()
# 
#     def tearDown(self):
#         db.session.remove()
#         db.drop_all()
# 
#     def login(self, email=None, password=None):
#         data = dict(
#             email=email or self.app.config['ADMIN_USER']['email'],
#             password=password or self.app.config['ADMIN_USER']['password'],
#             remember=True,
#         )
#         return self.client.post('/user/sign-in', data=data,
#                                 follow_redirects=True)
# 
#     def logout(self):
#         return self.client.get('/user/sign-out', follow_redirects=True)
# 
#     def assertRedirectToLogin(self, response, next_url):
#         expected = '/user/sign-in?next=http%3A//localhost{0}'.format(next_url)
#         self.assertRedirects(response, expected)
# 
# Path: app/accounts/models.py
# class Project(db.Model, models.BaseModelMixin, models.CreateAndModifyMixin):
#     __tablename__ = 'projects'
# 
#     title = db.Column(db.Unicode(255), nullable=False)
# 
#     intercom_app_id = db.Column(db.Unicode(255), nullable=False, unique=True)
#     intercom_api_key = db.Column(db.Unicode(255), nullable=False)
#     intercom_webhooks_internal_secret = db.Column(db.Unicode(255))
#     intercom_subscription_id = db.Column(db.Unicode(255))
# 
#     aws_access_id = db.Column(db.Unicode(255), nullable=False)
#     aws_secret_access_key = db.Column(db.Unicode(255), nullable=False)
# 
#     user_id = db.Column(db.Integer(), db.ForeignKey('users.id'),
#                         nullable=False)
#     user = db.relationship('User', back_populates='projects')
# 
#     intercom_users = db.relationship('IntercomUser',
#                                      back_populates='project')
# 
#     def __unicode__(self):
#         return self.title
# 
#     @classmethod
#     def get_for_current_user_or_404(cls, pk):
#         return cls.get_or_404(cls.user_id == current_user.id, cls.id == pk)
# 
#     def get_intercom_client(project):
#         from app.intercom.service import IntercomClient
#         return IntercomClient(project.intercom_app_id,
#                               project.intercom_api_key)
# 
#     def start_awis_session(project):
#         """ Initiate contextmanager for working with AWIS.
#         """
#         return AWISContextManager(project.aws_access_id,
#                                   project.aws_secret_access_key)
# 
#     def delete(self):
#         client = self.get_intercom_client()
#         client.unsubscribe(self.intercom_subscription_id)
#         return super(Project, self).delete()
# 
# class User(db.Model, UserMixin, models.BaseModelMixin):
#     __tablename__ = 'users'
# 
#     email = db.Column(db.Unicode(255), nullable=False, unique=True)
#     password = db.Column(db.String(255), nullable=False)
# 
#     confirmed_at = db.Column(db.DateTime())
#     reset_password_token = db.Column(db.String(100), nullable=False,
#                                      default='')
# 
#     is_enabled = db.Column(db.Boolean(), nullable=False, default=False)
#     is_admin = db.Column(db.Boolean(), nullable=False, default=False)
# 
#     projects = db.relationship('Project', back_populates='user')
# 
#     def __unicode__(self):
#         return self.email
# 
#     def is_active(self):
#         # HACK for Flask-Login :/
#         return self.is_enabled


from datetime import datetime
from flask import url_for
from tests.base import TestCase
from app.accounts.models import Project, User
import mock
        self.assertTrue(subscribe.called)

    def test_invalid_data_not_added(self):
        self.login()
        response = self.client.post(self.add_url)

        self.assert200(response)

        form = self.get_context_variable('form')
        self.assertTrue(form.errors)


class ProjectUpdateTestCase(TestCase):
    def setUp(self):
        super(ProjectUpdateTestCase, self).setUp()
        self.project = Project(
            title='title',
            intercom_app_id='intercom_app_id',
            intercom_api_key='intercom_api_key',
            aws_access_id='aws_access_id',
            aws_secret_access_key='aws_secret_access_key',
            user_id=self.user.id)
        self.project.save()
        self.url = url_for('accounts.project_update', pk=self.project.id)

    def test_page_not_allowed_for_anon(self):
        response = self.client.get(self.url)
        self.assertRedirectToLogin(response, self.url)

    def test_only_owner_can_see_project(self):

# Path: tests/base.py
# class TestCase(_TestCase):
#     db = db
# 
#     def create_app(self):
#         app.config.from_object('tests.settings_test')
#         app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
#         return app
# 
#     def setUp(self):
#         db.create_all()
#         self.user = create_admin()
# 
#     def tearDown(self):
#         db.session.remove()
#         db.drop_all()
# 
#     def login(self, email=None, password=None):
#         data = dict(
#             email=email or self.app.config['ADMIN_USER']['email'],
#             password=password or self.app.config['ADMIN_USER']['password'],
#             remember=True,
#         )
#         return self.client.post('/user/sign-in', data=data,
#                                 follow_redirects=True)
# 
#     def logout(self):
#         return self.client.get('/user/sign-out', follow_redirects=True)
# 
#     def assertRedirectToLogin(self, response, next_url):
#         expected = '/user/sign-in?next=http%3A//localhost{0}'.format(next_url)
#         self.assertRedirects(response, expected)
# 
# Path: app/accounts/models.py
# class Project(db.Model, models.BaseModelMixin, models.CreateAndModifyMixin):
#     __tablename__ = 'projects'
# 
#     title = db.Column(db.Unicode(255), nullable=False)
# 
#     intercom_app_id = db.Column(db.Unicode(255), nullable=False, unique=True)
#     intercom_api_key = db.Column(db.Unicode(255), nullable=False)
#     intercom_webhooks_internal_secret = db.Column(db.Unicode(255))
#     intercom_subscription_id = db.Column(db.Unicode(255))
# 
#     aws_access_id = db.Column(db.Unicode(255), nullable=False)
#     aws_secret_access_key = db.Column(db.Unicode(255), nullable=False)
# 
#     user_id = db.Column(db.Integer(), db.ForeignKey('users.id'),
#                         nullable=False)
#     user = db.relationship('User', back_populates='projects')
# 
#     intercom_users = db.relationship('IntercomUser',
#                                      back_populates='project')
# 
#     def __unicode__(self):
#         return self.title
# 
#     @classmethod
#     def get_for_current_user_or_404(cls, pk):
#         return cls.get_or_404(cls.user_id == current_user.id, cls.id == pk)
# 
#     def get_intercom_client(project):
#         from app.intercom.service import IntercomClient
#         return IntercomClient(project.intercom_app_id,
#                               project.intercom_api_key)
# 
#     def start_awis_session(project):
#         """ Initiate contextmanager for working with AWIS.
#         """
#         return AWISContextManager(project.aws_access_id,
#                                   project.aws_secret_access_key)
# 
#     def delete(self):
#         client = self.get_intercom_client()
#         client.unsubscribe(self.intercom_subscription_id)
#         return super(Project, self).delete()
# 
# class User(db.Model, UserMixin, models.BaseModelMixin):
#     __tablename__ = 'users'
# 
#     email = db.Column(db.Unicode(255), nullable=False, unique=True)
#     password = db.Column(db.String(255), nullable=False)
# 
#     confirmed_at = db.Column(db.DateTime())
#     reset_password_token = db.Column(db.String(100), nullable=False,
#                                      default='')
# 
#     is_enabled = db.Column(db.Boolean(), nullable=False, default=False)
#     is_admin = db.Column(db.Boolean(), nullable=False, default=False)
# 
#     projects = db.relationship('Project', back_populates='user')
# 
#     def __unicode__(self):
#         return self.email
# 
#     def is_active(self):
#         # HACK for Flask-Login :/
#         return self.is_enabled


# Path: tests/test_projects.py
from datetime import datetime
from flask import url_for
from tests.base import TestCase
from app.accounts.models import Project, User
import mock

        self.assertTrue(subscribe.called)

    def test_invalid_data_not_added(self):
        self.login()
        response = self.client.post(self.add_url)

        self.assert200(response)

        form = self.get_context_variable('form')
        self.assertTrue(form.errors)


class ProjectUpdateTestCase(TestCase):
    def setUp(self):
        super(ProjectUpdateTestCase, self).setUp()
        self.project = Project(
            title='title',
            intercom_app_id='intercom_app_id',
            intercom_api_key='intercom_api_key',
            aws_access_id='aws_access_id',
            aws_secret_access_key='aws_secret_access_key',
            user_id=self.user.id)
        self.project.save()
        self.url = url_for('accounts.project_update', pk=self.project.id)

    def test_page_not_allowed_for_anon(self):
        response = self.client.get(self.url)
        self.assertRedirectToLogin(response, self.url)

    def test_only_owner_can_see_project(self):

        other_user = User(