Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #58 from google/staging
Browse files Browse the repository at this point in the history
2019-05-23 Merge from staging
  • Loading branch information
chief8192 authored May 23, 2019
2 parents 5f25469 + 33e93e8 commit 0b4477d
Show file tree
Hide file tree
Showing 26 changed files with 161 additions and 102 deletions.
8 changes: 7 additions & 1 deletion upvote/gae/datastore/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ py_appengine_library(
name = "test_utils",
srcs = ["test_utils.py"],
deps = [
":utils",
"//external:mock",
"//external:six",
"//upvote/gae:settings",
"//upvote/gae/datastore/models:binary",
"//upvote/gae/datastore/models:cert",
Expand All @@ -42,7 +44,10 @@ py_appengine_library(
name = "utils",
srcs = ["utils.py"],
srcs_version = "PY2AND3",
deps = ["//external:six"],
deps = [
"//external:six",
"//upvote/shared:constants",
],
)

# AppEngine Unit Tests
Expand All @@ -55,6 +60,7 @@ upvote_appengine_test(
deps = [
":utils",
"//external:mock",
"//external:six",
"//upvote/gae/lib/testing:basetest",
"@absl_git//absl/testing:absltest",
],
Expand Down
29 changes: 14 additions & 15 deletions upvote/gae/datastore/models/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ py_appengine_library(
":mixin",
":note",
":rule",
":user",
":vote",
"//upvote/gae/bigquery:tables",
"//upvote/gae/datastore:utils",
Expand Down Expand Up @@ -73,8 +72,10 @@ py_appengine_library(
py_appengine_library(
name = "event",
srcs = ["event.py"],
srcs_version = "PY2AND3",
deps = [
":mixin",
"//upvote/shared:constants",
],
)

Expand All @@ -85,7 +86,7 @@ py_appengine_library(
":mixin",
"//upvote/gae/bigquery:tables",
"//upvote/gae/lib/exemption:monitoring",
"//upvote/gae/taskqueue:utils",
"//upvote/shared:constants",
],
)

Expand All @@ -94,19 +95,17 @@ py_appengine_library(
srcs = ["host.py"],
deps = [
":mixin",
"//upvote/gae/bigquery:tables",
"//upvote/gae/utils:env_utils",
"//upvote/gae/utils:mail_utils",
"//upvote/gae/utils:template_utils",
"//upvote/shared:constants",
],
)

py_appengine_library(
name = "metrics",
srcs = ["metrics.py"],
srcs_version = "PY2AND3",
deps = [
"//upvote/gae/lib/analysis/virustotal:constants",
"//upvote/shared:constants",
],
)

Expand All @@ -123,9 +122,6 @@ py_appengine_library(
name = "note",
srcs = ["note.py"],
srcs_version = "PY2AND3",
deps = [
"//upvote/shared:constants",
],
)

py_appengine_library(
Expand All @@ -134,7 +130,6 @@ py_appengine_library(
deps = [
":binary",
":mixin",
":user",
"//upvote/gae/bigquery:tables",
"//upvote/gae/datastore:utils",
"//upvote/shared:constants",
Expand All @@ -144,6 +139,7 @@ py_appengine_library(
py_appengine_library(
name = "policy",
srcs = ["policy.py"],
srcs_version = "PY2AND3",
deps = [
":mixin",
"//upvote/shared:constants",
Expand All @@ -164,6 +160,7 @@ py_appengine_library(
py_appengine_library(
name = "singleton",
srcs = ["singleton.py"],
srcs_version = "PY2AND3",
deps = [
"//common/cloud_kms:kms_ndb",
],
Expand All @@ -174,10 +171,9 @@ py_appengine_library(
srcs = ["user.py"],
deps = [
":mixin",
"//external:six",
"//upvote/gae:settings",
"//upvote/gae/bigquery:tables",
"//upvote/gae/datastore:utils",
"//upvote/gae/taskqueue:utils",
"//upvote/gae/utils:mail_utils",
"//upvote/gae/utils:template_utils",
"//upvote/gae/utils:user_utils",
Expand All @@ -189,6 +185,7 @@ py_appengine_library(
name = "utils",
srcs = ["utils.py"],
deps = [
":binary",
":cert",
":event",
":exemption",
Expand All @@ -206,6 +203,7 @@ py_appengine_library(
name = "vote",
srcs = ["vote.py"],
deps = [
":mixin",
":user",
"//upvote/gae/datastore:utils",
"//upvote/shared:constants",
Expand Down Expand Up @@ -234,14 +232,14 @@ upvote_appengine_test(
":binary",
":cert",
":event",
":utils",
":vote",
"//common/testing:basetest",
"//external:mock",
"//upvote/gae:settings",
"//upvote/gae/bigquery:tables",
"//upvote/gae/datastore:test_utils",
"//upvote/gae/datastore:utils",
"//upvote/gae/datastore/models:utils",
"//upvote/gae/lib/testing:basetest",
"//upvote/shared:constants",
"@absl_git//absl/testing:absltest",
Expand All @@ -253,11 +251,11 @@ upvote_appengine_test(
size = "small",
srcs = ["cert_test.py"],
deps = [
":binary",
":cert",
"//external:mock",
"//upvote/gae:settings",
"//upvote/gae/datastore:test_utils",
"//upvote/gae/datastore/models:binary",
"//upvote/gae/lib/testing:basetest",
"//upvote/shared:constants",
"@absl_git//absl/testing:absltest",
Expand All @@ -270,8 +268,8 @@ upvote_appengine_test(
srcs = ["event_test.py"],
deps = [
":event",
":utils",
"//upvote/gae/datastore:test_utils",
"//upvote/gae/datastore/models:utils",
"//upvote/gae/lib/testing:basetest",
"@absl_git//absl/testing:absltest",
],
Expand Down Expand Up @@ -392,6 +390,7 @@ upvote_appengine_test(
":rule",
":utils",
"//external:mock",
"//external:six",
"//upvote/gae:settings",
"//upvote/gae/datastore:test_utils",
"//upvote/gae/datastore:utils",
Expand Down
2 changes: 1 addition & 1 deletion upvote/gae/datastore/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def DedupeMultiple(cls, events):
duped_event.Dedupe(event)
else:
distinct_events[event.key] = event
return distinct_events.values()
return list(distinct_events.values())

def to_dict(self, include=None, exclude=None): # pylint: disable=g-bad-name
result = super(Event, self).to_dict(include=include, exclude=exclude)
Expand Down
1 change: 0 additions & 1 deletion upvote/gae/datastore/models/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ def GetPlatformName(self):

def GetClientName(self):
return constants.CLIENT.SANTA

1 change: 0 additions & 1 deletion upvote/gae/datastore/models/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ class Note(polymodel.PolyModel):
def GenerateKey(cls, message, parent):
key_hash = hashlib.sha256(message).hexdigest()
return ndb.Key(Note, key_hash, parent=parent)

1 change: 0 additions & 1 deletion upvote/gae/datastore/models/note_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ def testGenerateKey(self):
key = note_models.Note.GenerateKey('fake_message', self.blockable.key)
self.assertEqual(key.parent(), self.blockable.key)
self.assertLen(key.id(), 64)

11 changes: 9 additions & 2 deletions upvote/gae/datastore/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@

"""Model definitions for Upvote users."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import datetime
import logging
import random

import six

from google.appengine.api import users
from google.appengine.ext import ndb

from upvote.gae import settings
from upvote.gae.bigquery import tables
from upvote.gae.datastore.models import mixin
Expand Down Expand Up @@ -273,7 +278,9 @@ def highest_role(self):
"""Returns the highest role for the user, by voting weight."""
role_set = set(self.roles)
for role, _ in sorted(
settings.VOTING_WEIGHTS.iteritems(), key=lambda t: t[1], reverse=True):
six.iteritems(settings.VOTING_WEIGHTS),
key=lambda t: t[1],
reverse=True):
if role in role_set:
return role

Expand Down
8 changes: 6 additions & 2 deletions upvote/gae/datastore/models/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

"""Unit tests for utils.py."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import datetime

import mock
from six.moves import range

from google.appengine.ext import ndb

from upvote.gae import settings
from upvote.gae.datastore import test_utils
from upvote.gae.datastore import utils as datastore_utils
Expand Down Expand Up @@ -353,7 +357,7 @@ def testSuccess(self):
blockable, host_id=host_id, executing_user='user2')

# Multiple Events for one user.
for _ in xrange(3):
for _ in range(3):
test_utils.CreateSantaEvent(
blockable, host_id=host_id, executing_user='user3')

Expand Down
Loading

0 comments on commit 0b4477d

Please sign in to comment.