Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user id in aggregates #1380

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/project/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_recent_active_users(project, max_users=3):
]
return [
{
'id': user.id,
'user_id': user.id,
'name': user.get_display_name(),
'date': date,
} for user, date in recent_active_users
Expand All @@ -112,7 +112,6 @@ def get_top_entity_contributor(project, Entity):

return [
{
'id': contributor.id,
'name': contributor.member.get_display_name(),
'user_id': contributor.member.id,
'count': contributor.entity_count,
Expand Down
5 changes: 2 additions & 3 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3720,14 +3720,13 @@ enum UserEmailConditionOptOutEnum {
}

type UserEntityCountType {
id: String
name: String
userId: String
userId: String!
count: Int
}

type UserEntityDateType {
id: String!
userId: String!
name: String
date: DateTime!
}
Expand Down
42 changes: 28 additions & 14 deletions utils/graphene/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import pytz
import shutil
import inspect
import datetime
from enum import Enum
from unittest.mock import patch
Expand Down Expand Up @@ -36,17 +37,13 @@
TEST_MEDIA_ROOT = 'media-temp'


class CommonSetupClassMixin:
@classmethod
def tearDownClass(cls):
super().tearDownClass()
# clear the temporary media files
try:
# NOTE: CI will clean itself
if os.environ.get('CI', '').lower() != 'true':
shutil.rmtree(os.path.join(settings.BASE_DIR, TEST_MEDIA_ROOT), ignore_errors=True)
except FileNotFoundError:
pass
def clean_up_test_media_files():
try:
# NOTE: CI will clean itself
if os.environ.get('CI', '').lower() != 'true':
shutil.rmtree(os.path.join(settings.BASE_DIR, TEST_MEDIA_ROOT), ignore_errors=True)
except FileNotFoundError:
pass


@override_settings(
Expand All @@ -57,7 +54,7 @@ def tearDownClass(cls):
AUTH_PASSWORD_VALIDATORS=TEST_AUTH_PASSWORD_VALIDATORS,
CELERY_TASK_ALWAYS_EAGER=True,
)
class GraphQLTestCase(CommonSetupClassMixin, BaseGraphQLTestCase):
class GraphQLTestCase(BaseGraphQLTestCase):
"""
GraphQLTestCase with custom helper methods
"""
Expand All @@ -66,6 +63,12 @@ class GraphQLTestCase(CommonSetupClassMixin, BaseGraphQLTestCase):
ENABLE_NOW_PATCHER = False
PATCHER_NOW_VALUE = datetime.datetime(2021, 1, 1, 0, 0, 0, 123456, tzinfo=pytz.UTC)

@classmethod
def tearDownClass(cls):
# clear the temporary media files
clean_up_test_media_files()
super().tearDownClass()

def _setup_premailer_patcher(self, mock):
mock.get.return_value.text = ''
mock.post.return_value.text = ''
Expand Down Expand Up @@ -367,6 +370,12 @@ def setUp(self):
factory_random.reseed_random(42)
for factory in self.factories_used:
factory.reset_sequence()
# XXX: Quick hack to make sure _snapshot_file is always defined. Which seems to be missing when running in CI
# https://github.com/syrusakbary/snapshottest/blob/770b8f14cd965d923a0183a0e531e9ec0ba20192/snapshottest/unittest.py#L86
if not hasattr(self, '_snapshot_file'):
self._snapshot_file = inspect.getfile(type(self))
if not hasattr(self, '_snapshot_tests'):
self._snapshot_tests = []
super().setUp()

def tearDown(self):
Expand All @@ -380,5 +389,10 @@ def tearDown(self):
CACHES=TEST_CACHES,
AUTH_PASSWORD_VALIDATORS=TEST_AUTH_PASSWORD_VALIDATORS,
)
class CommonTestCase(CommonSetupClassMixin, TestCase):
pass
class CommonTestCase(TestCase):

@classmethod
def tearDownClass(cls):
# clear the temporary media files
clean_up_test_media_files()
super().tearDownClass()
5 changes: 2 additions & 3 deletions utils/graphene/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,12 @@ class DateCountType(graphene.ObjectType):


class UserEntityCountType(graphene.ObjectType):
id = graphene.String()
name = graphene.String()
user_id = graphene.String()
user_id = graphene.String(required=True)
count = graphene.Int()


class UserEntityDateType(graphene.ObjectType):
id = graphene.String(required=True)
user_id = graphene.String(required=True)
name = graphene.String()
date = graphene.DateTime(required=True)
Loading