Example #1
0
# -*- coding: utf-8 -*-

#       Licensed to the Apache Software Foundation (ASF) under one
#       or more contributor license agreements.  See the NOTICE file
#       distributed with this work for additional information
#       regarding copyright ownership.  The ASF licenses this file
#       to you under the Apache License, Version 2.0 (the
#       "License"); you may not use this file except in compliance
#       with the License.  You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#       Unless required by applicable law or agreed to in writing,
#       software distributed under the License is distributed on an
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.

# Make our own Git tool test decorator
from __future__ import unicode_literals
from __future__ import absolute_import
from allura.tests.decorators import with_tool

with_git = with_tool('test', 'Git', 'src-git', 'Git', type='git')
Example #2
0
from unittest import TestCase
from mock import Mock, patch
from ming.odm import ThreadLocalORMSession

from allura.tests import TestController
from allura.tests.decorators import with_tool
from allura import model as M
from alluratest.controller import setup_unit_test
from forgeimporters.github.code import GitHubRepoImporter
from forgeimporters.github import GitHubOAuthMixin


# important to be distinct from 'test' which ForgeGit uses, so that the
# tests can run in parallel and not clobber each other
test_project_with_repo = 'test2'
with_git = with_tool(test_project_with_repo, 'git', 'src', 'git')


class TestGitHubRepoImporter(TestCase):

    def _make_project(self, gh_proj_name=None):
        project = Mock()
        project.get_tool_data.side_effect = lambda *args: gh_proj_name
        return project

    @patch('forgeimporters.github.code.M')
    @patch('forgeimporters.github.code.g')
    @patch('forgeimporters.github.code.GitHubProjectExtractor')
    def test_import_tool_happy_path(self, ghpe, g, M):
        setup_unit_test()
        ghpe.return_value.get_repo_url.return_value = 'http://remote/clone/url/'
Example #3
0
    send_webhook,
    RepoPushWebhookSender,
    SendWebhookHelper,
)
from allura.tests import decorators as td
from alluratest.controller import (
    setup_basic_test,
    TestController,
    TestRestApiBase,
)

# important to be distinct from 'test' and 'test2' which ForgeGit and
# ForgeImporter use, so that the tests can run in parallel and not clobber each
# other
test_project_with_repo = 'adobe-1'
with_git = td.with_tool(test_project_with_repo, 'git', 'src', 'Git')
with_git2 = td.with_tool(test_project_with_repo, 'git', 'src2', 'Git2')


class TestWebhookBase(object):
    def setUp(self):
        setup_basic_test()
        self.patches = self.monkey_patch()
        for p in self.patches:
            p.start()
        self.setup_with_tools()
        self.project = M.Project.query.get(shortname=test_project_with_repo)
        self.git = self.project.app_instance('src')
        self.wh = M.Webhook(type='repo-push',
                            app_config_id=self.git.config._id,
                            hook_url='http://httpbin.org/post',
Example #4
0
from tg import tmpl_context as c
from tg import config
import mock

from alluratest.controller import setup_basic_test, setup_global_objects, setup_trove_categories
from allura.tests import decorators as td
from allura.model import User, Project, TroveCategory
from allura.lib import helpers as h
from allura import model as M

from forgeuserstats.model import stats as USM

# important to be distinct from 'test' which ForgeGit uses, so that the
# tests can run in parallel and not clobber each other
with_git = td.with_tool('test', 'Git', 'git-userstats-model', 'Git', type='git')


class TestUserStats(unittest.TestCase):

    def setUp(self):
        setup_basic_test()
        setup_global_objects()
        self.user = User.by_username('test-user-2')
        c.user = self.user

    def test_init_values(self):
        artifacts = self.user.stats.getArtifacts()
        tickets = self.user.stats.getTickets()
        commits = self.user.stats.getCommits()
        assert self.user.stats.tot_logins_count == 0
Example #5
0
from pylons import tmpl_context as c
from tg import config
import mock

from alluratest.controller import setup_basic_test, setup_global_objects, setup_trove_categories
from allura.tests import decorators as td
from allura.model import User, Project, TroveCategory
from allura.lib import helpers as h
from allura import model as M

from forgeuserstats.model import stats as USM

# important to be distinct from 'test' which ForgeGit uses, so that the
# tests can run in parallel and not clobber each other
test_project_with_repo = 'test2'
with_git = td.with_tool(test_project_with_repo, 'Git',
                        'src-git', 'Git', type='git')


class TestUserStats(unittest.TestCase):

    def setUp(self):
        setup_basic_test()
        setup_global_objects()
        self.user = User.by_username('test-user-2')
        c.user = self.user

    def test_init_values(self):
        artifacts = self.user.stats.getArtifacts()
        tickets = self.user.stats.getTickets()
        commits = self.user.stats.getCommits()
        assert self.user.stats.tot_logins_count == 0
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.

from unittest import TestCase
from mock import patch
from ming.odm import ThreadLocalORMSession

from allura.tests import TestController
from allura.tests.decorators import with_tool
from allura import model as M

# important to be distinct from 'test' which ForgeTracker uses, so that the tests can run in parallel and not clobber each other
test_project_with_tracker = 'test2'
with_tracker = with_tool(test_project_with_tracker, 'tickets', 'spooky-issues',
                         'tickets')


class TestGitHubTrackerImportController(TestController, TestCase):

    url = '/p/%s/admin/ext/import/github-tracker/' % test_project_with_tracker

    @with_tracker
    def test_index(self):
        r = self.app.get(self.url)
        self.assertIsNotNone(r.html.find(attrs=dict(name='gh_user_name')))
        self.assertIsNotNone(r.html.find(attrs=dict(name='gh_project_name')))
        self.assertIsNotNone(r.html.find(attrs=dict(name='mount_label')))
        self.assertIsNotNone(r.html.find(attrs=dict(name='mount_point')))

    @with_tracker
Example #7
0
    RepoPushWebhookSender,
    SendWebhookHelper,
)
from allura.tests import decorators as td
from alluratest.controller import (
    setup_basic_test,
    TestController,
    TestRestApiBase,
)


# important to be distinct from 'test' and 'test2' which ForgeGit and
# ForgeImporter use, so that the tests can run in parallel and not clobber each
# other
test_project_with_repo = 'adobe-1'
with_git = td.with_tool(test_project_with_repo, 'git', 'src', 'Git')
with_git2 = td.with_tool(test_project_with_repo, 'git', 'src2', 'Git2')


class TestWebhookBase(object):
    def setUp(self):
        setup_basic_test()
        self.patches = self.monkey_patch()
        for p in self.patches:
            p.start()
        self.setup_with_tools()
        self.project = M.Project.query.get(shortname=test_project_with_repo)
        self.git = self.project.app_instance('src')
        self.wh = M.Webhook(
            type='repo-push',
            app_config_id=self.git.config._id,
Example #8
0
# -*- coding: utf-8 -*-

#       Licensed to the Apache Software Foundation (ASF) under one
#       or more contributor license agreements.  See the NOTICE file
#       distributed with this work for additional information
#       regarding copyright ownership.  The ASF licenses this file
#       to you under the Apache License, Version 2.0 (the
#       "License"); you may not use this file except in compliance
#       with the License.  You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#       Unless required by applicable law or agreed to in writing,
#       software distributed under the License is distributed on an
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.


# Make our own Git tool test decorator
from allura.tests.decorators import with_tool

with_git = with_tool('test', 'Git', 'src-git', 'Git', type='git')
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.

from unittest import TestCase
from mock import Mock, patch
from ming.odm import ThreadLocalORMSession

from allura.tests import TestController
from allura.tests.decorators import with_tool
from allura import model as M
from forgeimporters.github.code import GitHubRepoImporter

# important to be distinct from 'test' which ForgeGit uses, so that the tests can run in parallel and not clobber each other
test_project_with_repo = 'test2'
with_git = with_tool(test_project_with_repo, 'git', 'src', 'git')


class TestGitHubRepoImporter(TestCase):
    def _make_project(self, gh_proj_name=None):
        project = Mock()
        project.get_tool_data.side_effect = lambda *args: gh_proj_name
        return project

    @patch('forgeimporters.github.code.M')
    @patch('forgeimporters.github.code.g')
    @patch('forgeimporters.github.code.GitHubProjectExtractor')
    def test_import_tool_happy_path(self, ghpe, g, M):
        ghpe.return_value.get_repo_url.return_value = 'http://remote/clone/url/'
        p = self._make_project(gh_proj_name='myproject')
        u = Mock(name='c.user')
Example #10
0
#       software distributed under the License is distributed on an
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.

import json
from datadiff.tools import assert_equal

from alluratest.controller import TestController
from allura.tests.decorators import with_tool

from forgechat import model as CM


with_chat = with_tool('test', 'Chat', 'chat', 'Chat')


class TestRootController(TestController):

    def test_root_index(self):
        response = self.app.get('/chat/').follow()
        assert 'Log for' in response

    @with_chat
    def test_admin_configure(self):
        self.app.get('/').follow()  # establish session
        data = {'channel': 'test channel',
                '_session_id': self.app.cookies['_session_id']}
        ch = CM.ChatChannel.query.get()
        assert_equal(ch.channel, '')
Example #11
0
#       software distributed under the License is distributed on an
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.

from unittest import TestCase
from mock import Mock, patch

from allura.tests import TestController
from allura.tests.decorators import with_tool


# important to be distinct from 'test' which ForgeSVN uses, so that the tests can run in parallel and not clobber each other
test_project_with_repo = 'test2'
with_svn = with_tool(test_project_with_repo, 'SVN', 'src', 'SVN')


from forgeimporters.google.code import (
        get_repo_url,
        GoogleRepoImporter,
        GoogleRepoImportController,
        )


class TestGetRepoUrl(TestCase):

    def test_svn(self):
        r = get_repo_url('projname', 'svn')
        self.assertEqual(r, 'http://projname.googlecode.com/svn/')
Example #12
0
from tg import tmpl_context as c
from tg import config
import mock

from alluratest.controller import setup_basic_test, setup_global_objects, setup_trove_categories
from allura.tests import decorators as td
from allura.model import User, Project, TroveCategory
from allura.lib import helpers as h
from allura import model as M

from forgeuserstats.model import stats as USM

# important to be distinct from 'test' which ForgeGit uses, so that the
# tests can run in parallel and not clobber each other
with_git = td.with_tool('test', 'Git', 'git-userstats-model', 'Git', type='git')


class TestUserStats(unittest.TestCase):

    def setUp(self):
        setup_basic_test()
        setup_global_objects()
        self.user = User.by_username('test-user-2')
        c.user = self.user

    def test_init_values(self):
        artifacts = self.user.stats.getArtifacts()
        tickets = self.user.stats.getTickets()
        commits = self.user.stats.getCommits()
        assert self.user.stats.tot_logins_count == 0
Example #13
0
#       Unless required by applicable law or agreed to in writing,
#       software distributed under the License is distributed on an
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.

import json
from datadiff.tools import assert_equal

from alluratest.controller import TestController
from allura.tests.decorators import with_tool

from forgechat import model as CM

with_chat = with_tool('test', 'Chat', 'chat', 'Chat')


class TestRootController(TestController):
    def test_root_index(self):
        response = self.app.get('/chat/').follow()
        assert 'Log for' in response

    @with_chat
    def test_admin_configure(self):
        self.app.get('/').follow()  # establish session
        data = {
            'channel': 'test channel',
            '_session_id': self.app.cookies['_session_id']
        }
        ch = CM.ChatChannel.query.get()
Example #14
0
# -*- coding: utf-8 -*-

#       Licensed to the Apache Software Foundation (ASF) under one
#       or more contributor license agreements.  See the NOTICE file
#       distributed with this work for additional information
#       regarding copyright ownership.  The ASF licenses this file
#       to you under the Apache License, Version 2.0 (the
#       "License"); you may not use this file except in compliance
#       with the License.  You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#       Unless required by applicable law or agreed to in writing,
#       software distributed under the License is distributed on an
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.


## Make our own SVN tool test decorator
from allura.tests.decorators import with_tool

with_svn = with_tool('test', 'SVN', 'src', 'SVN')
Example #15
0
from mock import Mock, patch, call
from ming.odm import ThreadLocalORMSession

from IPython.testing.decorators import module_not_available, skipif
from allura import model as M
from allura.tests import TestController
from allura.tests.decorators import with_tool, without_module
from alluratest.controller import setup_basic_test
from forgeimporters.github.wiki import GitHubWikiImporter
from forgeimporters.github.utils import GitHubMarkdownConverter
from forgeimporters.github import GitHubOAuthMixin


# important to be distinct from 'test' which ForgeWiki uses, so that the tests can run in parallel and not clobber each other
test_project_with_wiki = 'test2'
with_wiki = with_tool(test_project_with_wiki, 'wiki', 'w', 'wiki')


class TestGitHubWikiImporter(TestCase):

    def _make_project(self, gh_proj_name=None):
        project = Mock()
        project.get_tool_data.side_effect = lambda *args: gh_proj_name
        return project


    @patch('forgeimporters.github.wiki.M')
    @patch('forgeimporters.github.wiki.ThreadLocalORMSession')
    @patch('forgeimporters.github.wiki.g')
    @patch('forgeimporters.github.wiki.GitHubProjectExtractor')
    def test_import_tool_happy_path(self, ghpe, g, tlorms, M):
from pylons import tmpl_context as c
from tg import config
import mock

from alluratest.controller import setup_basic_test, setup_global_objects
from allura.tests import decorators as td
from allura.model import User, Project, TroveCategory
from allura.lib import helpers as h
from allura import model as M

from forgeuserstats.model import stats as USM

test_project_with_repo = 'test2'  # important to be distinct from 'test' which ForgeGit uses, so that the tests can run in parallel and not clobber each other
with_git = td.with_tool(test_project_with_repo,
                        'Git',
                        'src-git',
                        'Git',
                        type='git')


class TestUserStats(unittest.TestCase):
    def setUp(self):
        from allura.model import User

        setup_basic_test()
        setup_global_objects()
        self.user = User.by_username('test-user-2')
        c.user = self.user

    def test_init_values(self):
        artifacts = self.user.stats.getArtifacts()
Example #17
0
from IPython.testing.decorators import module_not_available, skipif
from allura import model as M
from allura.tests import TestController
from allura.tests.decorators import with_tool, without_module
from alluratest.controller import setup_basic_test
from forgeimporters.github.wiki import GitHubWikiImporter
from forgeimporters.github.utils import GitHubMarkdownConverter
from forgeimporters.github import GitHubOAuthMixin
from six.moves import range


# important to be distinct from 'test' which ForgeWiki uses, so that the
# tests can run in parallel and not clobber each other
test_project_with_wiki = 'test2'
with_wiki = with_tool(test_project_with_wiki, 'wiki', 'w', 'wiki')


class TestGitHubWikiImporter(TestCase):

    def _make_project(self, gh_proj_name=None):
        project = Mock()
        project.get_tool_data.side_effect = lambda *args: gh_proj_name
        return project

    @patch('forgeimporters.github.wiki.M')
    @patch('forgeimporters.github.wiki.ThreadLocalORMSession')
    @patch('forgeimporters.github.wiki.g')
    @patch('forgeimporters.github.wiki.GitHubProjectExtractor')
    def test_import_tool_happy_path(self, ghpe, g, tlorms, M):
        with patch('forgeimporters.github.wiki.GitHubWikiImporter.import_pages'),\
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.

from unittest import TestCase
from mock import patch
from ming.odm import ThreadLocalORMSession

from allura.tests import TestController
from allura.tests.decorators import with_tool
from allura import model as M

# important to be distinct from 'test' which ForgeTracker uses, so that the tests can run in parallel and not clobber each other
test_project_with_tracker = 'test2'
with_tracker = with_tool(test_project_with_tracker, 'tickets', 'spooky-issues', 'tickets')


class TestGitHubTrackerImportController(TestController, TestCase):

    url = '/p/%s/admin/ext/import/github-tracker/' % test_project_with_tracker

    @with_tracker
    def test_index(self):
        r = self.app.get(self.url)
        self.assertIsNotNone(r.html.find(attrs=dict(name='gh_user_name')))
        self.assertIsNotNone(r.html.find(attrs=dict(name='gh_project_name')))
        self.assertIsNotNone(r.html.find(attrs=dict(name='mount_label')))
        self.assertIsNotNone(r.html.find(attrs=dict(name='mount_point')))

    @with_tracker
Example #19
0
# -*- coding: utf-8 -*-

#       Licensed to the Apache Software Foundation (ASF) under one
#       or more contributor license agreements.  See the NOTICE file
#       distributed with this work for additional information
#       regarding copyright ownership.  The ASF licenses this file
#       to you under the Apache License, Version 2.0 (the
#       "License"); you may not use this file except in compliance
#       with the License.  You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#       Unless required by applicable law or agreed to in writing,
#       software distributed under the License is distributed on an
#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#       KIND, either express or implied.  See the License for the
#       specific language governing permissions and limitations
#       under the License.

# Make our own SVN tool test decorator
from allura.tests.decorators import with_tool

with_svn = with_tool('test', 'SVN', 'src', 'SVN')
from pylons import tmpl_context as c

from alluratest.controller import TestController, setup_basic_test, setup_global_objects
from allura.tests import decorators as td
from allura.lib import helpers as h
from allura.model import User
from allura import model as M

from forgewiki import model as WM
from forgetracker import model as TM


test_project_with_repo = (
    "test2"
)  # important to be distinct from 'test' which ForgeGit uses, so that the tests can run in parallel and not clobber each other
with_git = td.with_tool(test_project_with_repo, "Git", "src-git", "Git", type="git")


class TestStats(TestController):
    def setUp(self):
        super(TestStats, self).setUp()
        p = M.Project.query.get(shortname="test")
        p.add_user(M.User.by_username("test-user"), ["Admin"])

    def test_login(self):
        user = User.by_username("test-user")
        init_logins = user.stats.tot_logins_count
        r = self.app.post("/auth/do_login", params=dict(username=user.username, password="******"))

        assert user.stats.tot_logins_count == 1 + init_logins
        assert user.stats.getLastMonthLogins() == 1 + init_logins