def setUpClass(cls):
        """Set up the WebEditor Test Class.

        Create a webpost and a testuser
        """
        cls.repo = KnowledgeRepository.for_uri('sqlite:///:memory::test_posts',
                                               auto_create=True)
        cls.repo.config.editors = ['test_knowledge_editor']
        cls.app = cls.repo.get_app(config='tests/config_server.py')
        cls.app.config['AUTH_USER_IDENTIFIER_REQUEST_HEADER'] = 'user_header'
        cls.app.config['DEBUG'] = True
        cls.client = cls.app.test_client()

        cls.post_path = 'webeditor/misc/test_webeditor_functionality.kp'
        kp = KnowledgePost(cls.post_path)

        headers = {
            'title': 'Test Webeditor Functionality',
            'authors': ['webeditor_test_user'],
            'tldr': 'This is the test tldr for the webpost.',
            'created_at': datetime.date.today(),
            'updated_at': datetime.date.today()
        }
        kp.write(md='Test Text', headers=headers)
        cls.repo.add(kp)

        # manual re-index
        with cls.app.app_context():
            post = Post()
            db_session.add(post)
            post.update_metadata_from_kp(kp)
            db_session.commit()
            cls.post_id = post.id
Exemplo n.º 2
0
    def setUpClass(self):

        self.repo = KnowledgeRepository.for_uri('tests/test_repo',
                                                auto_create=True)
        self.app = self.repo.get_app(config='tests/config_server.py')
        self.app.repository.config.editors = ['knowledge_editors']
        self.client = self.app.test_client()

        self.knowledge_username = '******'
        self.post_path = 'tests/test_email_functionality'
        kp = KnowledgePost(self.post_path)

        headers = {
            'title': 'Test Email Functionality',
            'authors': [self.knowledge_username],
            'tags': ['test_tag'],
            'tldr': 'This is the test tldr for the post',
            'created_at': datetime.date.today(),
            'updated_at': datetime.date.today()
        }
        kp.write(md='Test Text', headers=headers)
        self.repo.add(kp, message='test commit message')

        # manual re-index
        with self.app.app_context():
            post = Post()
            db_session.add(post)
            post.update_metadata_from_kp(kp)
            db_session.commit()
            self.post_id = post.id
Exemplo n.º 3
0
    def setUpClass(self):

        self.repo = KnowledgeRepository.for_uri('tests/test_repo',
                                                auto_create=True)
        self.app = self.repo.get_app(config='tests/config_server.py')
        self.app.repository.config.editors = ['knowledge_editors']
        self.client = self.app.test_client()

        self.knowledge_username = '******'
        self.post_path = 'tests/test_email_functionality'
        self.thumbnail = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXR' \
                         'STlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII='  # Red pixel
        kp = KnowledgePost(self.post_path)

        headers = {
            'title': 'Test Email Functionality',
            'authors': [self.knowledge_username],
            'tags': ['test_tag'],
            'tldr': 'This is the test tldr for the post',
            'thumbnail': 'data:image/png;base64,{}'.format(self.thumbnail),
            'created_at': datetime.date.today(),
            'updated_at': datetime.date.today()
        }
        kp.write(md='Test Text', headers=headers)

        # manual re-index
        with self.app.app_context():
            self.repo.add(kp, message='test commit message')

            post = Post()
            db_session.add(post)
            post.update_metadata_from_kp(kp)
            db_session.commit()

            self.post_id = post.id
Exemplo n.º 4
0
    def setUpClass(self):

        self.repo = KnowledgeRepository.for_uri('tests/test_repo', auto_create=True)
        self.app = self.repo.get_app(config='tests/config_server.py')
        self.app.repository.config.editors = ['knowledge_editors']
        self.client = self.app.test_client()

        self.knowledge_username = '******'
        self.post_path = 'tests/test_email_functionality'
        kp = KnowledgePost(self.post_path)

        headers = {'title': 'Test Email Functionality',
                   'authors': [self.knowledge_username],
                   'tags': ['test_tag'],
                   'tldr': 'This is the test tldr for the post',
                   'created_at': datetime.date.today(),
                   'updated_at': datetime.date.today()}
        kp.write(md='Test Text', headers=headers)

        # manual re-index
        with self.app.app_context():
            self.repo.add(kp, message='test commit message')

            post = Post()
            db_session.add(post)
            post.update_metadata_from_kp(kp)
            db_session.commit()

            self.post_id = post.id
Exemplo n.º 5
0
    def test04_subscription_email(self):
        """ Test Subscription Email """
        # Subscribe to a tag from gitpost and webpost Note, don't send
        # a request to do it so that create_index() will happen later,
        # as it is before_first_request

        with self.app.app_context():
            db_session.expire_on_commit = False
            post = db_session.query(Post).get(self.post_id)

            user = User(username=self.knowledge_username)
            if user.id is None:
                db_session.commit()
            user_id = user.id

            # grab the first tag from the post
            tag_id = post.tags[0].id
            post_id = post.id

            subscription = Subscription(user_id=user_id,
                                        object_type='tag',
                                        object_id=tag_id)
            db_session.add(subscription)
            db_session.commit()

            # Run a request, which should trigger a subscription email for
            # tag_to_subscribe
            with self.app.config['mail'].record_messages() as outbox:
                with self.app.app_context():
                    send_subscription_emails(post)

            emails_sent = (db_session.query(Email).filter(
                and_(Email.object_id == post_id, Email.user_id == user_id,
                     Email.trigger_id == tag_id,
                     Email.trigger_type == 'subscription')).all())

            # There should be exactly 1 email sent to the user for the target post
            # Check EmailSent records
            assert len(
                outbox) == 1, 'One subscription email should be actually sent'
            assert len(emails_sent
                       ) == 1, 'One subscription email should recorded as sent'
            # Check outbox of messages
            assert len(
                outbox[0].bcc
            ) == 1, 'One subscription email should be actually sent to one user'
            assert "A knowledge post was just posted under tag" in outbox[
                0].body, 'Email should be the subscription email'

            username_to_email = self.app.repository.config.username_to_email
            assert outbox[0].bcc[0] == username_to_email(
                self.knowledge_username)
Exemplo n.º 6
0
    def test04_subscription_email(self):
        """ Test Subscription Email """
        # Subscribe to a tag from gitpost and webpost Note, don't send
        # a request to do it so that create_index() will happen later,
        # as it is before_first_request

        with self.app.app_context():
            db_session.expire_on_commit = False
            post = db_session.query(Post).get(self.post_id)

            user = User(identifier=self.knowledge_username)
            if user.id is None:
                db_session.commit()
            user_id = user.id

            # grab the first tag from the post
            tag_id = post.tags[0].id
            post_id = post.id

            subscription = Subscription(user_id=user_id, object_type='tag',
                                        object_id=tag_id)
            db_session.add(subscription)
            db_session.commit()

            # Run a request, which should trigger a subscription email for
            # tag_to_subscribe
            with self.app.config['mail'].record_messages() as outbox:
                with self.app.app_context():
                    send_subscription_emails(post)

            emails_sent = (db_session.query(Email)
                                     .filter(and_(Email.object_id == post_id,
                                                  Email.user_id == user_id,
                                                  Email.trigger_id == tag_id,
                                                  Email.trigger_type == 'subscription'))
                                     .all())

            # There should be exactly 1 email sent to the user for the target post
            # Check EmailSent records
            assert len(outbox) == 1, 'One subscription email should be actually sent'
            assert len(emails_sent) == 1, 'One subscription email should recorded as sent'
            # Check outbox of messages
            assert len(outbox[0].bcc) == 1, 'One subscription email should be actually sent to one user'
            assert "A knowledge post was just posted under tag" in outbox[0].body, 'Email should be the subscription email'

            username_to_email = self.app.repository.config.username_to_email
            assert outbox[0].bcc[0] == username_to_email(self.knowledge_username)
Exemplo n.º 7
0
    def setUpClass(self):
        self.repo = KnowledgeRepository.for_uri('tests/test_repo',
                                                auto_create=True)
        self.app = self.repo.get_app(config='tests/config_server.py')
        self.app.repository.config.editors = ['knowledge_editors']
        self.client = self.app.test_client()

        self.knowledge_username = '******'
        # this creates a user
        with self.app.app_context():
            User(username=self.knowledge_username)

            web_post = Post(title='test_webpost')
            git_post = (db_session.query(Post).first())

            db_session.add(web_post)
            web_post.authors = ['test_author']

            git_post.tags = ['test_tag']

            db_session.commit()

            self.web_post_id = web_post.id
            self.git_post_id = git_post.id
Exemplo n.º 8
0
    def test04_subscription_email(self):
        """ Test Subscription Email """
        # Subscribe to a tag from gitpost and webpost Note, don't send
        # a request to do it so that create_index() will happen later,
        # as it is before_first_request

        with self.app.app_context():
            db_session.expire_on_commit = False
            post = db_session.query(Post).get(self.post_id)

            user = User(identifier=self.knowledge_username)
            if user.id is None:
                db_session.commit()
            user_id = user.id

            # grab the first tag from the post
            tag_id = post.tags[0].id
            post_id = post.id

            subscription = Subscription(user_id=user_id,
                                        object_type='tag',
                                        object_id=tag_id)
            db_session.add(subscription)
            db_session.commit()

            # Run a request, which should trigger a subscription email for
            # tag_to_subscribe
            with self.app.config['mail'].record_messages() as outbox:
                with self.app.app_context():
                    send_subscription_emails(post)

            emails_sent = (db_session.query(Email).filter(
                and_(Email.object_id == post_id, Email.user_id == user_id,
                     Email.trigger_id == tag_id,
                     Email.trigger_type == 'subscription')).all())

            # There should be exactly 1 email sent to the user for the target post
            # Check EmailSent records
            assert len(
                outbox) == 1, 'One subscription email should be actually sent'
            assert len(emails_sent
                       ) == 1, 'One subscription email should recorded as sent'
            # Check outbox of messages
            assert len(
                outbox[0].bcc
            ) == 1, 'One subscription email should be actually sent to one user'
            assert "Title: " in outbox[
                0].body, 'Plain email should use the txt template'
            assert "cid:Thumb" in outbox[
                0].html, 'Rich email should use the html template'
            # Check thumbnail attachment
            assert len(
                outbox[0].attachments) == 1, 'One attachment should be sent'
            thumbnail = outbox[0].attachments[0]
            assert base64.b64decode(
                self.thumbnail) == thumbnail.data, 'Attachment should match'
            assert [['Content-ID', '<Thumb>']
                    ] == thumbnail.headers, 'Attachment id should match'

            username_to_email = self.app.repository.config.username_to_email
            assert outbox[0].bcc[0] == username_to_email(
                self.knowledge_username)