<commit_before># -*- coding: utf8 -*-
# This file is part of PyBossa.
#
# Copyright (C) 2015 SciFabric LTD.
#
# PyBossa 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.
#
# PyBossa 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa.  If not, see <http://www.gnu.org/licenses/>.
from helper import web
from default import with_context
from factories import ProjectFactory, UserFactory
from pybossa.core import user_repo

class TestWebSse(web.Helper):


    @with_context
    def test_stream_uri_private_anon(self):
        """Test stream URI private anon works."""
        project = ProjectFactory.create()
        private_uri = '/project/%s/privatestream' % project.short_name
        res = self.app.get(private_uri, follow_redirects=True)
        assert res.status_code == 200, res.status_code
        assert 'Please sign in to access this page' in res.data, res.data

    @with_context
    def test_stream_uri_private_auth(self):
        """Test stream URI private auth but not owner works."""
        self.register()
        user = user_repo.get(1)
        project = ProjectFactory.create(owner=user)
        self.signout()
        self.register(fullname='Juan', name='juan', password='<PASSWORD>')
        private_uri = '/project/%s/privatestream' % project.short_name
        res = self.app.get(private_uri, follow_redirects=True)
        assert res.status_code == 403, res.data<commit_msg>Test for project event stream.<commit_after># -*- coding: utf8 -*-
# This file is part of PyBossa.
#
# Copyright (C) 2015 SciFabric LTD.
#
# PyBossa 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.
#
# PyBossa 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with PyBossa.  If not, see <http://www.gnu.org/licenses/>.
from helper import web
from default import with_context, FakeResponse
from factories import ProjectFactory
from pybossa.core import user_repo
from mock import patch


class TestWebSse(web.Helper):


    @with_context
    def test_stream_uri_private_anon(self):
        """Test stream URI private anon works."""
        project = ProjectFactory.create()
        private_uri = '/project/%s/privatestream' % project.short_name
        res = self.app.get(private_uri, follow_redirects=True)
        assert res.status_code == 200, res.status_code
        assert 'Please sign in to access this page' in res.data, res.data

    @with_context
    def test_stream_uri_private_auth(self):
        """Test stream URI private auth but not owner works."""
        self.register()
        user = user_repo.get(1)
        project = ProjectFactory.create(owner=user)
        self.signout()
        self.register(fullname='Juan', name='juan', password='<PASSWORD>')
        private_uri = '/project/%s/privatestream' % project.short_name
        res = self.app.get(private_uri, follow_redirects=True)
        assert res.status_code == 403, res.data

    @with_context
    @patch('pybossa.view.projects.project_event_stream')
    @patch('flask.Response', autospec=True)
    def test_stream_uri_private_owner(self, mock_response, mock_sse):
        """Test stream URI private owner works."""
        self.register()
        user = user_repo.get(1)
        project = ProjectFactory.create(owner=user)
        private_uri = '/project/%s/privatestream' % project.short_name
        self.app.get(private_uri, follow_redirects=True)
        assert mock_sse.called
        assert mock_sse.called_once_with(project.short_name, 'private')
{'fraction_non_alphanumeric': 0.09022038567493113, 'fraction_numerical': 0.006198347107438017, 'mean_word_length': 3.5197095435684647, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4585812', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1225, 'n_words': 426}