aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3
diff options
context:
space:
mode:
authorAlejandro Gómez <alejandroogomez@gmail.com>2012-04-27 13:50:25 +0200
committerAlejandro Gómez <alejandroogomez@gmail.com>2012-05-27 19:54:29 +0200
commit837c07729c089b8c5fdf3828cedff054b0cf1dde (patch)
tree3afcb0ab80782c22d74baeae803a369c8886eea0 /pygithub3
parentLabels and Milestones services added (diff)
downloadpython-github3-837c07729c089b8c5fdf3828cedff054b0cf1dde.tar.xz
python-github3-837c07729c089b8c5fdf3828cedff054b0cf1dde.zip
test Label validation errors
Diffstat (limited to 'pygithub3')
-rw-r--r--pygithub3/requests/issues/labels.py14
-rw-r--r--pygithub3/requests/repos/__init__.py1
-rw-r--r--pygithub3/resources/issues.py2
-rw-r--r--pygithub3/tests/resources/test_issues.py17
-rw-r--r--pygithub3/tests/services/test_issues.py22
5 files changed, 49 insertions, 7 deletions
diff --git a/pygithub3/requests/issues/labels.py b/pygithub3/requests/issues/labels.py
index 47337f9..75e11e4 100644
--- a/pygithub3/requests/issues/labels.py
+++ b/pygithub3/requests/issues/labels.py
@@ -18,11 +18,13 @@ class Create(Request):
'required': ('name', 'color' )
}
- def validate_color(color):
- color = color.get('color', '')
+ def clean_body(self):
+ color = self.body.get('color', '')
if not Label.is_valid_color(color):
raise ValidationError('colors must have 6 hexadecimal characters, '
'without # in the beggining')
+ else:
+ return self.body
class Update(Request):
@@ -33,12 +35,13 @@ class Update(Request):
'schema': ('name', 'color'),
'required': ('name', 'color' )
}
-
- def validate_color(color):
- color = color.get('color', '')
+ def clean_body(self):
+ color = self.body.get('color', '')
if not Label.is_valid_color(color):
raise ValidationError('colors must have 6 hexadecimal characters, '
'without # in the beggining')
+ else:
+ return self.body
class Delete(Request):
@@ -61,6 +64,7 @@ class Add_to_issue(Request):
uri = 'repos/{user}/{repo}/issues/{number}/labels'
resource = Label
+
class Remove_from_issue(Request):
uri = 'repos/{user}/{repo}/issues/{number}/labels/{name}'
resource = Label
diff --git a/pygithub3/requests/repos/__init__.py b/pygithub3/requests/repos/__init__.py
index 7a145f2..a4a1acb 100644
--- a/pygithub3/requests/repos/__init__.py
+++ b/pygithub3/requests/repos/__init__.py
@@ -89,7 +89,6 @@ class List_milestones(Request):
uri = 'repos/{user}/{repo}/milestones'
resource = Milestone
- # TODO: validate
body_schema = {
'schema': ('state', 'sort', 'direction'),
'required': ()
diff --git a/pygithub3/resources/issues.py b/pygithub3/resources/issues.py
index c560faa..af7547f 100644
--- a/pygithub3/resources/issues.py
+++ b/pygithub3/resources/issues.py
@@ -11,7 +11,7 @@ class Label(Resource):
@staticmethod
def is_valid_color(color):
valid_color = re.compile(r'[0-9abcdefABCDEF]{6}')
- match = valid_color(color)
+ match = valid_color.match(color)
if match is None:
return False
return match.start() == 0 and match.end() == len(color)
diff --git a/pygithub3/tests/resources/test_issues.py b/pygithub3/tests/resources/test_issues.py
new file mode 100644
index 0000000..0bef3c1
--- /dev/null
+++ b/pygithub3/tests/resources/test_issues.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from unittest import TestCase
+
+from pygithub3.resources.issues import Label
+
+
+class TestLabel(TestCase):
+ def test_is_valid_color(self):
+ valid_colors = ['BADA55', 'FFFFFF', '45DFCA']
+ for color in valid_colors:
+ self.assertTrue(Label.is_valid_color(color))
+
+ invalid_colors = ['BDA55', '#FFAABB', 'FFf']
+ for color in invalid_colors:
+ self.assertFalse(Label.is_valid_color(color))
diff --git a/pygithub3/tests/services/test_issues.py b/pygithub3/tests/services/test_issues.py
index 33ce754..4672bdb 100644
--- a/pygithub3/tests/services/test_issues.py
+++ b/pygithub3/tests/services/test_issues.py
@@ -4,6 +4,7 @@
import requests
from mock import patch, Mock
+from pygithub3.exceptions import ValidationError
from pygithub3.tests.utils.core import TestCase
from pygithub3.resources.base import json
from pygithub3.services.issues import Issue, Comments, Events, Labels, Milestones
@@ -133,12 +134,33 @@ class TestLabelsService(TestCase):
self.assertEqual(request_method.call_args[0],
('post', _('repos/octocat/Hello-World/labels')))
+ def test_CREATE_with_invalid_color(self, request_method):
+ request_method.return_value = mock_response('post')
+ # invalid color
+ with self.assertRaises(ValidationError):
+ args={'user': 'octocat',
+ 'repo': 'Hello-world',
+ 'name': 'bug',
+ 'color': 'FF00',}
+ self.lb.create(**args)
+
def test_UPDATE(self, request_method):
request_method.return_value = mock_response('patch')
self.lb.update('octocat', 'Hello-World', 'bug', 'critical', 'FF0000')
self.assertEqual(request_method.call_args[0],
('patch', _('repos/octocat/Hello-World/labels/bug')))
+ def test_UPDATE_with_invalid_color(self, request_method):
+ request_method.return_value = mock_response('post')
+ # invalid color
+ with self.assertRaises(ValidationError):
+ args={'user': 'octocat',
+ 'repo': 'Hello-world',
+ 'name': 'bug',
+ 'new_name': 'critical',
+ 'color': 'FF00',}
+ self.lb.update(**args)
+
def test_DELETE(self, request_method):
request_method.return_value = mock_response('delete')
self.lb.delete('octocat', 'Hello-World', 'bug')