Skip to content

Commit

Permalink
🚨 Format data_templates code with black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
znatty22 committed Jun 23, 2021
1 parent 49e2b52 commit 09d131b
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 123 deletions.
2 changes: 1 addition & 1 deletion creator/data_templates/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Meta:
"default": "foo",
"data_type": "string",
"instructions": f"Populate label_{x} properly",
"accepted_values": None
"accepted_values": None,
}
for x in range(2)
]
Expand Down
10 changes: 5 additions & 5 deletions creator/data_templates/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Meta:
null=True,
blank=True,
help_text="Name of the Font Awesome icon to use when displaying the "
"template in the frontend web application"
"template in the frontend web application",
)

@property
Expand All @@ -91,9 +91,9 @@ def released(self):
versions has been assigned to a study
"""
assigned_to_studies = (
TemplateVersion.objects
.filter(data_template__pk=self.pk)
.exclude(studies=None).count()
TemplateVersion.objects.filter(data_template__pk=self.pk)
.exclude(studies=None)
.count()
)
return assigned_to_studies > 0

Expand Down Expand Up @@ -144,7 +144,7 @@ class Meta:
)
field_definitions = JSONField(
default=dict,
help_text="The field definitions for this template version"
help_text="The field definitions for this template version",
)
data_template = models.ForeignKey(
DataTemplate,
Expand Down
24 changes: 13 additions & 11 deletions creator/data_templates/mutations/data_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class CreateDataTemplateInput(graphene.InputObjectType):
""" Parameters used when creating a new data_template """
"""Parameters used when creating a new data_template"""

name = graphene.String(
required=True, description="The name of the data_template"
Expand All @@ -23,12 +23,12 @@ class CreateDataTemplateInput(graphene.InputObjectType):
)
organization = graphene.ID(
required=True,
description="The organization that will own this data_template"
description="The organization that will own this data_template",
)


class UpdateDataTemplateInput(graphene.InputObjectType):
""" Parameters used when updating an existing data_template """
"""Parameters used when updating an existing data_template"""

name = graphene.String(description="The name of the data_template")
description = graphene.String(
Expand All @@ -44,7 +44,7 @@ class UpdateDataTemplateInput(graphene.InputObjectType):


class CreateDataTemplateMutation(graphene.Mutation):
""" Creates a new data_template """
"""Creates a new data_template"""

class Arguments:
input = CreateDataTemplateInput(
Expand Down Expand Up @@ -87,7 +87,7 @@ def mutate(self, info, input):


class UpdateDataTemplateMutation(graphene.Mutation):
""" Update an existing data_template """
"""Update an existing data_template"""

class Arguments:
id = graphene.ID(
Expand Down Expand Up @@ -116,8 +116,9 @@ def mutate(self, info, id, input):

# User may only change templates for an org they are a member of
if not (
user.organizations
.filter(pk=data_template.organization.pk).exists()
user.organizations.filter(
pk=data_template.organization.pk
).exists()
):
raise GraphQLError(
"Not allowed - may only update templates owned by an "
Expand Down Expand Up @@ -154,7 +155,7 @@ def mutate(self, info, id, input):


class DeleteDataTemplateMutation(graphene.Mutation):
""" Delete an existing data_template """
"""Delete an existing data_template"""

class Arguments:
id = graphene.ID(
Expand All @@ -181,8 +182,9 @@ def mutate(self, info, id):

# User may only delete templates for an org they are a member of
if not (
user.organizations
.filter(pk=data_template.organization.pk).exists()
user.organizations.filter(
pk=data_template.organization.pk
).exists()
):
raise GraphQLError(
"Not allowed - may only delete templates that are owned by "
Expand All @@ -202,7 +204,7 @@ def mutate(self, info, id):


class Mutation:
""" Mutations for data_templates """
"""Mutations for data_templates"""

create_data_template = CreateDataTemplateMutation.Field(
description="Create a new data_template."
Expand Down
35 changes: 19 additions & 16 deletions creator/data_templates/mutations/template_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,26 @@ def check_studies(study_node_ids):


class CreateTemplateVersionInput(graphene.InputObjectType):
""" Parameters used when creating a new template_version """
"""Parameters used when creating a new template_version"""

description = graphene.String(
required=True, description="The description of the template_version"
)
field_definitions = graphene.JSONString(
required=True,
description="The field definitions for this template"
required=True, description="The field definitions for this template"
)
data_template = graphene.ID(
required=True,
description="The data_template that this template_version belongs to"
description="The data_template that this template_version belongs to",
)
studies = graphene.List(
graphene.ID,
description="The studies this template version should be assigned to"
description="The studies this template version should be assigned to",
)


class UpdateTemplateVersionInput(graphene.InputObjectType):
""" Parameters used when updating an existing template_version """
"""Parameters used when updating an existing template_version"""

description = graphene.String(
description="The description of the template_version"
Expand All @@ -66,16 +65,17 @@ class UpdateTemplateVersionInput(graphene.InputObjectType):
)
studies = graphene.List(
graphene.ID,
description="The studies this template version should be assigned to"
description="The studies this template version should be assigned to",
)


class CreateTemplateVersionMutation(graphene.Mutation):
""" Creates a new template_version """
"""Creates a new template_version"""

class Arguments:
input = CreateTemplateVersionInput(
required=True, description="Attributes for the new template_version"
required=True,
description="Attributes for the new template_version",
)

template_version = graphene.Field(TemplateVersionNode)
Expand Down Expand Up @@ -128,11 +128,12 @@ def mutate(self, info, input):


class UpdateTemplateVersionMutation(graphene.Mutation):
""" Update an existing template_version """
"""Update an existing template_version"""

class Arguments:
id = graphene.ID(
required=True, description="The ID of the template_version to update"
required=True,
description="The ID of the template_version to update",
)
input = UpdateTemplateVersionInput(
required=True, description="Attributes for the template_version"
Expand Down Expand Up @@ -196,11 +197,12 @@ def mutate(self, info, id, input):


class DeleteTemplateVersionMutation(graphene.Mutation):
""" Delete an existing template_version """
"""Delete an existing template_version"""

class Arguments:
id = graphene.ID(
required=True, description="The ID of the template_version to delete"
required=True,
description="The ID of the template_version to delete",
)

success = graphene.Boolean()
Expand All @@ -223,8 +225,9 @@ def mutate(self, info, id):

# User may only delete templates for an org they are a member of
if not (
user.organizations
.filter(pk=template_version.organization.pk).exists()
user.organizations.filter(
pk=template_version.organization.pk
).exists()
):
raise GraphQLError(
"Not allowed - may only delete templates that are owned by "
Expand All @@ -244,7 +247,7 @@ def mutate(self, info, id):


class Mutation:
""" Mutations for template_versions """
"""Mutations for template_versions"""

create_template_version = CreateTemplateVersionMutation.Field(
description="Create a new template_version."
Expand Down
4 changes: 1 addition & 3 deletions creator/data_templates/nodes/data_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ def get_node(cls, info, id):
try:
data_template = cls._meta.model.objects.get(id=id)
except cls._meta.model.DoesNotExist:
raise GraphQLError(
f"DataTemplate {id} does not exist"
)
raise GraphQLError(f"DataTemplate {id} does not exist")

return data_template
4 changes: 1 addition & 3 deletions creator/data_templates/nodes/template_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ def get_node(cls, info, id):
try:
template_version = cls._meta.model.objects.get(id=id)
except cls._meta.model.DoesNotExist:
raise GraphQLError(
f"TemplateVersion {id} does not exist"
)
raise GraphQLError(f"TemplateVersion {id} does not exist")

return template_version
8 changes: 4 additions & 4 deletions creator/data_templates/schema.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import graphene

from creator.data_templates.queries.data_template import (
Query as DataTemplateQuery
Query as DataTemplateQuery,
)
from creator.data_templates.mutations.data_template import (
Mutation as DataTemplateMutation
Mutation as DataTemplateMutation,
)
from creator.data_templates.queries.template_version import (
Query as TemplateVersionQuery
Query as TemplateVersionQuery,
)
from creator.data_templates.mutations.template_version import (
Mutation as TemplateVersionMutation
Mutation as TemplateVersionMutation,
)


Expand Down
39 changes: 9 additions & 30 deletions tests/data_templates/test_data_templates_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ def test_create_data_template(db, permission_client, permissions, allowed):
}
resp = client.post(
"/graphql",
data={
"query": CREATE_DATA_TEMPLATE,
"variables": variables
},
data={"query": CREATE_DATA_TEMPLATE, "variables": variables},
content_type="application/json",
)

Expand Down Expand Up @@ -115,10 +112,7 @@ def test_create_data_template_missing_org(db, permission_client):
}
resp = client.post(
"/graphql",
data={
"query": CREATE_DATA_TEMPLATE,
"variables": variables
},
data={"query": CREATE_DATA_TEMPLATE, "variables": variables},
content_type="application/json",
)
assert f"{org_id} does not exist" in resp.json()["errors"][0]["message"]
Expand All @@ -142,10 +136,7 @@ def test_create_data_template_not_my_org(db, permission_client):
}
resp = client.post(
"/graphql",
data={
"query": CREATE_DATA_TEMPLATE,
"variables": variables
},
data={"query": CREATE_DATA_TEMPLATE, "variables": variables},
content_type="application/json",
)
assert f"Not allowed" in resp.json()["errors"][0]["message"]
Expand Down Expand Up @@ -375,18 +366,14 @@ def test_delete_data_template(db, permission_client, permissions, allowed):
data={
"query": DELETE_DATA_TEMPLATE,
"variables": {
"id": to_global_id(
"DataTemplateNode}}", data_template.id
),
"id": to_global_id("DataTemplateNode}}", data_template.id),
},
},
content_type="application/json",
)

if allowed:
resp_dt = (
resp.json()["data"]["deleteDataTemplate"]["id"]
)
resp_dt = resp.json()["data"]["deleteDataTemplate"]["id"]
assert resp_dt is not None
with pytest.raises(DataTemplate.DoesNotExist):
DataTemplate.objects.get(id=data_template.id)
Expand Down Expand Up @@ -420,9 +407,7 @@ def test_delete_data_template_does_not_exist(db, permission_client):
assert DataTemplate.objects.count() == 1


def test_delete_data_template_not_my_org(
db, permission_client
):
def test_delete_data_template_not_my_org(db, permission_client):
"""
Test the delete data template for an org user is not a member of
"""
Expand All @@ -441,9 +426,7 @@ def test_delete_data_template_not_my_org(
data={
"query": DELETE_DATA_TEMPLATE,
"variables": {
"id": to_global_id(
"DataTemplateNode}}", data_template.id
),
"id": to_global_id("DataTemplateNode}}", data_template.id),
},
},
content_type="application/json",
Expand All @@ -466,9 +449,7 @@ def test_delete_released_data_template(db, permission_client):
# Create template in organization that user is member of
# with a template version assigned to some studies
data_template = DataTemplateFactory(organization=org)
tv = TemplateVersionFactory(
data_template=data_template, studies=studies
)
tv = TemplateVersionFactory(data_template=data_template, studies=studies)
tv.refresh_from_db()

assert DataTemplate.objects.count() == 1
Expand All @@ -477,9 +458,7 @@ def test_delete_released_data_template(db, permission_client):
data={
"query": DELETE_DATA_TEMPLATE,
"variables": {
"id": to_global_id(
"DataTemplateNode}}", data_template.id
),
"id": to_global_id("DataTemplateNode}}", data_template.id),
},
},
content_type="application/json",
Expand Down
Loading

0 comments on commit 09d131b

Please sign in to comment.