Merge lp://qastaging/~rvb/maas/maas-improve-tests into lp://qastaging/~maas-committers/maas/trunk
Status: | Merged |
---|---|
Approved by: | Raphaël Badin |
Approved revision: | no longer in the source branch. |
Merged at revision: | 49 |
Proposed branch: | lp://qastaging/~rvb/maas/maas-improve-tests |
Merge into: | lp://qastaging/~maas-committers/maas/trunk |
Prerequisite: | lp://qastaging/~rvb/maas/maas-cleanups |
Diff against target: |
189 lines (+97/-20) 3 files modified
src/maasserver/middleware.py (+6/-6) src/maasserver/tests/test_api.py (+20/-1) src/maasserver/tests/test_models.py (+71/-13) |
To merge this branch: | bzr merge lp://qastaging/~rvb/maas/maas-improve-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jeroen T. Vermeulen (community) | Approve | ||
Review via email: mp+90078@code.qastaging.launchpad.net |
Commit message
Make api doc accessible to anon users, improve tests.
Description of the change
This branch:
- makes the api doc accessible to anon users
- improves test coverage:
./bin/django test --with-coverage --cover-
.......
Name Stmts Miss Cover Missing
-------
maasserver 0 0 100%
maasserver.api 114 1 99% 50
maasserver.
maasserver.
maasserver.
maasserver.
maasserver.
maasserver.models 83 1 99% 153
maasserver.urls 18 0 100%
maasserver.views 18 2 89% 36, 44
-------
TOTAL 289 10 97%
-------
Ran 59 tests in 13.732s
Hi,
Lots of progress but there's one thing I feel very strongly needs fixing. See rant inline:
=== modified file 'src/maasserver /middleware. py' middleware. py 2012-01-24 13:21:41 +0000 middleware. py 2012-01-25 11:34:39 +0000
--- src/maasserver/
+++ src/maasserver/
@@ -43,7 +43,8 @@
> def process_ request( self, request): url.match( request. path): url.match( request. path) urls.match( request. path)): user.is_ anonymous( ):
> # API views.
> - if self.api_
> + if (self.api_
> + and not self.public_
> if request.
> return rc.FORBIDDEN
> else:
Line-breaking conditionals often makes it harder to grok the code at speed. It also raises the "where does the 'and' go" controversy in an awkward place. Could you rephrase this so that the "if" is a single line?
@@ -125,6 +131,19 @@
self. assertEqual( 0, Node.objects. filter( hostname= 'diane' ).count( ))
self. assertEqual( 1, Node.objects. filter( hostname= 'francis' ).count( ))
+ def test_node_ PUT_invalid( self): make_node( hostname= 'diane' )
+ """
+ If the data provided to update a node is invalid, a 'Bad request'
+ response is returned.
+
+ """
+ node = factory.
+ response = self.client.put(
+ '/api/nodes/%s/' % node.system_id,
+ {'hostname': ''.join(['too long' for x in xrange(100)])})
Tip: "too long" * 100
=== modified file 'src/maasserver /tests/ test_models. py' tests/test_ models. py 2012-01-23 12:43:28 +0000 tests/test_ models. py 2012-01-25 11:34:39 +0000 l(len(self. node.system_ id), 41) (self.node. system_ id.startswith( 'node-' )) status( self): l('New' , self.node. display_ status( ))
--- src/maasserver/
+++ src/maasserver/
@@ -34,6 +39,9 @@
> self.assertEqua
> self.assertTrue
>
> + def test_display_
> + self.assertEqua
> +
Waitwaitwait — where does self.node come from? What are you testing and proving exactly when you say its display_status is 'New'? Yes, I can guess, but making people guess is a bad habit. Tests should be as self-evident and independent as possible.
@@ -48,6 +56,50 @@
+class NodeManagerTest (TestCase) : erTest, self).setUp() make_admin( ) NODE_STATUS. DEPLOYED, NODE_STATUS. DEPLOYED,
+
+ def setUp(self):
+ super(NodeManag
+ self.user = factory.make_user()
+ self.admin = factory.
+ self.anon_node = factory.make_node()
+ self.user_node = factory.make_node(
+ set_hostname=True, status=
+ owner=self.user)
+ self.admin_node = factory.make_node(
+ set_hostname=True, status=
+ owner=self.admin)
This is more of the bad habit: for every test I need to look at, I have to bear in mind how setUp initialized these objects.
It's also usually bad for performance, since setUp() gets called for each test in the test case. When test cases are set up in this way, they typically initially objects that not all of the tests need.
And in the longer run, there's always the temptation to extend the setup, which makes the problems worse. If you need an object created for a test, create it in a helper method that you call explicitly.
+ def test_ge...