Esempio n. 1
0
    def test_search_serializer_mixed_model(self):

        user = AuthUserFactory()
        project = ProjectFactory(creator=user, is_public=True)
        component = NodeFactory(parent=project, creator=user, is_public=True)
        file_component = utils.create_test_file(component, user)
        context = {'request': make_drf_request_with_version(version='2.0')}
        schema = MetaSchema.objects.filter(
            name='Replication Recipe (Brandt et al., 2013): Post-Completion',
            schema_version=LATEST_SCHEMA_VERSION).first()

        # test_search_serializer_mixed_model_project
        result = SearchSerializer(project, context=context).data
        assert result['data']['type'] == 'nodes'

        # test_search_serializer_mixed_model_component
        result = SearchSerializer(component, context=context).data
        assert result['data']['type'] == 'nodes'

        # test_search_serializer_mixed_model_registration
        with mock_archive(project,
                          autocomplete=True,
                          autoapprove=True,
                          schema=schema) as registration:
            result = SearchSerializer(registration, context=context).data
            assert result['data']['type'] == 'registrations'

        # test_search_serializer_mixed_model_file
        result = SearchSerializer(file_component, context=context).data
        assert result['data']['type'] == 'files'

        # test_search_serializer_mixed_model_user
        result = SearchSerializer(user, context=context).data
        assert result['data']['type'] == 'users'
Esempio n. 2
0
 def test_search_serializer_mixed_model_user(self):
     req = make_drf_request()
     result = SearchSerializer(self.user, context={'request': req}).data
     assert_equal(result['data']['type'], 'users')
Esempio n. 3
0
 def test_search_serializer_mixed_model_file(self):
     req = make_drf_request_with_version(version='2.0')
     result = SearchSerializer(self.file, context={'request': req}).data
     assert_equal(result['data']['type'], 'files')