From 8d96d8b6821b56cfe62c5bce05c118ce9ddbafd1 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 8 Feb 2017 16:52:17 -0800 Subject: [PATCH 1/2] Add tests for missing logs APIs --- endpoints/api/logs.py | 2 +- test/test_api_usage.py | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/endpoints/api/logs.py b/endpoints/api/logs.py index 05d340d20..8722ad298 100644 --- a/endpoints/api/logs.py +++ b/endpoints/api/logs.py @@ -9,7 +9,7 @@ from endpoints.api import (resource, nickname, ApiResource, query_param, parse_a RepositoryParamResource, require_repo_admin, related_user_resource, format_date, require_user_admin, path_param, require_scope, page_support) from endpoints.exception import Unauthorized, NotFound -from auth.permissions import AdministerOrganizationPermission, AdministerOrganizationPermission +from auth.permissions import AdministerOrganizationPermission from auth.auth_context import get_authenticated_user from data import model, database from auth import scopes diff --git a/test/test_api_usage.py b/test/test_api_usage.py index 6f237744f..d5c738e59 100644 --- a/test/test_api_usage.py +++ b/test/test_api_usage.py @@ -51,7 +51,8 @@ from endpoints.api.user import (PrivateRepositories, ConvertToOrganization, Sign from endpoints.api.repotoken import RepositoryToken, RepositoryTokenList from endpoints.api.prototype import PermissionPrototype, PermissionPrototypeList -from endpoints.api.logs import UserLogs, OrgLogs, OrgAggregateLogs, UserAggregateLogs +from endpoints.api.logs import (UserLogs, OrgLogs, OrgAggregateLogs, UserAggregateLogs, + RepositoryLogs, RepositoryAggregateLogs) from endpoints.api.billing import (UserCard, UserPlan, ListPlans, OrganizationCard, OrganizationPlan) from endpoints.api.discovery import DiscoveryResource @@ -3551,6 +3552,30 @@ class TestOrgRobots(ApiTestCase): class TestLogs(ApiTestCase): + def test_repo_logs(self): + self.login(ADMIN_ACCESS_USER) + + json = self.getJsonResponse(RepositoryLogs, params=dict(repository='devtable/simple')) + assert 'logs' in json + assert 'start_time' in json + assert 'end_time' in json + + def test_repo_logs_crossyear(self): + self.login(ADMIN_ACCESS_USER) + + json = self.getJsonResponse(RepositoryLogs, params=dict(repository='devtable/simple', + starttime='12/01/2016', + endtime='1/09/2017')) + self.assertEquals('Thu, 01 Dec 2016 00:00:00 -0000', json['start_time']) + self.assertEquals('Tue, 10 Jan 2017 00:00:00 -0000', json['end_time']) + + def test_repo_aggregate_logs(self): + self.login(ADMIN_ACCESS_USER) + + json = self.getJsonResponse(RepositoryAggregateLogs, params=dict(repository='devtable/simple')) + assert 'aggregated' in json + assert len(json['aggregated']) > 0 + def test_user_logs(self): self.login(ADMIN_ACCESS_USER) From f569cea4b39e747fe70e9593d8aac8907e3385b7 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 8 Feb 2017 17:18:37 -0800 Subject: [PATCH 2/2] Fix logs graphs tooltips for months < 10 Fixes #2342 --- static/js/graphing.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/static/js/graphing.js b/static/js/graphing.js index 4ed68ab16..ec62ac378 100644 --- a/static/js/graphing.js +++ b/static/js/graphing.js @@ -1126,12 +1126,10 @@ LogUsageChart.prototype.buildData_ = function(aggregatedLogs) { var title = this.titleMap_[aggregated.kind] || aggregated.kind; var datetime = parseDate(aggregated.datetime); - var day = datetime.getDate(); - if (day < 10) { - day = '0' + day; - } + var day = ('0' + datetime.getDate()).slice(-2); + var month = ('0' + (datetime.getMonth() + 1)).slice(-2); - var formatted = (datetime.getMonth() + 1) + '/' + day; + var formatted = month + '/' + day; var justdate = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate()); var key = title + '_' + formatted; var entry = {