Exemple #1
0
 def test_del_artifacts(self, solr):
     old_shortlinks = M.Shortlink.query.find().count()
     artifacts = [_TestArtifact(_shorthand_id='ta_%s' % x)
                  for x in range(5)]
     M.artifact_orm_session.flush()
     arefs = [M.ArtifactReference.from_artifact(a) for a in artifacts]
     ref_ids = [r._id for r in arefs]
     M.artifact_orm_session.flush()
     index_tasks.add_artifacts(ref_ids)
     M.main_orm_session.flush()
     M.main_orm_session.clear()
     new_shortlinks = M.Shortlink.query.find().count()
     assert old_shortlinks + 5 == new_shortlinks, 'Shortlinks not created'
     assert solr.add.call_count == 1
     sort_key = operator.itemgetter('id')
     assert_equal(
         sorted(solr.add.call_args[0][0], key=sort_key),
         sorted([ref.artifact.solarize() for ref in arefs],
                key=sort_key))
     index_tasks.del_artifacts(ref_ids)
     M.main_orm_session.flush()
     M.main_orm_session.clear()
     new_shortlinks = M.Shortlink.query.find().count()
     assert old_shortlinks == new_shortlinks, 'Shortlinks not deleted'
     solr_query = 'id:({0})'.format(' || '.join(ref_ids))
     solr.delete.assert_called_once_with(q=solr_query)
Exemple #2
0
 def test_del_artifacts(self, solr):
     old_shortlinks = M.Shortlink.query.find().count()
     artifacts = [
         _TestArtifact(_shorthand_id='ta_%s' % x) for x in range(5)
     ]
     M.artifact_orm_session.flush()
     arefs = [M.ArtifactReference.from_artifact(a) for a in artifacts]
     ref_ids = [r._id for r in arefs]
     M.artifact_orm_session.flush()
     index_tasks.add_artifacts(ref_ids)
     M.main_orm_session.flush()
     M.main_orm_session.clear()
     new_shortlinks = M.Shortlink.query.find().count()
     assert old_shortlinks + 5 == new_shortlinks, 'Shortlinks not created'
     assert solr.add.call_count == 1
     sort_key = operator.itemgetter('id')
     assert_equal(
         sorted(solr.add.call_args[0][0], key=sort_key),
         sorted([ref.artifact.solarize() for ref in arefs], key=sort_key))
     index_tasks.del_artifacts(ref_ids)
     M.main_orm_session.flush()
     M.main_orm_session.clear()
     new_shortlinks = M.Shortlink.query.find().count()
     assert old_shortlinks == new_shortlinks, 'Shortlinks not deleted'
     solr_query = 'id:({0})'.format(' || '.join(ref_ids))
     solr.delete.assert_called_once_with(q=solr_query)
Exemple #3
0
 def test_del_artifacts(self):
     old_shortlinks = M.Shortlink.query.find().count()
     old_solr_size = len(g.solr.db)
     artifacts = [
         _TestArtifact(_shorthand_id='ta_%s' % x) for x in range(5)
     ]
     M.artifact_orm_session.flush()
     arefs = [M.ArtifactReference.from_artifact(a) for a in artifacts]
     ref_ids = [r._id for r in arefs]
     M.artifact_orm_session.flush()
     index_tasks.add_artifacts(ref_ids)
     M.main_orm_session.flush()
     M.main_orm_session.clear()
     new_shortlinks = M.Shortlink.query.find().count()
     new_solr_size = len(g.solr.db)
     assert old_shortlinks + 5 == new_shortlinks, 'Shortlinks not created'
     assert old_solr_size + 5 == new_solr_size, "Solr additions didn't happen"
     index_tasks.del_artifacts(ref_ids)
     M.main_orm_session.flush()
     M.main_orm_session.clear()
     new_shortlinks = M.Shortlink.query.find().count()
     new_solr_size = len(g.solr.db)
     assert old_shortlinks == new_shortlinks, 'Shortlinks not deleted'
     assert old_solr_size == new_solr_size, "Solr deletions didn't happen"