-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from BenjamenMeyer/enhancement_regex_uri_matching
Enhancement: Basic Regex pattern matching for service URLs
- Loading branch information
Showing
7 changed files
with
143 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import re | ||
import unittest | ||
|
||
|
||
from stackinabox.services.service import * | ||
|
||
|
||
class TestServiceRegex(unittest.TestCase): | ||
|
||
def setUp(self): | ||
super(TestServiceRegex, self).setUp() | ||
|
||
def tearDown(self): | ||
super(TestServiceRegex, self).tearDown() | ||
|
||
def test_stackinabox_service_regex(self): | ||
|
||
positive_cases = [ | ||
re.compile('^/$') | ||
] | ||
|
||
negative_cases = [ | ||
re.compile('^/'), | ||
re.compile('/$') | ||
] | ||
|
||
for case in positive_cases: | ||
StackInABoxService.validate_regex(case) | ||
|
||
for case in negative_cases: | ||
with self.assertRaises(InvalidRouteRegexError): | ||
StackInABoxService.validate_regex(case) | ||
|
||
|
||
class AnotherAdvancedService(StackInABoxService): | ||
|
||
def __init__(self): | ||
super(AnotherAdvancedService, self).__init__('aas') | ||
self.register(StackInABoxService.GET, '/', | ||
AnotherAdvancedService.first_handler) | ||
|
||
def first_handler(self, request, uri, headers): | ||
return (200, headers, 'hello') | ||
|
||
def second_handler(self, request, uri, headers): | ||
return (200, headers, 'howdy') | ||
|
||
|
||
class TestServiceRouteRegistration(unittest.TestCase): | ||
|
||
def setUp(self): | ||
super(TestServiceRouteRegistration, self).setUp() | ||
|
||
def tearDown(self): | ||
super(TestServiceRouteRegistration, self).tearDown() | ||
|
||
def test_bad_registration(self): | ||
|
||
service = AnotherAdvancedService() | ||
|
||
with self.assertRaises(RouteAlreadyRegisteredError): | ||
service.register(StackInABoxService.GET, '/', | ||
AnotherAdvancedService.second_handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters