From 8d96d8b6821b56cfe62c5bce05c118ce9ddbafd1 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 8 Feb 2017 16:52:17 -0800 Subject: [PATCH] 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)