Ejemplo n.º 1
0
    def test_annotations(self):
        model = self.model

        u = model.User(email="*****@*****.**", password="******")
        self.persist(u)

        def persist_and_check_annotation(annotation_class, **kwds):
            annotated_association = annotation_class()
            annotated_association.annotation = "Test Annotation"
            annotated_association.user = u
            for key, value in kwds.items():
                setattr(annotated_association, key, value)
            self.persist(annotated_association)
            self.expunge()
            stored_annotation = self.query(annotation_class).all()[0]
            assert stored_annotation.annotation == "Test Annotation"
            assert stored_annotation.user.email == "*****@*****.**"

        sw = model.StoredWorkflow()
        sw.user = u
        self.persist(sw)
        persist_and_check_annotation(model.StoredWorkflowAnnotationAssociation, stored_workflow=sw)

        workflow = model.Workflow()
        workflow.stored_workflow = sw
        self.persist(workflow)

        ws = model.WorkflowStep()
        ws.workflow = workflow
        self.persist(ws)
        persist_and_check_annotation(model.WorkflowStepAnnotationAssociation, workflow_step=ws)

        h = model.History(name="History for Annotation", user=u)
        self.persist(h)
        persist_and_check_annotation(model.HistoryAnnotationAssociation, history=h)

        d1 = model.HistoryDatasetAssociation(extension="txt", history=h, create_dataset=True, sa_session=model.session)
        self.persist(d1)
        persist_and_check_annotation(model.HistoryDatasetAssociationAnnotationAssociation, hda=d1)

        page = model.Page()
        page.user = u
        self.persist(page)
        persist_and_check_annotation(model.PageAnnotationAssociation, page=page)

        visualization = model.Visualization()
        visualization.user = u
        self.persist(visualization)
        persist_and_check_annotation(model.VisualizationAnnotationAssociation, visualization=visualization)

        dataset_collection = model.DatasetCollection(collection_type="paired")
        history_dataset_collection = model.HistoryDatasetCollectionAssociation(collection=dataset_collection)
        self.persist(history_dataset_collection)
        persist_and_check_annotation(model.HistoryDatasetCollectionAssociationAnnotationAssociation, history_dataset_collection=history_dataset_collection)

        library_dataset_collection = model.LibraryDatasetCollectionAssociation(collection=dataset_collection)
        self.persist(library_dataset_collection)
        persist_and_check_annotation(model.LibraryDatasetCollectionAnnotationAssociation, library_dataset_collection=library_dataset_collection)
Ejemplo n.º 2
0
 def create(self, trans, payload=None, **kwd):
     """
     Create a new page.
     """
     if trans.request.method == 'GET':
         return {
             'title'  : 'Create a new page',
             'inputs' : [{
                 'name'      : 'title',
                 'label'     : 'Name'
             }, {
                 'name'      : 'slug',
                 'label'     : 'Identifier',
                 'help'      : 'A unique identifier that will be used for public links to this page. This field can only contain lowercase letters, numbers, and dashes (-).'
             }, {
                 'name'      : 'annotation',
                 'label'     : 'Annotation',
                 'help'      : 'A description of the page. The annotation is shown alongside published pages.'
             }]
         }
     else:
         user = trans.get_user()
         p_title = payload.get('title')
         p_slug = payload.get('slug')
         p_annotation = payload.get('annotation')
         if not p_title:
             return self.message_exception(trans, 'Please provide a page name is required.')
         elif not p_slug:
             return self.message_exception(trans, 'Please provide a unique identifier.')
         elif not self._is_valid_slug(p_slug):
             return self.message_exception(trans, 'Page identifier can only contain lowercase letters, numbers, and dashes (-).')
         elif trans.sa_session.query(model.Page).filter_by(user=user, slug=p_slug, deleted=False).first():
             return self.message_exception(trans, 'Page id must be unique.')
         else:
             # Create the new stored page
             p = model.Page()
             p.title = p_title
             p.slug = p_slug
             p.user = user
             if p_annotation:
                 p_annotation = sanitize_html(p_annotation, 'utf-8', 'text/html')
                 self.add_item_annotation(trans.sa_session, user, p, p_annotation)
             # And the first (empty) page revision
             p_revision = model.PageRevision()
             p_revision.title = p_title
             p_revision.page = p
             p.latest_revision = p_revision
             p_revision.content = ""
             # Persist
             trans.sa_session.add(p)
             trans.sa_session.flush()
         return {'message': 'Page \'%s\' successfully created.' % p.title, 'status': 'success'}
Ejemplo n.º 3
0
    def test_ratings(self):
        model = self.model

        u = model.User(email="*****@*****.**", password="******")
        self.persist(u)

        def persist_and_check_rating(rating_class, **kwds):
            rating_association = rating_class()
            rating_association.rating = 5
            rating_association.user = u
            for key, value in kwds.items():
                setattr(rating_association, key, value)
            self.persist(rating_association)
            self.expunge()
            stored_annotation = self.query(rating_class).all()[0]
            assert stored_annotation.rating == 5
            assert stored_annotation.user.email == "*****@*****.**"

        sw = model.StoredWorkflow()
        sw.user = u
        self.persist(sw)
        persist_and_check_rating(model.StoredWorkflowRatingAssociation, stored_workflow=sw)

        h = model.History(name="History for Rating", user=u)
        self.persist(h)
        persist_and_check_rating(model.HistoryRatingAssociation, history=h)

        d1 = model.HistoryDatasetAssociation(extension="txt", history=h, create_dataset=True, sa_session=model.session)
        self.persist(d1)
        persist_and_check_rating(model.HistoryDatasetAssociationRatingAssociation, hda=d1)

        page = model.Page()
        page.user = u
        self.persist(page)
        persist_and_check_rating(model.PageRatingAssociation, page=page)

        visualization = model.Visualization()
        visualization.user = u
        self.persist(visualization)
        persist_and_check_rating(model.VisualizationRatingAssociation, visualization=visualization)

        dataset_collection = model.DatasetCollection(collection_type="paired")
        history_dataset_collection = model.HistoryDatasetCollectionAssociation(collection=dataset_collection)
        self.persist(history_dataset_collection)
        persist_and_check_rating(model.HistoryDatasetCollectionRatingAssociation, history_dataset_collection=history_dataset_collection)

        library_dataset_collection = model.LibraryDatasetCollectionAssociation(collection=dataset_collection)
        self.persist(library_dataset_collection)
        persist_and_check_rating(model.LibraryDatasetCollectionRatingAssociation, library_dataset_collection=library_dataset_collection)
 def create( self, trans, page_title="", page_slug="", page_annotation="" ):
     """
     Create a new page
     """
     user = trans.get_user()
     page_title_err = page_slug_err = page_annotation_err = ""
     if trans.request.method == "POST":
         if not page_title:
             page_title_err = "Page name is required"
         elif not page_slug:
             page_slug_err = "Page id is required"
         elif not self._is_valid_slug( page_slug ):
             page_slug_err = "Page identifier must consist of only lowercase letters, numbers, and the '-' character"
         elif trans.sa_session.query( model.Page ).filter_by( user=user, slug=page_slug, deleted=False ).first():
             page_slug_err = "Page id must be unique"
         else:
             # Create the new stored page
             page = model.Page()
             page.title = page_title
             page.slug = page_slug
             page_annotation = sanitize_html( page_annotation, 'utf-8', 'text/html' )
             self.add_item_annotation( trans.sa_session, trans.get_user(), page, page_annotation )
             page.user = user
             # And the first (empty) page revision
             page_revision = model.PageRevision()
             page_revision.title = page_title
             page_revision.page = page
             page.latest_revision = page_revision
             page_revision.content = ""
             # Persist
             session = trans.sa_session
             session.add( page )
             session.flush()
             # Display the management page
             ## trans.set_message( "Page '%s' created" % page.title )
             return trans.response.send_redirect( web.url_for(controller='page', action='list' ) )
     return trans.show_form(
         web.FormBuilder( web.url_for(controller='page', action='create'), "Create new page", submit_text="Submit" )
             .add_text( "page_title", "Page title", value=page_title, error=page_title_err )
             .add_text( "page_slug", "Page identifier", value=page_slug, error=page_slug_err,
                        help="""A unique identifier that will be used for
                             public links to this page. A default is generated
                             from the page title, but can be edited. This field
                             must contain only lowercase letters, numbers, and
                             the '-' character.""" )
             .add_text( "page_annotation", "Page annotation", value=page_annotation, error=page_annotation_err,
                         help="A description of the page; annotation is shown alongside published pages."),
             template="page/create.mako" )
Ejemplo n.º 5
0
    def test_ratings(self):
        model = self.model

        user_email = "*****@*****.**"
        u = model.User(email=user_email, password="******")
        self.persist(u)

        def persist_and_check_rating(rating_class, item):
            rating = 5
            rating_association = rating_class(u, item, rating)
            self.persist(rating_association)
            self.expunge()
            stored_rating = self.query(rating_class).all()[0]
            assert stored_rating.rating == rating
            assert stored_rating.user.email == user_email

        sw = model.StoredWorkflow()
        sw.user = u
        self.persist(sw)
        persist_and_check_rating(model.StoredWorkflowRatingAssociation, sw)

        h = model.History(name="History for Rating", user=u)
        self.persist(h)
        persist_and_check_rating(model.HistoryRatingAssociation, h)

        d1 = model.HistoryDatasetAssociation(extension="txt", history=h, create_dataset=True, sa_session=model.session)
        self.persist(d1)
        persist_and_check_rating(model.HistoryDatasetAssociationRatingAssociation, d1)

        page = model.Page()
        page.user = u
        self.persist(page)
        persist_and_check_rating(model.PageRatingAssociation, page)

        visualization = model.Visualization()
        visualization.user = u
        self.persist(visualization)
        persist_and_check_rating(model.VisualizationRatingAssociation, visualization)

        dataset_collection = model.DatasetCollection(collection_type="paired")
        history_dataset_collection = model.HistoryDatasetCollectionAssociation(collection=dataset_collection)
        self.persist(history_dataset_collection)
        persist_and_check_rating(model.HistoryDatasetCollectionRatingAssociation, history_dataset_collection)

        library_dataset_collection = model.LibraryDatasetCollectionAssociation(collection=dataset_collection)
        self.persist(library_dataset_collection)
        persist_and_check_rating(model.LibraryDatasetCollectionRatingAssociation, library_dataset_collection)
Ejemplo n.º 6
0
    def test_tags(self):
        model = self.model

        my_tag = model.Tag(name="Test Tag")
        u = model.User(email="*****@*****.**", password="******")
        self.persist(my_tag, u)

        def tag_and_test(taggable_object, tag_association_class, backref_name):
            assert len(getattr(self.query(model.Tag).filter(model.Tag.name == "Test Tag").all()[0], backref_name)) == 0

            tag_association = tag_association_class()
            tag_association.tag = my_tag
            taggable_object.tags = [tag_association]
            self.persist(tag_association, taggable_object)

            assert len(getattr(self.query(model.Tag).filter(model.Tag.name == "Test Tag").all()[0], backref_name)) == 1

        sw = model.StoredWorkflow()
        sw.user = u
        tag_and_test(sw, model.StoredWorkflowTagAssociation, "tagged_workflows")

        h = model.History(name="History for Tagging", user=u)
        tag_and_test(h, model.HistoryTagAssociation, "tagged_histories")

        d1 = model.HistoryDatasetAssociation(extension="txt", history=h, create_dataset=True, sa_session=model.session)
        tag_and_test(d1, model.HistoryDatasetAssociationTagAssociation, "tagged_history_dataset_associations")

        page = model.Page()
        page.user = u
        tag_and_test(page, model.PageTagAssociation, "tagged_pages")

        visualization = model.Visualization()
        visualization.user = u
        tag_and_test(visualization, model.VisualizationTagAssociation, "tagged_visualizations")

        dataset_collection = model.DatasetCollection(collection_type="paired")
        history_dataset_collection = model.HistoryDatasetCollectionAssociation(collection=dataset_collection)
        tag_and_test(history_dataset_collection, model.HistoryDatasetCollectionTagAssociation, "tagged_history_dataset_collections")

        library_dataset_collection = model.LibraryDatasetCollectionAssociation(collection=dataset_collection)
        tag_and_test(library_dataset_collection, model.LibraryDatasetCollectionTagAssociation, "tagged_library_dataset_collections")