Skip to content
This repository was archived by the owner on Aug 28, 2023. It is now read-only.

Commit ecbc1cc

Browse files
committed
Added some tests
1 parent 14735d1 commit ecbc1cc

File tree

6 files changed

+120
-6
lines changed

6 files changed

+120
-6
lines changed

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
sudo: false
2+
language: python
3+
services:
4+
- memcached
5+
- postgresql
6+
- redis-server
7+
python:
8+
- '2.7'
9+
cache: pip
10+
deploy:
11+
provider: pypi
12+
user: getsentry
13+
password:
14+
secure: Cckg3cvzfGBAKuSZ++eDLrezxxZCMBs97ZnDHhfLxpwbMhZXquXmkQHoOmd/7qUq5Yijdzz7XQb17qh3rlE+WcB+htmd+m3QEu2YIk8BwFFVE5CeRus7ALlNsYyn0dWv8wpbqGVihpF1pbKlIY+NUDD4MTICTTQrMU4CfpPEE6E=
15+
on:
16+
tags: true
17+
distributions: sdist bdist_wheel
18+
install:
19+
- make install-tests
20+
script:
21+
- flake8
22+
- py.test

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
develop:
2+
pip install "pip>=7"
3+
pip install -e .
4+
5+
install-tests: develop
6+
pip install .[tests]
7+
8+
.PHONY: develop install-tests

conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from __future__ import absolute_import
2+
3+
pytest_plugins = ['sentry.utils.pytest']

setup.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[bdist_wheel]
2+
universal = 1
3+
4+
[pytest]
5+
python_files = test*.py
6+
addopts = --tb=native -p no:doctest
7+
norecursedirs = bin dist docs htmlcov script hooks node_modules .* {args}
8+
9+
[flake8]
10+
ignore = F999,E501,E128,E124,E402,W503,E731,C901
11+
max-line-length = 100
12+
exclude = .tox,.git,*/migrations/*,node_modules/*,docs/*
13+

setup.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414

1515
tests_require = [
16-
'nose',
16+
'exam',
17+
'flake8>=2.0,<2.1',
18+
'responses',
1719
]
1820

1921
install_requires = [
@@ -33,15 +35,13 @@
3335
packages=find_packages('src'),
3436
zip_safe=False,
3537
install_requires=install_requires,
36-
tests_require=tests_require,
37-
extras_require={'test': tests_require},
38-
test_suite='runtests.runtests',
38+
extras_require={'tests': tests_require},
3939
include_package_data=True,
4040
entry_points={
41-
'sentry.apps': [
41+
'sentry.apps': [
4242
'github = sentry_github',
4343
],
44-
'sentry.plugins': [
44+
'sentry.plugins': [
4545
'github = sentry_github.plugin:GitHubPlugin'
4646
],
4747
},

tests/sentry_github/test_plugin.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from __future__ import absolute_import
2+
3+
import responses
4+
from exam import fixture
5+
from django.contrib.auth.models import AnonymousUser
6+
from django.forms import ValidationError
7+
from django.test import RequestFactory
8+
from django.test.utils import override_settings
9+
from sentry.testutils import TestCase
10+
from sentry.utils import json
11+
from social_auth.models import UserSocialAuth
12+
13+
from sentry_github.plugin import GitHubPlugin
14+
15+
16+
class GitHubPluginTest(TestCase):
17+
@fixture
18+
def plugin(self):
19+
return GitHubPlugin()
20+
21+
@fixture
22+
def request(self):
23+
return RequestFactory()
24+
25+
def test_get_issue_label(self):
26+
group = self.create_group(message='Hello world', culprit='foo.bar')
27+
assert self.plugin.get_issue_label(group, 1) == 'GH-1'
28+
29+
def test_get_issue_url(self):
30+
self.plugin.set_option('repo', 'getsentry/sentry', self.project)
31+
group = self.create_group(message='Hello world', culprit='foo.bar')
32+
assert self.plugin.get_issue_url(group, 1) == 'https://github.com/getsentry/sentry/issues/1'
33+
self.plugin.set_option('github_url', 'http://example.com', self.project)
34+
assert self.plugin.get_issue_url(group, 1) == 'http://example.com/getsentry/sentry/issues/1'
35+
36+
def test_is_configured(self):
37+
assert self.plugin.is_configured(None, self.project) is False
38+
self.plugin.set_option('repo', 'getsentry/sentry', self.project)
39+
assert self.plugin.is_configured(None, self.project) is True
40+
41+
@responses.activate
42+
@override_settings(GITHUB_APP_ID='abc', GITHUB_API_SECRET='123')
43+
def test_create_issue(self):
44+
self.plugin.set_option('repo', 'getsentry/sentry', self.project)
45+
group = self.create_group(message='Hello world', culprit='foo.bar')
46+
47+
request = self.request.get('/')
48+
request.user = AnonymousUser()
49+
form_data = {
50+
'title': 'Hello',
51+
'description': 'Fix this.',
52+
}
53+
with self.assertRaises(ValidationError):
54+
self.plugin.create_issue(request, group, form_data)
55+
56+
request.user = self.user
57+
self.login_as(self.user)
58+
UserSocialAuth.objects.create(user=self.user, provider=self.plugin.auth_provider, extra_data={'access_token': 'foo'})
59+
60+
responses.add(responses.POST, 'https://api.github.com/repos/getsentry/sentry/issues',
61+
body='{"number": 1}')
62+
assert self.plugin.create_issue(request, group, form_data) == 1
63+
request = responses.calls[0].request
64+
payload = json.loads(request.body)
65+
assert payload == {
66+
'title': 'Hello',
67+
'body': 'Fix this.',
68+
}

0 commit comments

Comments
 (0)