Merge lp:~salgado/offspring/builder_details into lp:offspring

Proposed by Guilherme Salgado
Status: Merged
Approved by: Kevin McDermott
Approved revision: 110
Merged at revision: 110
Proposed branch: lp:~salgado/offspring/builder_details
Merge into: lp:offspring
Prerequisite: lp:~salgado/offspring/list-views
Diff against target: 164 lines (+50/-11)
6 files modified
Makefile (+2/-2)
lib/offspring/web/queuemanager/tests/test_views.py (+25/-7)
lib/offspring/web/queuemanager/views.py (+14/-1)
lib/offspring/web/templates/queuemanager/builder_details.html (+1/-1)
lib/offspring/web/templates/queuemanager/builds.html (+4/-0)
lib/offspring/web/templates/queuemanager/projects.html (+4/-0)
To merge this branch: bzr merge lp:~salgado/offspring/builder_details
Reviewer Review Type Date Requested Status
Kevin McDermott Approve
Review via email: mp+84295@code.launchpad.net

Description of the change

Update the builder_details view to omit details of the current job if the user has no rights to see it.

Also shows a small padlock icon next to private projects on both the list of projects and the list of builds

To post a comment you must log in.
108. By Guilherme Salgado

merge list-views branch

Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

=== modified file 'lib/offspring/web/queuemanager/tests/test_views.py'

+ # Stub Lexbuilder.average_load because it executes some SQL that's not
+ # supported by sqlite3 and we're not interested in testing it here.

Can you file a bug to fix this?

I would have fixed it when I was fixing the metrics code, but I'm not sure I fully understand what it's calculating (and the docstring isn't very helpful).

It looks to be calculating the % of the day that builds take for all builds that finish the same day as they start?

=== modified file 'lib/offspring/web/queuemanager/views.py'

+def builders(request):
+ # builder_list is a dictionary where keys are Lexbuilder instances to be
+ # shown and the values represent whether or not the information about the
+ # builder's current job should be shown to the current user.

Why no docstring?

+def builder_details(request, builderName):
+ # Here we don't filter out the builders working on private projects (as we

Again, no docstring, and this doesn't handle unknown builder names very well...

Other than that it looks pretty good...

My usual annoyances with things like...

+ projects = projects.select_related('project_group').order_by(
+ "project_group")

Why change between different quote types in the same statement?

And running PEP8 on view.py is horrific...but hey :-)

review: Needs Fixing
Revision history for this message
Guilherme Salgado (salgado) wrote :

Hi Kevin,

Thanks for the review!

On 11/01/12 05:59, Kevin McDermott wrote:
> Review: Needs Fixing
>
> === modified file 'lib/offspring/web/queuemanager/tests/test_views.py'
>
> + # Stub Lexbuilder.average_load because it executes some SQL that's not
> + # supported by sqlite3 and we're not interested in testing it here.
>
> Can you file a bug to fix this?
>
> I would have fixed it when I was fixing the metrics code, but I'm not sure I fully understand what it's calculating (and the docstring isn't very helpful).
>
> It looks to be calculating the % of the day that builds take for all builds that finish the same day as they start?

Hmm, this was not introduced on this branch, and it was not clear to me
we want to restrict ourselves to the subset of SQL implemented by sqlite3.

>
> === modified file 'lib/offspring/web/queuemanager/views.py'
>
> +def builders(request):
> + # builder_list is a dictionary where keys are Lexbuilder instances to be
> + # shown and the values represent whether or not the information about the
> + # builder's current job should be shown to the current user.
>
> Why no docstring?
>
> +def builder_details(request, builderName):
> + # Here we don't filter out the builders working on private projects (as we
>
> Again, no docstring, and this doesn't handle unknown builder names very well...

Mostly because, IMHO, there wouldn't be much to say other than what one
can easily infer from the function name, but I've added them regardless
as it certainly won't hurt.

>
> Other than that it looks pretty good...
>
> My usual annoyances with things like...
>
> + projects = projects.select_related('project_group').order_by(
> + "project_group")
>
> Why change between different quote types in the same statement?

This also wasn't introduced here...

Ok, now I understand, this branch depends on list-view
(https://code.launchpad.net/~salgado/offspring/list-views/+merge/84291),
which is still up for review. I'll change this on that branch.

109. By Guilherme Salgado

merge list-view branch

Revision history for this message
Guilherme Salgado (salgado) wrote :

I've actually done all the changes on the list-view branch as the relevant code was introduced there, but I've also merged that branch here again, so if you check the MP page you'll see the diff has the changes you suggested.

110. By Guilherme Salgado

Fix the builder_details view to raise a 404 when the builder name is not known

Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

Thanks for the fixes, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2011-12-12 22:24:42 +0000
3+++ Makefile 2012-01-11 16:50:40 +0000
4@@ -74,10 +74,10 @@
5 --cover-package=offspring.web
6
7 test-web: web web-test install-test-runner
8- ./bin/offspring-web test offspring.web.queuemanager --settings=offspring.web.settings_test
9+ ./bin/offspring-web test offspring.web.queuemanager -s --settings=offspring.web.settings_test
10
11 test-web-postgres: web web-test install-test-runner
12- ./bin/offspring-web test queuemanager --settings=offspring.web.settings_devel
13+ ./bin/offspring-web test offspring.web.queuemanager -s --settings=offspring.web.settings_devel
14
15 test: master slave web install-test-runner test-web master-test
16 ./.virtualenv/bin/nosetests -e 'queuemanager.*'
17
18=== modified file 'lib/offspring/web/queuemanager/tests/test_views.py'
19--- lib/offspring/web/queuemanager/tests/test_views.py 2012-01-11 14:50:20 +0000
20+++ lib/offspring/web/queuemanager/tests/test_views.py 2012-01-11 16:50:40 +0000
21@@ -146,7 +146,12 @@
22
23
24 class BuilderListTests(TestCase):
25- view_name = "offspring.web.queuemanager.views.builders"
26+ view_name = "builder_list"
27+
28+ def get_url(self, builder):
29+ # The builder argument exists only so that the tests here also work
30+ # for the builder_details view (see BuilderDetailsTests below).
31+ return reverse(self.view_name)
32
33 def setUp(self):
34 super(BuilderListTests, self).setUp()
35@@ -168,7 +173,7 @@
36 """
37 builder = factory.make_lexbuilder()
38 make_user_and_login(self.client)
39- response = self.client.get(reverse(self.view_name))
40+ response = self.client.get(self.get_url(builder))
41 self.assertContains(
42 response, builder.current_job.project.name, status_code=200,
43 msg_prefix=response.content)
44@@ -184,7 +189,7 @@
45 user = project.owner
46 self.assertTrue(
47 self.client.login(username=user.username, password=user.username))
48- response = self.client.get(reverse(self.view_name))
49+ response = self.client.get(self.get_url(builder))
50 self.assertContains(
51 response, builder.current_job.project.name, status_code=200,
52 msg_prefix=response.content)
53@@ -201,15 +206,28 @@
54 job = factory.make_build_result(project=project)
55 builder = factory.make_lexbuilder(current_job=job)
56 make_user_and_login(self.client)
57- response = self.client.get(reverse(self.view_name))
58- self.assertContains(
59- response, builder.name, status_code=200,
60- msg_prefix=response.content)
61+ response = self.client.get(self.get_url(builder))
62 self.assertNotContains(
63 response, builder.current_job.project.name, status_code=200,
64 msg_prefix=response.content)
65
66
67+class BuilderDetailsTests(BuilderListTests):
68+ view_name = 'builder_details'
69+
70+ def get_url(self, builder):
71+ return reverse(self.view_name, args=[builder.name])
72+
73+ def test_builder_details_with_unknown_builder_name(self):
74+ """
75+ If an unknown builder is specified, we should get a 404.
76+ """
77+ make_user_and_login(self.client)
78+ url = reverse(self.view_name, args=[u"unknown-builder"])
79+ response = self.client.get(url)
80+ self.assertEqual(404, response.status_code)
81+
82+
83 class BuildResultViewTests(TestCase):
84
85 def test_public_build(self):
86
87=== modified file 'lib/offspring/web/queuemanager/views.py'
88--- lib/offspring/web/queuemanager/views.py 2012-01-11 14:50:20 +0000
89+++ lib/offspring/web/queuemanager/views.py 2012-01-11 16:50:40 +0000
90@@ -85,6 +85,10 @@
91 # shown and the values represent whether or not the information about the
92 # builder's current job should be shown to the current user.
93 builder_list = {}
94+ # Here we don't filter out the builders working on private projects (as we
95+ # do with other stuff, using .accessible_by_user()) because we want to
96+ # show that the builders exist and just hide the info about private
97+ # projects the user is not allowed to see.
98 builders = Lexbuilder.all_objects.order_by(
99 "-is_active", "-machine_type", "-created_at")
100 for builder in builders:
101@@ -108,10 +112,19 @@
102 If the Lexbuilder is building a private project the user is not allowed to
103 see, the current job details are omitted.
104 """
105- builder = Lexbuilder.objects.get(name=builderName)
106+ # Here we don't filter out the builders working on private projects (as we
107+ # do with other stuff, using .accessible_by_user()) because we want to
108+ # show that the builders exist and just hide the info about private
109+ # projects the user is not allowed to see.
110+ builder = get_object_or_404(Lexbuilder.all_objects, name=builderName)
111+ shown_job = "Private build"
112+ job = builder.current_job
113+ if job is not None and job.is_visible_to(request.user):
114+ shown_job = job
115 pageData = {
116 "builder": builder,
117 "pillar": "builders",
118+ "current_job": shown_job,
119 }
120 return render_to_response(
121 "queuemanager/builder_details.html", pageData,
122
123=== modified file 'lib/offspring/web/templates/queuemanager/builder_details.html'
124--- lib/offspring/web/templates/queuemanager/builder_details.html 2011-01-22 04:47:32 +0000
125+++ lib/offspring/web/templates/queuemanager/builder_details.html 2012-01-11 16:50:40 +0000
126@@ -60,7 +60,7 @@
127
128 <dl>
129 <dt>Job:</dt>
130- <dd>{{builder.current_build}}</dd>
131+ <dd>{{current_job}}</dd>
132 </dl>
133
134 <dl>
135
136=== modified file 'lib/offspring/web/templates/queuemanager/builds.html'
137--- lib/offspring/web/templates/queuemanager/builds.html 2011-08-13 06:30:36 +0000
138+++ lib/offspring/web/templates/queuemanager/builds.html 2012-01-11 16:50:40 +0000
139@@ -31,6 +31,10 @@
140 <a title="View project details" href="{% url offspring.web.queuemanager.views.project_details build_result.project.name %}">
141 {{ build_result.project.title }}
142 </a>
143+ {% if build_result.project.is_private %}
144+ <img src="/assets/images/padlock-small.png"
145+ title="This project is private" />
146+ {% endif %}
147 </td>
148 <td>
149 {% if build_result.name %}
150
151=== modified file 'lib/offspring/web/templates/queuemanager/projects.html'
152--- lib/offspring/web/templates/queuemanager/projects.html 2011-08-13 06:30:36 +0000
153+++ lib/offspring/web/templates/queuemanager/projects.html 2012-01-11 16:50:40 +0000
154@@ -41,6 +41,10 @@
155 </td>
156 <td>
157 <a href="{% url offspring.web.queuemanager.views.project_details project.name %}">{{ project.title }}</a>
158+ {% if project.is_private %}
159+ <img src="/assets/images/padlock-small.png"
160+ title="This project is private" />
161+ {% endif %}
162 </td>
163 <td>
164 {{project.get_status_display|default_if_none:"Unknown"}}

Subscribers

People subscribed via source and target branches