Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requirements.txt: Update Errbot #572

Merged
merged 2 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .moban.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: corobo

dependencies:
- pyopenssl
- git+https://github.com/errbotio/errbot@c2639879d4c298933cdf406193de5a5e626db12b
- git+https://github.com/errbotio/errbot@a0f35732484c8c0692e123c48653517cffa21a42
- wolframalpha
- github3.py~=1.0.0
- IGitt==0.4.1.dev20180317153318
Expand Down
2 changes: 1 addition & 1 deletion plugins/git_stats.plug
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Core]
name = git_stats
name = GitStats
module = git_stats

[Documentation]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pyopenssl
git+https://github.com/errbotio/errbot@c2639879d4c298933cdf406193de5a5e626db12b
git+https://github.com/errbotio/errbot@a0f35732484c8c0692e123c48653517cffa21a42
wolframalpha
github3.py~=1.0.0
IGitt==0.4.1.dev20180317153318
Expand Down
25 changes: 11 additions & 14 deletions tests/ban_test.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import logging
import unittest
from unittest.mock import MagicMock, patch, PropertyMock

import plugins.ban

from tests.helper import plugin_testbot
from tests.corobo_test_case import CoroboTestCase


class TestBan(unittest.TestCase):
class TestBan(CoroboTestCase):

def setUp(self):
super().setUp((plugins.ban.Ban,))
self.ban = self.load_plugin('Ban')
self.ban.bot_config.ROOMS_TO_JOIN = (
'coala/coala', 'coala/coala-bears')
self.ban.bot_config.BOT_IDENTITY['token'] = 'mocked?'

@patch('plugins.ban.requests')
@patch('plugins.ban.json')
def test_ban_cmd(self, mockjson, mockreq):
ban, testbot = plugin_testbot(plugins.ban.Ban, logging.ERROR)
ban.activate()

ban.bot_config.ROOMS_TO_JOIN = ('coala/coala', 'coala/coala-bears')
ban.bot_config.BOT_IDENTITY['token'] = 'mocked?'
status_mock = MagicMock()
type(status_mock).status_code = PropertyMock(return_value=200)
mockreq.post.return_value = status_mock
Expand All @@ -27,18 +27,14 @@ def test_ban_cmd(self, mockjson, mockreq):
{'id': '897', 'uri': 'coala/coala-bears'}
]
mockjson.loads.return_value = fake_room_data
testbot = self
testbot.assertCommand('!ban @nvzard',
'nvzard has been banned from: coala/coala, '
'coala/coala-bears')

@patch('plugins.ban.requests')
@patch('plugins.ban.json')
def test_unban_cmd(self, mockjson, mockreq):
ban, testbot = plugin_testbot(plugins.ban.Ban, logging.ERROR)
ban.activate()

ban.bot_config.ROOMS_TO_JOIN = ('coala/coala', 'coala/coala-bears')
ban.bot_config.BOT_IDENTITY['token'] = 'mocked?'
status_mock = MagicMock()
type(status_mock).status_code = PropertyMock(return_value=200)
mockreq.delete.return_value = status_mock
Expand All @@ -49,6 +45,7 @@ def test_unban_cmd(self, mockjson, mockreq):
{'id': '897', 'uri': 'coala/coala-bears'}
]
mockjson.loads.return_value = fake_room_data
testbot = self
testbot.assertCommand('!unban @nvzard',
'nvzard has been unbanned from: coala/coala, '
'coala/coala-bears')
44 changes: 44 additions & 0 deletions tests/corobo_test_case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from errbot.backends.test import FullStackTest
from errbot.plugin_info import PluginInfo
from errbot.templating import add_plugin_templates_path
from pathlib import Path

import logging


class CoroboTestCase(FullStackTest):

def setUp(self, klasses: tuple):
super().setUp(loglevel=logging.ERROR,
extra_config={'BACKEND': 'text'})
self.klasses = {}
self.plug_files = {}
self.plugins = {}

for klass in klasses:
self.klasses[klass.__name__] = klass
self.load_plugin_templates(klass)

def load_plugin_templates(self, klass):
plug_filename = klass.__module__.split('.')[-1] + '.plug'
plug_file_path = (Path(__file__)
.parent / '..' / 'plugins' / plug_filename)
with plug_file_path.open() as plugfile:
plug_info = PluginInfo.load_file(plugfile, plug_file_path)
self.plug_files[klass.__name__] = plug_info
add_plugin_templates_path(plug_info)

def load_plugin(self, plugin_name: str, mock_dict=False):
"""Load plugin manually"""
klass = self.klasses[plugin_name]
plugin = klass(self.bot, plugin_name)
plugin.activate()
self.plugins[plugin_name] = plugin
self.bot.plugin_manager.plugins[plugin_name] = plugin
plug_file = self.plug_files[plugin_name]
self.bot.plugin_manager.plugin_infos[plug_file.name] = plug_file

if mock_dict:
self.inject_mocks(plugin_name=plugin_name, mock_dict=mock_dict)

return plugin
14 changes: 6 additions & 8 deletions tests/git_stats_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import logging
from tempfile import mkdtemp
from errbot import BotPlugin
import unittest
from unittest.mock import create_autospec

from IGitt.GitHub.GitHubMergeRequest import GitHubMergeRequest
Expand All @@ -14,12 +12,13 @@
import IGitt
import plugins.git_stats
import plugins.labhub
from tests.helper import plugin_testbot
from tests.corobo_test_case import CoroboTestCase


class TestGitStats(unittest.TestCase):
class TestGitStats(CoroboTestCase):

def setUp(self):
super().setUp((plugins.git_stats.GitStats,))
plugins.git_stats.github3 = create_autospec(github3)
self.mock_org = create_autospec(github3.orgs.Organization)
self.mock_gh = create_autospec(github3.GitHub)
Expand All @@ -30,12 +29,10 @@ def setUp(self):

self.plugin = plugins.git_stats.GitStats
self.plugin.__bases__ = (BotPlugin, )
self.git_stats = self.load_plugin('GitStats')
self.git_stats.REPOS = {'test': self.mock_repo}

def test_pr_list(self):
git_stats, testbot = plugin_testbot(self.plugin, logging.ERROR)
git_stats.activate()

git_stats.REPOS = {'test': self.mock_repo}
mock_github_mr = create_autospec(GitHubMergeRequest)
mock_gitlab_mr = create_autospec(GitLabMergeRequest)
mock_github_issue = create_autospec(GitHubIssue)
Expand All @@ -49,6 +46,7 @@ def test_pr_list(self):
mock_repo_obj = create_autospec(Repo)
cmd_github = '!mergable {}'
cmd_gitlab = '!mergable {}'
testbot = self

self.mock_repo.merge_requests = [mock_github_mr]

Expand Down
9 changes: 0 additions & 9 deletions tests/helper.py

This file was deleted.

Loading