allura
Révision | 4b355d125835dbba745bcaa00a4f855e762c1c4e (tree) |
---|---|
l'heure | 2012-03-02 00:44:25 |
Auteur | Dave Brondsema <dbrondsema@geek...> |
Commiter | Cory Johns |
[#3824] don't do extra set_context lookup attempts if an ObjectId was used
Signed-off-by: Dave Brondsema <dbrondsema@geek.net>
@@ -174,7 +174,7 @@ def set_context(project_shortname_or_id, mount_point=None, app_config_id=None, n | ||
174 | 174 | p = model.Project.query.get(_id=ObjectId(str(project_shortname_or_id))) |
175 | 175 | except InvalidId: |
176 | 176 | p = None |
177 | - if p is None: | |
177 | + if p is None and type(project_shortname_or_id) != ObjectId: | |
178 | 178 | if neighborhood is None: |
179 | 179 | raise TypeError('neighborhood is required; it must not be None') |
180 | 180 | if not isinstance(neighborhood, model.Neighborhood): |
@@ -1,5 +1,6 @@ | ||
1 | 1 | from nose.tools import assert_raises |
2 | 2 | from pylons import c |
3 | +from bson import ObjectId | |
3 | 4 | |
4 | 5 | from allura.lib.helpers import set_context |
5 | 6 | from allura.lib.exceptions import NoSuchProjectError, NoSuchNeighborhoodError |
@@ -79,6 +80,13 @@ class TestWhenProjectIsNotFound(WithDatabase): | ||
79 | 80 | 'myproject', |
80 | 81 | neighborhood=nbhd) |
81 | 82 | |
83 | + def test_proper_exception_when_id_lookup(self): | |
84 | + nbhd = create_neighborhood() | |
85 | + assert_raises(NoSuchProjectError, | |
86 | + set_context, | |
87 | + ObjectId(), | |
88 | + neighborhood=None) | |
89 | + | |
82 | 90 | class TestWhenNeighborhoodIsNotFound(WithDatabase): |
83 | 91 | |
84 | 92 | def test_that_it_raises_an_exception(self): |