Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Commit 6029cf7

Browse files
committed
Various small fixes to make tests pass
A hodgepodge of internal API cleanup, testing vagaries, and typos. Barely worth mentioning, really.
1 parent c076639 commit 6029cf7

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

editorsnotes/api/serializers/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from rest_framework.relations import (HyperlinkedRelatedField, RelatedField,
33
get_attribute)
44
from rest_framework.reverse import reverse
5-
from rest_framework.serializers import ReadOnlyField, ModelSerializer
5+
from rest_framework.serializers import ReadOnlyField, ModelSerializer, SerializerMethodField
66

77
from editorsnotes.main.models import Topic, TopicAssignment, Project
88

@@ -79,9 +79,12 @@ def to_representation(self, value):
7979

8080
class MinimalTopicSerializer(ModelSerializer):
8181
url = URLField(lookup_arg_attrs=('project.slug', 'topic_node_id'))
82+
topic_node_id = SerializerMethodField()
8283
class Meta:
8384
model = Topic
8485
fields = ('id', 'topic_node_id', 'preferred_name', 'url',)
86+
def get_topic_node_id(self, obj):
87+
return obj.topic_node_id
8588

8689
class TopicAssignmentField(RelatedField):
8790
default_error_messages = {

editorsnotes/api/tests.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def delete_es_indexes():
4343
def create_test_topic(**kwargs):
4444
data = TEST_TOPIC.copy()
4545
data.update(kwargs)
46-
node, topic = main_models.Topic.objects.create_along_with_node(**kwargs)
46+
data.pop('alternate_names', None)
47+
data.pop('related_topics', None)
48+
node, topic = main_models.Topic.objects.create_along_with_node(**data)
4749
return topic
4850

4951

@@ -63,19 +65,21 @@ def create_test_topic(**kwargs):
6365
def create_test_document(**kwargs):
6466
data = TEST_DOCUMENT.copy()
6567
data['zotero_data'] = json.dumps(data['zotero_data'])
68+
data.pop('related_topics', None)
6669
data.update(kwargs)
67-
return main_models.Document.objects.create(**kwargs)
70+
return main_models.Document.objects.create(**data)
6871

6972
TEST_NOTE = {
7073
'title': u'Is testing good?',
71-
'related_topics': [u'Testing', u'Django'],
74+
'related_topics': [],
7275
'content': u'<p>We need to figure out if it\'s worth it to write tests.</p>',
7376
'status': 'open'
7477
}
7578
def create_test_note(**kwargs):
7679
data = TEST_NOTE.copy()
80+
data.pop('related_topics', None)
7781
data.update(kwargs)
78-
return main_models.Note.objects.create(**kwargs)
82+
return main_models.Note.objects.create(**data)
7983

8084

8185
BAD_PERMISSION_MESSAGE = u'You do not have permission to perform this action.'

editorsnotes/main/models/topics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def related_objects(self, model=None):
8484
#################################
8585

8686
class TopicManager(models.Manager):
87-
def create_along_with_node(self, preferred_name, project, user, topic_type=None,
87+
def create_along_with_node(self, preferred_name, project, user, type=None,
8888
**kwargs):
8989
"""
9090
Create a new topic node and a container with the given name.
@@ -94,7 +94,7 @@ def create_along_with_node(self, preferred_name, project, user, topic_type=None,
9494
topic_node = TopicNode.objects.create(_preferred_name=preferred_name,
9595
creator=user,
9696
last_updater=user,
97-
type=topic_type)
97+
type=type)
9898
return topic_node, self.create(topic_node_id=topic_node.id,
9999
project_id=project.id,
100100
preferred_name=preferred_name,

0 commit comments

Comments
 (0)