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

Commit

Permalink
Added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed Feb 29, 2016
1 parent 14735d1 commit effd98c
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 6 deletions.
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
sudo: false
language: python
services:
- memcached
- postgresql
- redis-server
python:
- '2.7'
cache: pip
deploy:
provider: pypi
user: getsentry
password:
secure: Cckg3cvzfGBAKuSZ++eDLrezxxZCMBs97ZnDHhfLxpwbMhZXquXmkQHoOmd/7qUq5Yijdzz7XQb17qh3rlE+WcB+htmd+m3QEu2YIk8BwFFVE5CeRus7ALlNsYyn0dWv8wpbqGVihpF1pbKlIY+NUDD4MTICTTQrMU4CfpPEE6E=
on:
tags: true
distributions: sdist bdist_wheel
install:
- make install-tests
script:
- flake8
- py.test
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
develop:
pip install -e .

install-tests: develop
pip install .[tests]

.PHONY: develop install-tests
3 changes: 3 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import absolute_import

pytest_plugins = ['sentry.utils.pytest']
13 changes: 13 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[bdist_wheel]
universal = 1

[pytest]
python_files = test*.py
addopts = --tb=native -p no:doctest
norecursedirs = bin dist docs htmlcov script hooks node_modules .* {args}

[flake8]
ignore = F999,E501,E128,E124,E402,W503,E731,C901
max-line-length = 100
exclude = .tox,.git,*/migrations/*,node_modules/*,docs/*

12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


tests_require = [
'nose',
'exam',
'flake8>=2.0,<2.1',
'responses',
]

install_requires = [
Expand All @@ -33,15 +35,13 @@
packages=find_packages('src'),
zip_safe=False,
install_requires=install_requires,
tests_require=tests_require,
extras_require={'test': tests_require},
test_suite='runtests.runtests',
extras_require={'tests': tests_require},
include_package_data=True,
entry_points={
'sentry.apps': [
'sentry.apps': [
'github = sentry_github',
],
'sentry.plugins': [
'sentry.plugins': [
'github = sentry_github.plugin:GitHubPlugin'
],
},
Expand Down
68 changes: 68 additions & 0 deletions tests/sentry_github/test_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from __future__ import absolute_import

import responses
from exam import fixture
from django.contrib.auth.models import AnonymousUser
from django.forms import ValidationError
from django.test import RequestFactory
from django.test.utils import override_settings
from sentry.testutils import TestCase
from sentry.utils import json
from social_auth.models import UserSocialAuth

from sentry_github.plugin import GitHubPlugin


class GitHubPluginTest(TestCase):
@fixture
def plugin(self):
return GitHubPlugin()

@fixture
def request(self):
return RequestFactory()

def test_get_issue_label(self):
group = self.create_group(message='Hello world', culprit='foo.bar')
assert self.plugin.get_issue_label(group, 1) == 'GH-1'

def test_get_issue_url(self):
self.plugin.set_option('repo', 'getsentry/sentry', self.project)
group = self.create_group(message='Hello world', culprit='foo.bar')
assert self.plugin.get_issue_url(group, 1) == 'https://github.com/getsentry/sentry/issues/1'
self.plugin.set_option('github_url', 'http://example.com', self.project)
assert self.plugin.get_issue_url(group, 1) == 'http://example.com/getsentry/sentry/issues/1'

def test_is_configured(self):
assert self.plugin.is_configured(None, self.project) is False
self.plugin.set_option('repo', 'getsentry/sentry', self.project)
assert self.plugin.is_configured(None, self.project) is True

@responses.activate
@override_settings(GITHUB_APP_ID='abc', GITHUB_API_SECRET='123')
def test_create_issue(self):
self.plugin.set_option('repo', 'getsentry/sentry', self.project)
group = self.create_group(message='Hello world', culprit='foo.bar')

request = self.request.get('/')
request.user = AnonymousUser()
form_data = {
'title': 'Hello',
'description': 'Fix this.',
}
with self.assertRaises(ValidationError):
self.plugin.create_issue(request, group, form_data)

request.user = self.user
self.login_as(self.user)
UserSocialAuth.objects.create(user=self.user, provider=self.plugin.auth_provider, extra_data={'access_token': 'foo'})

responses.add(responses.POST, 'https://api.github.com/repos/getsentry/sentry/issues',
body='{"number": 1}')
assert self.plugin.create_issue(request, group, form_data) == 1
request = responses.calls[0].request
payload = json.loads(request.body)
assert payload == {
'title': 'Hello',
'body': 'Fix this.',
}

0 comments on commit effd98c

Please sign in to comment.