2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/1b78bcbb1bc2/ Changeset: 1b78bcbb1bc2 User: jmchilton Date: 2013-12-11 16:55:54 Summary: Add some higher-level methods to mapping unit test. Affected #: 1 file diff -r df88d6121d48b0b193d34445ce49916adf17a2d2 -r 1b78bcbb1bc2bc0f39149726855418ccc890a3ff test/unit/test_galaxy_mapping.py --- a/test/unit/test_galaxy_mapping.py +++ b/test/unit/test_galaxy_mapping.py @@ -3,10 +3,10 @@ class MappingTests( unittest.TestCase ): + def test_basic( self ): - # Start the database and connect the mapping - model = mapping.init( "/tmp", "sqlite:///:memory:", create_tables=True ) - assert model.engine is not None + model = self.model + # Make some changes and commit them u = model.User( email="james@foo.bar.baz", password="password" ) # gs = model.GalaxySession() @@ -14,15 +14,14 @@ #h1.queries.append( model.Query( "h1->q1" ) ) #h1.queries.append( model.Query( "h1->q2" ) ) h2 = model.History( name=( "H" * 1024 ) ) - model.session.add_all( ( u, h1, h2 ) ) + self.persist( u, h1, h2 ) #q1 = model.Query( "h2->q1" ) metadata = dict( chromCol=1, startCol=2, endCol=3 ) d1 = model.HistoryDatasetAssociation( extension="interval", metadata=metadata, history=h2, create_dataset=True, sa_session=model.session ) #h2.queries.append( q1 ) #h2.queries.append( model.Query( "h2->q2" ) ) - model.session.add( ( d1 ) ) - model.session.flush() - model.session.expunge_all() + self.persist( d1 ) + # Check users = model.session.query( model.User ).all() assert len( users ) == 1 @@ -41,13 +40,33 @@ #assert hists[1].datasets[0].file_name == os.path.join( "/tmp", *directory_hash_id( id ) ) + ( "/dataset_%d.dat" % id ) # Do an update and check hists[1].name = "History 2b" - model.session.flush() - model.session.expunge_all() + self.expunge() hists = model.session.query( model.History ).all() assert hists[0].name == "History 1" assert hists[1].name == "History 2b" # gvk TODO need to ad test for GalaxySessions, but not yet sure what they should look like. + @classmethod + def setUpClass(cls): + # Start the database and connect the mapping + cls.model = mapping.init( "/tmp", "sqlite:///:memory:", create_tables=True ) + assert cls.model.engine is not None + + @classmethod + def query( cls, type ): + return cls.model.session.query( type ) + + @classmethod + def persist(cls, *args): + for arg in args: + cls.model.session.add( arg ) + cls.expunge() + + @classmethod + def expunge(cls): + cls.model.session.flush() + cls.model.session.expunge_all() + def get_suite(): suite = unittest.TestSuite() https://bitbucket.org/galaxy/galaxy-central/commits/35ae5ce8be84/ Changeset: 35ae5ce8be84 User: jmchilton Date: 2013-12-11 16:55:54 Summary: Higher-level abstractions for defining annotation, tag, and rating mappings... ... as well unit tests. Affected #: 2 files diff -r 1b78bcbb1bc2bc0f39149726855418ccc890a3ff -r 35ae5ce8be84dcccadaf58c9b569fb9cf9daccbf lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py +++ b/lib/galaxy/model/mapping.py @@ -1050,8 +1050,11 @@ Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), Column( "key", TrimmedString( 32 ), index=True, unique=True ) ) + # With the tables defined we can define the mappers and setup the # relationships between the model objects. +def simple_mapping( model, **kwds ): + mapper( model, model.table, properties=kwds ) mapper( model.Sample, model.Sample.table, @@ -1200,64 +1203,62 @@ mapper( model.ValidationError, model.ValidationError.table ) -mapper( model.HistoryDatasetAssociation, model.HistoryDatasetAssociation.table, - properties=dict( - dataset=relation( - model.Dataset, - primaryjoin=( model.Dataset.table.c.id == model.HistoryDatasetAssociation.table.c.dataset_id ), lazy=False ), - # .history defined in History mapper - copied_from_history_dataset_association=relation( - model.HistoryDatasetAssociation, - primaryjoin=( model.HistoryDatasetAssociation.table.c.copied_from_history_dataset_association_id == model.HistoryDatasetAssociation.table.c.id ), - remote_side=[model.HistoryDatasetAssociation.table.c.id], - uselist=False ), - copied_to_history_dataset_associations=relation( - model.HistoryDatasetAssociation, - primaryjoin=( model.HistoryDatasetAssociation.table.c.copied_from_history_dataset_association_id == model.HistoryDatasetAssociation.table.c.id ) ), - copied_from_library_dataset_dataset_association=relation( - model.LibraryDatasetDatasetAssociation, - primaryjoin=( model.HistoryDatasetAssociation.table.c.copied_from_library_dataset_dataset_association_id == model.LibraryDatasetDatasetAssociation.table.c.id ), - uselist=False ), - copied_to_library_dataset_dataset_associations=relation( - model.LibraryDatasetDatasetAssociation, - primaryjoin=( model.HistoryDatasetAssociation.table.c.copied_from_library_dataset_dataset_association_id == model.LibraryDatasetDatasetAssociation.table.c.id ) ), - implicitly_converted_datasets=relation( - model.ImplicitlyConvertedDatasetAssociation, - primaryjoin=( model.ImplicitlyConvertedDatasetAssociation.table.c.hda_parent_id == model.HistoryDatasetAssociation.table.c.id ) ), - implicitly_converted_parent_datasets=relation( - model.ImplicitlyConvertedDatasetAssociation, - primaryjoin=( model.ImplicitlyConvertedDatasetAssociation.table.c.hda_id == model.HistoryDatasetAssociation.table.c.id ) ), - children=relation( - model.HistoryDatasetAssociation, - primaryjoin=( model.HistoryDatasetAssociation.table.c.parent_id == model.HistoryDatasetAssociation.table.c.id ), - backref=backref( "parent", primaryjoin=( model.HistoryDatasetAssociation.table.c.parent_id == model.HistoryDatasetAssociation.table.c.id ), remote_side=[model.HistoryDatasetAssociation.table.c.id], uselist=False ) ), - visible_children=relation( - model.HistoryDatasetAssociation, - primaryjoin=( ( model.HistoryDatasetAssociation.table.c.parent_id == model.HistoryDatasetAssociation.table.c.id ) & ( model.HistoryDatasetAssociation.table.c.visible == True ) ) ), - tags=relation( model.HistoryDatasetAssociationTagAssociation, order_by=model.HistoryDatasetAssociationTagAssociation.table.c.id, backref='history_tag_associations' ), - annotations=relation( model.HistoryDatasetAssociationAnnotationAssociation, order_by=model.HistoryDatasetAssociationAnnotationAssociation.table.c.id, backref="hdas" ), - ratings=relation( model.HistoryDatasetAssociationRatingAssociation, order_by=model.HistoryDatasetAssociationRatingAssociation.table.c.id, backref="hdas" ) ) - ) +simple_mapping( model.HistoryDatasetAssociation, + dataset=relation( + model.Dataset, + primaryjoin=( model.Dataset.table.c.id == model.HistoryDatasetAssociation.table.c.dataset_id ), lazy=False ), + # .history defined in History mapper + copied_from_history_dataset_association=relation( + model.HistoryDatasetAssociation, + primaryjoin=( model.HistoryDatasetAssociation.table.c.copied_from_history_dataset_association_id == model.HistoryDatasetAssociation.table.c.id ), + remote_side=[model.HistoryDatasetAssociation.table.c.id], + uselist=False ), + copied_to_history_dataset_associations=relation( + model.HistoryDatasetAssociation, + primaryjoin=( model.HistoryDatasetAssociation.table.c.copied_from_history_dataset_association_id == model.HistoryDatasetAssociation.table.c.id ) ), + copied_from_library_dataset_dataset_association=relation( + model.LibraryDatasetDatasetAssociation, + primaryjoin=( model.HistoryDatasetAssociation.table.c.copied_from_library_dataset_dataset_association_id == model.LibraryDatasetDatasetAssociation.table.c.id ), + uselist=False ), + copied_to_library_dataset_dataset_associations=relation( + model.LibraryDatasetDatasetAssociation, + primaryjoin=( model.HistoryDatasetAssociation.table.c.copied_from_library_dataset_dataset_association_id == model.LibraryDatasetDatasetAssociation.table.c.id ) ), + implicitly_converted_datasets=relation( + model.ImplicitlyConvertedDatasetAssociation, + primaryjoin=( model.ImplicitlyConvertedDatasetAssociation.table.c.hda_parent_id == model.HistoryDatasetAssociation.table.c.id ) ), + implicitly_converted_parent_datasets=relation( + model.ImplicitlyConvertedDatasetAssociation, + primaryjoin=( model.ImplicitlyConvertedDatasetAssociation.table.c.hda_id == model.HistoryDatasetAssociation.table.c.id ) ), + children=relation( + model.HistoryDatasetAssociation, + primaryjoin=( model.HistoryDatasetAssociation.table.c.parent_id == model.HistoryDatasetAssociation.table.c.id ), + backref=backref( "parent", primaryjoin=( model.HistoryDatasetAssociation.table.c.parent_id == model.HistoryDatasetAssociation.table.c.id ), remote_side=[model.HistoryDatasetAssociation.table.c.id], uselist=False ) ), + visible_children=relation( + model.HistoryDatasetAssociation, + primaryjoin=( ( model.HistoryDatasetAssociation.table.c.parent_id == model.HistoryDatasetAssociation.table.c.id ) & ( model.HistoryDatasetAssociation.table.c.visible == True ) ) ), + tags=relation( model.HistoryDatasetAssociationTagAssociation, order_by=model.HistoryDatasetAssociationTagAssociation.table.c.id, backref='history_tag_associations' ), + annotations=relation( model.HistoryDatasetAssociationAnnotationAssociation, order_by=model.HistoryDatasetAssociationAnnotationAssociation.table.c.id, backref="hdas" ), + ratings=relation( model.HistoryDatasetAssociationRatingAssociation, order_by=model.HistoryDatasetAssociationRatingAssociation.table.c.id, backref="hdas" ) +) -mapper( model.Dataset, model.Dataset.table, - properties=dict( - history_associations=relation( - model.HistoryDatasetAssociation, - primaryjoin=( model.Dataset.table.c.id == model.HistoryDatasetAssociation.table.c.dataset_id ) ), - active_history_associations=relation( - model.HistoryDatasetAssociation, - primaryjoin=( ( model.Dataset.table.c.id == model.HistoryDatasetAssociation.table.c.dataset_id ) & ( model.HistoryDatasetAssociation.table.c.deleted == False ) & ( model.HistoryDatasetAssociation.table.c.purged == False ) ) ), - purged_history_associations=relation( - model.HistoryDatasetAssociation, - primaryjoin=( ( model.Dataset.table.c.id == model.HistoryDatasetAssociation.table.c.dataset_id ) & ( model.HistoryDatasetAssociation.table.c.purged == True ) ) ), - library_associations=relation( - model.LibraryDatasetDatasetAssociation, - primaryjoin=( model.Dataset.table.c.id == model.LibraryDatasetDatasetAssociation.table.c.dataset_id ) ), - active_library_associations=relation( - model.LibraryDatasetDatasetAssociation, - primaryjoin=( ( model.Dataset.table.c.id == model.LibraryDatasetDatasetAssociation.table.c.dataset_id ) & ( model.LibraryDatasetDatasetAssociation.table.c.deleted == False ) ) ), - tags=relation(model.DatasetTagAssociation, order_by=model.DatasetTagAssociation.table.c.id, backref='datasets') - ) ) +simple_mapping( model.Dataset, + history_associations=relation( + model.HistoryDatasetAssociation, + primaryjoin=( model.Dataset.table.c.id == model.HistoryDatasetAssociation.table.c.dataset_id ) ), + active_history_associations=relation( + model.HistoryDatasetAssociation, + primaryjoin=( ( model.Dataset.table.c.id == model.HistoryDatasetAssociation.table.c.dataset_id ) & ( model.HistoryDatasetAssociation.table.c.deleted == False ) & ( model.HistoryDatasetAssociation.table.c.purged == False ) ) ), + purged_history_associations=relation( + model.HistoryDatasetAssociation, + primaryjoin=( ( model.Dataset.table.c.id == model.HistoryDatasetAssociation.table.c.dataset_id ) & ( model.HistoryDatasetAssociation.table.c.purged == True ) ) ), + library_associations=relation( + model.LibraryDatasetDatasetAssociation, + primaryjoin=( model.Dataset.table.c.id == model.LibraryDatasetDatasetAssociation.table.c.dataset_id ) ), + active_library_associations=relation( + model.LibraryDatasetDatasetAssociation, + primaryjoin=( ( model.Dataset.table.c.id == model.LibraryDatasetDatasetAssociation.table.c.dataset_id ) & ( model.LibraryDatasetDatasetAssociation.table.c.deleted == False ) ) ), + tags=relation(model.DatasetTagAssociation, order_by=model.DatasetTagAssociation.table.c.id, backref='datasets') +) mapper( model.HistoryDatasetAssociationDisplayAtAuthorization, model.HistoryDatasetAssociationDisplayAtAuthorization.table, properties=dict( history_dataset_association = relation( model.HistoryDatasetAssociation ), @@ -1751,90 +1752,63 @@ ) ) # Tag tables. +simple_mapping( model.Tag, + children=relation(model.Tag, backref=backref( 'parent', remote_side=[model.Tag.table.c.id] ) ) +) -mapper( model.Tag, model.Tag.table, - properties=dict( children=relation(model.Tag, backref=backref( 'parent', remote_side=[model.Tag.table.c.id] ) ) - ) ) -mapper( model.HistoryTagAssociation, model.HistoryTagAssociation.table, - properties=dict( tag=relation(model.Tag, backref="tagged_histories"), user=relation( model.User ) ) - ) +def tag_mapping( tag_association_class, backref_name ): + simple_mapping( tag_association_class, tag=relation( model.Tag, backref=backref_name), user=relation( model.User ) ) -mapper( model.DatasetTagAssociation, model.DatasetTagAssociation.table, - properties=dict( tag=relation(model.Tag, backref="tagged_datasets"), user=relation( model.User ) ) - ) +tag_mapping( model.HistoryTagAssociation, "tagged_histories" ) -mapper( model.HistoryDatasetAssociationTagAssociation, model.HistoryDatasetAssociationTagAssociation.table, - properties=dict( tag=relation(model.Tag, backref="tagged_history_dataset_associations"), user=relation( model.User ) ) - ) +tag_mapping( model.DatasetTagAssociation, "tagged_datasets" ) -mapper( model.PageTagAssociation, model.PageTagAssociation.table, - properties=dict( tag=relation(model.Tag, backref="tagged_pages"), user=relation( model.User ) ) - ) +tag_mapping( model.HistoryDatasetAssociationTagAssociation, "tagged_history_dataset_associations" ) -mapper( model.StoredWorkflowTagAssociation, model.StoredWorkflowTagAssociation.table, - properties=dict( tag=relation(model.Tag, backref="tagged_workflows"), user=relation( model.User ) ) - ) +tag_mapping( model.PageTagAssociation, "tagged_pages" ) -mapper( model.WorkflowStepTagAssociation, model.WorkflowStepTagAssociation.table, - properties=dict( tag=relation(model.Tag, backref="tagged_workflow_steps"), user=relation( model.User ) ) - ) +tag_mapping( model.StoredWorkflowTagAssociation, "tagged_workflows" ) -mapper( model.VisualizationTagAssociation, model.VisualizationTagAssociation.table, - properties=dict( tag=relation(model.Tag, backref="tagged_visualizations"), user=relation( model.User ) ) - ) +tag_mapping( model.WorkflowStepTagAssociation, "tagged_workflow_steps" ) -mapper( model.ToolTagAssociation, model.ToolTagAssociation.table, - properties=dict( tag=relation(model.Tag, backref="tagged_tools"), user=relation( model.User ) ) - ) +tag_mapping( model.VisualizationTagAssociation, "tagged_visualizations" ) + +tag_mapping( model.ToolTagAssociation, "tagged_tools" ) + # Annotation tables. +def annotation_mapping( annotation_class, **kwds ): + kwds = dict( [ (key, relation( value ) ) for key, value in kwds.iteritems() ] ) + simple_mapping( annotation_class, **dict(user=relation( model.User ), **kwds ) ) -mapper( model.HistoryAnnotationAssociation, model.HistoryAnnotationAssociation.table, - properties=dict( history=relation( model.History ), user=relation( model.User ) ) - ) +annotation_mapping( model.HistoryAnnotationAssociation, history=model.History ) -mapper( model.HistoryDatasetAssociationAnnotationAssociation, model.HistoryDatasetAssociationAnnotationAssociation.table, - properties=dict( hda=relation( model.HistoryDatasetAssociation ), user=relation( model.User ) ) - ) +annotation_mapping( model.HistoryDatasetAssociationAnnotationAssociation, hda=model.HistoryDatasetAssociation ) -mapper( model.StoredWorkflowAnnotationAssociation, model.StoredWorkflowAnnotationAssociation.table, - properties=dict( stored_workflow=relation( model.StoredWorkflow ), user=relation( model.User ) ) - ) +annotation_mapping( model.StoredWorkflowAnnotationAssociation, stored_workflow=model.StoredWorkflow ) -mapper( model.WorkflowStepAnnotationAssociation, model.WorkflowStepAnnotationAssociation.table, - properties=dict( workflow_step=relation( model.WorkflowStep ), user=relation( model.User ) ) - ) +annotation_mapping( model.WorkflowStepAnnotationAssociation, workflow_step=model.WorkflowStep ) -mapper( model.PageAnnotationAssociation, model.PageAnnotationAssociation.table, - properties=dict( page=relation( model.Page ), user=relation( model.User ) ) - ) +annotation_mapping( model.PageAnnotationAssociation, page=model.Page ) -mapper( model.VisualizationAnnotationAssociation, model.VisualizationAnnotationAssociation.table, - properties=dict( visualization=relation( model.Visualization ), user=relation( model.User ) ) - ) +annotation_mapping( model.VisualizationAnnotationAssociation, visualization=model.Visualization ) + # Rating tables. +def rating_mapping( rating_class, **kwds ): + kwds = dict( [ (key, relation( value ) ) for key, value in kwds.iteritems() ] ) + simple_mapping( rating_class, **dict(user=relation( model.User ), **kwds ) ) -mapper( model.HistoryRatingAssociation, model.HistoryRatingAssociation.table, - properties=dict( history=relation( model.History ), user=relation( model.User ) ) - ) +rating_mapping( model.HistoryRatingAssociation, history=model.History ) -mapper( model.HistoryDatasetAssociationRatingAssociation, model.HistoryDatasetAssociationRatingAssociation.table, - properties=dict( hda=relation( model.HistoryDatasetAssociation ), user=relation( model.User ) ) - ) +rating_mapping( model.HistoryDatasetAssociationRatingAssociation, hda=model.HistoryDatasetAssociation ) -mapper( model.StoredWorkflowRatingAssociation, model.StoredWorkflowRatingAssociation.table, - properties=dict( stored_workflow=relation( model.StoredWorkflow ), user=relation( model.User ) ) - ) +rating_mapping( model.StoredWorkflowRatingAssociation, stored_workflow=model.StoredWorkflow ) -mapper( model.PageRatingAssociation, model.PageRatingAssociation.table, - properties=dict( page=relation( model.Page ), user=relation( model.User ) ) - ) +rating_mapping( model.PageRatingAssociation, page=model.Page ) -mapper( model.VisualizationRatingAssociation, model.VisualizationRatingAssociation.table, - properties=dict( visualization=relation( model.Visualization ), user=relation( model.User ) ) - ) +rating_mapping( model.VisualizationRatingAssociation, visualizaiton=model.Visualization ) #Data Manager tables mapper( model.DataManagerHistoryAssociation, model.DataManagerHistoryAssociation.table, diff -r 1b78bcbb1bc2bc0f39149726855418ccc890a3ff -r 35ae5ce8be84dcccadaf58c9b569fb9cf9daccbf test/unit/test_galaxy_mapping.py --- a/test/unit/test_galaxy_mapping.py +++ b/test/unit/test_galaxy_mapping.py @@ -4,9 +4,138 @@ class MappingTests( unittest.TestCase ): + def test_annotations( self ): + model = self.model + + u = model.User( email="annotator@example.com", password="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.iteritems(): + 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 == "annotator@example.com" + + 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 ) + + def test_ratings( self ): + model = self.model + + u = model.User( email="rater@example.com", password="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.iteritems(): + 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 == "rater@example.com" + + 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 ) + + def test_tags( self ): + model = self.model + + my_tag = model.Tag(name="Test Tag") + u = model.User( email="tagger@example.com", password="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 + #self.persist( sw ) + 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" ) + def test_basic( self ): model = self.model + original_user_count = len( model.session.query( model.User ).all() ) + # Make some changes and commit them u = model.User( email="james@foo.bar.baz", password="password" ) # gs = model.GalaxySession() @@ -24,26 +153,31 @@ # Check users = model.session.query( model.User ).all() - assert len( users ) == 1 - assert users[0].email == "james@foo.bar.baz" - assert users[0].password == "password" - assert len( users[0].histories ) == 1 - assert users[0].histories[0].name == "History 1" + assert len( users ) == original_user_count + 1 + user = [user for user in users if user.email == "james@foo.bar.baz"][0] + assert user.email == "james@foo.bar.baz" + assert user.password == "password" + assert len( user.histories ) == 1 + assert user.histories[0].name == "History 1" hists = model.session.query( model.History ).all() - assert hists[0].name == "History 1" - assert hists[1].name == ( "H" * 255 ) - assert hists[0].user == users[0] - assert hists[1].user is None - assert hists[1].datasets[0].metadata.chromCol == 1 + hist0 = [history for history in hists if history.name == "History 1"][0] + hist1 = [history for history in hists if history.name == "H" * 255][0] + assert hist0.name == "History 1" + assert hist1.name == ( "H" * 255 ) + assert hist0.user == user + assert hist1.user is None + assert hist1.datasets[0].metadata.chromCol == 1 # The filename test has moved to objecstore - #id = hists[1].datasets[0].id - #assert hists[1].datasets[0].file_name == os.path.join( "/tmp", *directory_hash_id( id ) ) + ( "/dataset_%d.dat" % id ) + #id = hist1.datasets[0].id + #assert hist1.datasets[0].file_name == os.path.join( "/tmp", *directory_hash_id( id ) ) + ( "/dataset_%d.dat" % id ) # Do an update and check - hists[1].name = "History 2b" + hist1.name = "History 2b" self.expunge() hists = model.session.query( model.History ).all() - assert hists[0].name == "History 1" - assert hists[1].name == "History 2b" + hist0 = [history for history in hists if history.name == "History 1"][0] + hist1 = [history for history in hists if history.name == "History 2b"][0] + assert hist0.name == "History 1" + assert hist1.name == "History 2b" # gvk TODO need to ad test for GalaxySessions, but not yet sure what they should look like. @classmethod Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.