launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #04318
[Merge] lp:~stevenk/launchpad/destroy-branchsparkview into lp:launchpad
Steve Kowalik has proposed merging lp:~stevenk/launchpad/destroy-branchsparkview into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~stevenk/launchpad/destroy-branchsparkview/+merge/68627
Nuke BranchSparkView from orbit.
--
https://code.launchpad.net/~stevenk/launchpad/destroy-branchsparkview/+merge/68627
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/destroy-branchsparkview into lp:launchpad.
=== modified file 'lib/lp/code/browser/branch.py'
--- lib/lp/code/browser/branch.py 2011-07-11 03:58:41 +0000
+++ lib/lp/code/browser/branch.py 2011-07-21 02:35:57 +0000
@@ -21,7 +21,6 @@
'BranchNavigation',
'BranchEditMenu',
'BranchInProductView',
- 'BranchSparkView',
'BranchUpgradeView',
'BranchURL',
'BranchView',
@@ -1463,60 +1462,3 @@
@property
def prefix(self):
return "tryagain"
-
-
-class BranchSparkView(LaunchpadView):
- """This view generates the JSON data for the commit sparklines."""
-
- __for__ = IBranch
-
- # How many days to look for commits.
- COMMIT_DAYS = 90
-
- def _commitCounts(self):
- """Return a dict of commit counts for rendering."""
- epoch = (
- datetime.now(
- tz=pytz.UTC) - timedelta(days=(self.COMMIT_DAYS - 1)))
- # Make a datetime for that date, but midnight.
- epoch = epoch.replace(hour=0, minute=0, second=0, microsecond=0)
- commits = dict(self.context.commitsForDays(epoch))
- # However storm returns tz-unaware datetime objects.
- day = datetime(year=epoch.year, month=epoch.month, day=epoch.day)
- days = [day + timedelta(days=count)
- for count in range(self.COMMIT_DAYS)]
-
- commit_list = []
- total_commits = 0
- most_commits = 0
- for index, day in enumerate(days):
- count = commits.get(day, 0)
- commit_list.append(count)
- total_commits += count
- if count >= most_commits:
- most_commits = count
- max_index = index
- return {'count': total_commits,
- 'commits': commit_list,
- 'max_commits': max_index}
-
- def render(self):
- """Write out the commit data as a JSON string."""
- # We want:
- # count: total commit count
- # last_commit: string to say when the last commit was
- # commits: an array of COMMIT_DAYS values for commits for that day
- # max_commits: an index into the commits array with the most commits,
- # most recent wins any ties.
- values = {'count': 0, 'max_commits': 0}
- # Check there have been commits.
- if self.context.revision_count == 0:
- values['last_commit'] = 'empty branch'
- else:
- tip = self.context.getTipRevision()
- adapter = queryAdapter(tip.revision_date, IPathAdapter, 'fmt')
- values['last_commit'] = adapter.approximatedate()
- values.update(self._commitCounts())
-
- self.request.response.setHeader('content-type', 'application/json')
- return simplejson.dumps(values)
=== modified file 'lib/lp/code/browser/configure.zcml'
--- lib/lp/code/browser/configure.zcml 2011-06-28 11:10:51 +0000
+++ lib/lp/code/browser/configure.zcml 2011-07-21 02:35:57 +0000
@@ -657,13 +657,6 @@
class="lp.code.browser.branchvisibilitypolicy.RemoveBranchVisibilityTeamPolicyView"
permission="launchpad.Commercial"
template="../../app/templates/generic-edit.pt"/>
- <browser:page
- name="+spark"
- for="lp.code.interfaces.branch.IBranch"
- layer="lp.code.publisher.CodeLayer"
- class="lp.code.browser.branch.BranchSparkView"
- facet="branches"
- permission="zope.Public"/>
<browser:menus
classes="
BranchContextMenu
=== modified file 'lib/lp/code/browser/tests/test_branch.py'
--- lib/lp/code/browser/tests/test_branch.py 2011-05-16 03:46:33 +0000
+++ lib/lp/code/browser/tests/test_branch.py 2011-07-21 02:35:57 +0000
@@ -38,7 +38,6 @@
BranchAddView,
BranchMirrorStatusView,
BranchReviewerEditView,
- BranchSparkView,
BranchView,
)
from lp.code.browser.branchlisting import PersonOwnedBranchesView
@@ -668,94 +667,6 @@
self.assertEqual("lp://dev/fooix", decorated_branch.bzr_identity)
-class TestBranchSparkView(TestCaseWithFactory):
- """Tests for the BranchSparkView class."""
-
- layer = DatabaseFunctionalLayer
-
- def test_empty_branch(self):
- # A branch with no commits produces...
- branch = self.factory.makeAnyBranch()
- view = BranchSparkView(branch, LaunchpadTestRequest())
- json = simplejson.loads(view.render())
- self.assertEqual(0, json['count'])
- self.assertEqual('empty branch', json['last_commit'])
-
- def test_content_type(self):
- # The response has the correct (JSON) content type...
- branch = self.factory.makeAnyBranch()
- request = LaunchpadTestRequest()
- view = BranchSparkView(branch, request)
- view.render()
- self.assertEqual(
- request.response.getHeader('content-type'),
- 'application/json')
-
- def test_old_commits(self):
- # A branch with a commit older than the COMMIT_DAYS will create a list
- # of commits that all say zero.
- branch = self.factory.makeAnyBranch()
- revision = self.factory.makeRevision(
- revision_date=datetime(
- year=2008, month=9, day=10, tzinfo=pytz.UTC))
- branch.createBranchRevision(1, revision)
- branch.updateScannedDetails(revision, 1)
-
- view = BranchSparkView(branch, LaunchpadTestRequest())
- json = simplejson.loads(view.render())
-
- self.assertEqual(0, json['count'])
- self.assertEqual([0] * 90, json['commits'])
- self.assertEqual('2008-09-10', json['last_commit'])
-
- def test_last_commit_string(self):
- # If the last commit was very recent, we get a nicer string.
- branch = self.factory.makeAnyBranch()
- # Make the revision date six hours ago.
- revision_date = datetime.now(tz=pytz.UTC) - timedelta(seconds=6*3600)
- revision = self.factory.makeRevision(
- revision_date=revision_date)
- branch.createBranchRevision(1, revision)
- branch.updateScannedDetails(revision, 1)
-
- view = BranchSparkView(branch, LaunchpadTestRequest())
- json = simplejson.loads(view.render())
- self.assertEqual('6 hours ago', json['last_commit'])
-
- def test_new_commits(self):
- # If there are no commits for the day, there are zeros, if there are
- # commits, then the array contains the number of commits for that day.
- branch = self.factory.makeAnyBranch()
- # Create a commit 5 days ago.
- revision_date = datetime.now(tz=pytz.UTC) - timedelta(days=5)
- revision = self.factory.makeRevision(revision_date=revision_date)
- branch.createBranchRevision(1, revision)
- branch.updateScannedDetails(revision, 1)
-
- view = BranchSparkView(branch, LaunchpadTestRequest())
- json = simplejson.loads(view.render())
-
- self.assertEqual(1, json['count'])
- commits = ([0] * 84) + [1, 0, 0, 0, 0, 0]
- self.assertEqual(commits, json['commits'])
- self.assertEqual(84, json['max_commits'])
-
- def test_commit_for_just_now(self):
- # A commit now should show as a commit on the last day.
- branch = self.factory.makeAnyBranch()
- revision_date = datetime.now(tz=pytz.UTC)
- revision = self.factory.makeRevision(revision_date=revision_date)
- branch.createBranchRevision(1, revision)
- branch.updateScannedDetails(revision, 1)
-
- view = BranchSparkView(branch, LaunchpadTestRequest())
- json = simplejson.loads(view.render())
-
- self.assertEqual(1, json['count'])
- commits = ([0] * 89) + [1]
- self.assertEqual(commits, json['commits'])
-
-
class TestBranchProposalsVisible(TestCaseWithFactory):
"""Test that the BranchView filters out proposals the user cannot see."""