Skip to content
Snippets Groups Projects
Commit 9df20346 authored by Mark Skipper's avatar Mark Skipper
Browse files

WIP towards categorizing items

parent c1defccc
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('taxonomies', '0001_initial'),
('data_layer', '0002_auto_20150619_2132'),
]
operations = [
migrations.AddField(
model_name='message',
name='terms',
field=models.ManyToManyField(to='taxonomies.Term'),
),
]
from django.db import models
from taxonomies.models import Term
class DataLayerModel(models.Model):
......@@ -11,6 +12,7 @@ class DataLayerModel(models.Model):
class Message(DataLayerModel):
body = models.TextField()
timestamp = models.DateTimeField(null=True)
terms = models.ManyToManyField(Term)
def __unicode__(self):
return "{}: '{}' @{}".format(
......
from __future__ import unicode_literals, absolute_import
import pytest
from data_layer.models import Item
from .item_create_view_tests import create_item
from .taxonomy_and_term_create_tests import (
create_category,
add_term,
)
def categorize_item(**kwargs):
pass
@pytest.mark.django_db
def test_item_can_haz_category():
# Create Taxonomy for Category-scheme
category = create_category(name="Ebola Questions").data
# Add terms (Categories)
term = add_term(
taxonomy=category["slug"],
name="Vaccine",
).data
# Create an Item
item = create_item(body="Text").data
# Associate category with the item
categorize_item(
item_id=item['id'],
category=term['name'],
)
# Fetch the item
# TODO: use the API for this
[item_orm] = Item.objects.all()
# See the category
[term_orm] = item_orm.terms.all()
assert term_orm.name == 'Vaccine'
# Feel vindicated
pass # and go home happy
# TODO test for terms with the same name in different taxonomies
......@@ -9,16 +9,15 @@ from rest_framework import status
from rest_api.views import ItemViewSet
def create(item):
request = APIRequestFactory().post('/items', item)
def create_item(**kwargs):
request = APIRequestFactory().post('/items', kwargs)
view = ItemViewSet.as_view(actions={'post': 'create'})
return view(request)
@pytest.mark.django_db
def test_create_item():
item = {'body': "Text"}
response = create(item)
response = create_item(body="Text")
assert status.is_success(response.status_code)
assert response.data['body'] == "Text"
......@@ -29,8 +28,7 @@ def test_create_item_with_timestamp():
now = timezone.now().replace(
microsecond=0 # MySQL discards microseconds
)
item = {'body': "Text", 'timestamp': now}
response = create(item)
response = create_item(body="Text", timestamp=now)
assert status.is_success(response.status_code)
......@@ -135,19 +135,27 @@ it.
## '/taxonomies/<taxonomy-slug>/'
### GET
- details of the taxonomy
E.g.: `/taxonomies/ebola-questions/`.
- Taxonomy details URL should use the taxonomy's sluggified name
## '/terms/'
Get list of all terms
### GET
- list of all Terms in the Taxon
[ { "name": "Ebola Real?",
"long_name": "Is Ebola Real?"
"long_name": "Is Ebola Real?",
"taxonomy": "ebola-questions",
},
{ "name": "Timescale",
"long_name": "When will Liberia be free of Ebola?"
"taxonomy": "ebola-questions",
},
...
]
......@@ -162,12 +170,6 @@ E.g.: `/taxonomies/ebola-questions/`.
## '/taxonomies/'
### POST
- Create a new term within the given taxonomy
- Post details of a `Term` in JSON
## Taxonomies as Item metadata:
......@@ -177,6 +179,7 @@ And also to allow Item POST requests to add metadata terms.
### To create items with metadata
TODO
### /item/<item-id>/<taxonomy-id>/
......@@ -211,3 +214,84 @@ PUT [ { "name": "term" }, ... ]
- sets the values to those given, for cardinality `multiple`
- throws error for `optional`
/items/
{ body="kljlik" }
/items/67/
POST { long_name="new name!" }
POST { terms: [
{ "taxonomy": "ebola-questions",
"name": "vaccine",
},
...
]
}
/items/67/metadata/ebola-questions/
POST { "name": "health" }
POST [ { "name": "health" }]
POST []
GET /items/67/
{ id:87,
body:"lsdfkljasd",
meta: {
"ebola-questions": "vaccine",
...
}
}
{ id:87,
body:"lsdfkljasd",
meta: [
{ "taxonomy": "ebola-questions",
"name": "vaccine",
"long_name": "when will there be a vaccine"
},
...
]
}
Removing a tag from an item
/items/65/ebola-questions/vaccine
DELETE
/taxonomies/ebola-questions/vaccine/65
DELETE
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment