@@ -0,0 +1,2592 @@
+from nose.tools import *  # flake8: noqa%0Aimport functools%0A%0Afrom framework.auth.core import Auth%0A%0Afrom api.base.settings.defaults import API_BASE%0Afrom tests.base import ApiTestCase%0Afrom tests.factories import (%0A    ProjectFactory,%0A    AuthUserFactory,%0A    RegistrationFactory%0A)%0A%0Aclass TestRegistrationEmbeds(ApiTestCase):%0A%0A    def setUp(self):%0A        super(TestRegistrationEmbeds, self).setUp()%0A%0A        self.user = AuthUserFactory()%0A        self.auth = Auth(self.user)%0A        make_public_node = functools.partial(ProjectFactory, is_public=False, creator=self.user)%0A        self.root_node = make_public_node()%0A        self.child1 = make_public_node(parent=self.root_node)%0A        self.child2 = make_public_node(parent=self.root_node)%0A%0A        self.contribs = %5BAuthUserFactory() for i in range(2)%5D%0A        for contrib in self.contribs:%0A            self.root_node.add_contributor(contrib, %5B'read', 'write'%5D, auth=self.auth, save=True)%0A            self.child1.add_contributor(contrib, %5B'read', 'write'%5D, auth=self.auth, save=True)%0A%0A        self.contrib1 = self.contribs%5B0%5D%0A        self.contrib2 = self.contribs%5B1%5D%0A        self.subchild = ProjectFactory(parent=self.child2, creator=self.contrib1)%0A%0A        self.registration = RegistrationFactory(project=self.root_node, is_public=True)%0A        self.registration_child = RegistrationFactory(project=self.child1, is_public=True)%0A%0A    def test_embed_children(self):%0A        url = '/%7B0%7Dregistrations/%7B1%7D/?embed=children'.format(API_BASE, self.registration._id)%0A%0A        res = self.app.get(url, auth=self.user.auth)%0A        embeds = res.json%5B'data'%5D%5B'embeds'%5D%0A        assert_equal(len(embeds%5B'children'%5D%5B'data'%5D), 2)%0A        titles = %5Bself.child1.title, self.child2.title%5D%0A        for child in embeds%5B'children'%5D%5B'data'%5D:%0A            assert_in(child%5B'attributes'%5D%5B'title'%5D, titles)%0A%0A    def test_embed_contributors(self):%0A        url = '/%7B0%7Dregistrations/%7B1%7D/?embed=contributors'.format(API_BASE, self.registration._id)%0A%0A        res = self.app.get(url, auth=self.user.auth)%0A        embeds = res.json%5B'data'%5D%5B'embeds'%5D%0A        ids = %5Bc._id for c in self.contribs%5D + %5Bself.user._id%5D%0A        for contrib in embeds%5B'contributors'%5D%5B'data'%5D:%0A            assert_in(contrib%5B'id'%5D, ids)%0A%0A    def test_embed_attributes_not_relationships(self):%0A        url = '/%7B%7Dregistrations/%7B%7D/?embed=title'.format(API_BASE, self.registration._id)%0A%0A        res = self.app.get(url, auth=self.contrib1.auth, expect_errors=True)%0A        assert_equal(res.status_code, 400)%0A        assert_equal(res.json%5B'errors'%5D%5B0%5D%5B'detail'%5D, %22The following fields are not embeddable: title%22)%0A%0A%0A

Add a couple registrations embeds tests.