Skip to content

Commit

Permalink
Merge pull request #110 from c3g/develop
Browse files Browse the repository at this point in the history
Version 0.6.0
  • Loading branch information
davidlougheed authored Apr 30, 2020
2 parents c11bcf4 + 6662eb3 commit 732bf6a
Show file tree
Hide file tree
Showing 69 changed files with 8,296 additions and 537 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
dist: bionic
language: python
python:
- "3.7"
- "3.6"
- "3.8"
addons:
postgresql: "11"
apt:
Expand Down
5 changes: 3 additions & 2 deletions chord_metadata_service/chord/api_views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from rest_framework import viewsets
from rest_framework.permissions import BasePermission, SAFE_METHODS
from rest_framework.settings import api_settings

from chord_metadata_service.restapi.api_renderers import PhenopacketsRenderer, JSONLDDatasetRenderer, RDFDatasetRenderer
from chord_metadata_service.restapi.pagination import LargeResultsSetPagination
from .models import *
from .permissions import OverrideOrSuperUserOnly
from .serializers import *
from chord_metadata_service.restapi.api_renderers import PhenopacketsRenderer, JSONLDDatasetRenderer, RDFDatasetRenderer
from rest_framework.settings import api_settings


__all__ = ["ProjectViewSet", "DatasetViewSet", "TableOwnershipViewSet"]
Expand Down
19 changes: 19 additions & 0 deletions chord_metadata_service/chord/migrations/0010_auto_20200309_1945.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.11 on 2020-03-09 19:45

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('chord', '0009_auto_20200218_1615'),
]

operations = [
migrations.AlterField(
model_name='tableownership',
name='dataset',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='table_ownership', to='chord.Dataset'),
),
]
5 changes: 3 additions & 2 deletions chord_metadata_service/chord/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
def version_default():
return f"version_{timezone.now()}"


#############################################################
# #
# Project Management #
Expand Down Expand Up @@ -121,7 +122,7 @@ def n_of_tables(self):
keywords = ArrayField(JSONField(null=True, blank=True), blank=True, null=True,
help_text="Tags associated with the dataset, which will help in its discovery.")
version = models.CharField(max_length=200, blank=True, default=version_default,
help_text="A release point for the dataset when applicable.")
help_text="A release point for the dataset when applicable.")
extra_properties = JSONField(blank=True, null=True,
help_text="Extra properties that do not fit in the previous specified attributes.")

Expand All @@ -146,7 +147,7 @@ class TableOwnership(models.Model):
data_type = models.CharField(max_length=200) # TODO: Is this needed?

# Delete table ownership upon project/dataset deletion
dataset = models.ForeignKey(Dataset, on_delete=models.CASCADE, related_name='table_ownerships')
dataset = models.ForeignKey(Dataset, on_delete=models.CASCADE, related_name='table_ownership')
# If not specified, compound table which may link to many samples TODO: ???
sample = models.ForeignKey("phenopackets.Biosample", on_delete=models.CASCADE, blank=True, null=True)

Expand Down
15 changes: 9 additions & 6 deletions chord_metadata_service/chord/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@
#############################################################


class TableOwnershipSerializer(GenericSerializer):
class Meta:
model = TableOwnership
fields = '__all__'


class DatasetSerializer(GenericSerializer):
always_include = (
"description",
"contact_info",
"linked_field_sets",
"table_ownership",
)

table_ownership = TableOwnershipSerializer(read_only=True, many=True, exclude_when_nested=["dataset"])

# noinspection PyMethodMayBeStatic
def validate_title(self, value):
if len(value.strip()) < 3:
Expand Down Expand Up @@ -140,9 +149,3 @@ def validate_title(self, value):
class Meta:
model = Project
fields = '__all__'


class TableOwnershipSerializer(GenericSerializer):
class Meta:
model = TableOwnership
fields = '__all__'
44 changes: 39 additions & 5 deletions chord_metadata_service/chord/tests/test_api_search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
from unittest.mock import Mock, patch
import uuid

from unittest.mock import patch

from django.test import override_settings
from django.urls import reverse
Expand Down Expand Up @@ -83,6 +85,15 @@ def test_table_list(self):
self.assertEqual(len(c), 1)
self.assertEqual(c[0], self.dataset_rep(self.dataset, c[0]["metadata"]["created"], c[0]["metadata"]["updated"]))

def test_table_summary(self):
r = self.client.get(reverse("table-summary", kwargs={"table_id": str(uuid.uuid4())}))
self.assertEqual(r.status_code, 404)

r = self.client.get(reverse("table-summary", kwargs={"table_id": self.dataset["identifier"]}))
s = r.json()
self.assertEqual(s["count"], 0) # No phenopackets
self.assertIn("data_type_specific", s)


class SearchTest(APITestCase):
def setUp(self) -> None:
Expand Down Expand Up @@ -182,25 +193,48 @@ def test_private_search(self):

def test_private_table_search_1(self):
# No body
r = self.client.post(reverse("table-search", args=[str(self.dataset.identifier)]))

r = self.client.post(reverse("public-table-search", args=[str(self.dataset.identifier)]))
self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST)

r = self.client.post(reverse("private-table-search", args=[str(self.dataset.identifier)]))
self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST)

def test_private_table_search_2(self):
# No query
r = self.client.post(reverse("table-search", args=[str(self.dataset.identifier)]), data=json.dumps({}),

r = self.client.post(reverse("public-table-search", args=[str(self.dataset.identifier)]), data=json.dumps({}),
content_type="application/json")
self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST)

r = self.client.post(reverse("private-table-search", args=[str(self.dataset.identifier)]), data=json.dumps({}),
content_type="application/json")
self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST)

def test_private_table_search_3(self):
# Bad syntax for query
r = self.client.post(reverse("table-search", args=[str(self.dataset.identifier)]), data=json.dumps({

r = self.client.post(reverse("public-table-search", args=[str(self.dataset.identifier)]), data=json.dumps({
"query": ["hello", "world"]
}), content_type="application/json")
self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST)

r = self.client.post(reverse("private-table-search", args=[str(self.dataset.identifier)]), data=json.dumps({
"query": ["hello", "world"]
}), content_type="application/json")
self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST)

def test_private_table_search_4(self):
# Valid query with one result
r = self.client.post(reverse("table-search", args=[str(self.dataset.identifier)]), data=json.dumps({

r = self.client.post(reverse("public-table-search", args=[str(self.dataset.identifier)]), data=json.dumps({
"query": TEST_SEARCH_QUERY_1
}), content_type="application/json")
self.assertEqual(r.status_code, status.HTTP_200_OK)
c = r.json()
self.assertEqual(c, True)

r = self.client.post(reverse("private-table-search", args=[str(self.dataset.identifier)]), data=json.dumps({
"query": TEST_SEARCH_QUERY_1
}), content_type="application/json")
self.assertEqual(r.status_code, status.HTTP_200_OK)
Expand Down
2 changes: 1 addition & 1 deletion chord_metadata_service/chord/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ def test_table_ownership(self):
self.assertEqual(t.data_type, "variant")
self.assertEqual(t.dataset, d)

self.assertIn(t, d.table_ownerships.all())
self.assertIn(t, d.table_ownership.all())

self.assertEqual(str(t), f"{str(d)} -> {t.table_id}")
Loading

0 comments on commit 732bf6a

Please sign in to comment.