def setUp(self): self.MockSession = mock.Mock() self.MockSession.db = mock.MagicMock() self.MyDoc = collection( 'test_some_indexes', self.MockSession, Field('_id', S.ObjectId), Field('test1', str, index=True, unique=True), Field('test2'), Field('test3', str), Index('test2'), Index('test1', 'test2', direction=pymongo.DESCENDING))
def test_index_inheritance_parent_none(self): NoIndexDoc = collection('test123', self.MockSession, Field('_id', S.ObjectId), Field('test1', str), Field('test2', str), Field('test3', str)) AddSome = collection(NoIndexDoc, Index('foo'), Index('bar', unique=True)) self.assertEqual( list(AddSome.m.indexes), [Index('foo'), Index('bar', unique=True)])
def test_index_inheritance_both(self): MyChild = collection(self.MyDoc, Index('test3'), Index('test4', unique=True), collection_name='my_child') MyGrandChild = collection(MyChild, Index('test5'), Index('test6', unique=True), collection_name='my_grand_child') self.assertEqual(list(MyGrandChild.m.indexes), [ Index('test1', unique=True), Index('test2'), Index(('test1', -1), ('test2', -1)), Index('test3'), Index('test4', unique=True), Index('test5'), Index('test6', unique=True) ])
'repo_last_commit', project_doc_session, Field('_id', str), Field('object_id', str, index=True), Field('name', str), Field( 'commit_info', dict(id=str, date=datetime, author=str, author_email=str, author_url=str, shortlink=str, summary=str))) # Information about the last commit to touch a tree LastCommitDoc = collection('repo_last_commit', main_doc_session, Field('_id', S.ObjectId()), Field('commit_id', str), Field('path', str), Index('commit_id', 'path'), Field('entries', [dict(name=str, commit_id=str)])) # List of all trees contained within a commit # TreesDoc._id = CommitDoc._id # TreesDoc.tree_ids = [ TreeDoc._id, ... ] TreesDoc = collection('repo_trees', main_doc_session, Field('_id', str), Field('tree_ids', [str])) # Information about which things were added/removed in commit # DiffInfoDoc._id = CommitDoc._id DiffInfoDoc = collection( 'repo_diffinfo', main_doc_session, Field('_id', str), Field('differences', [dict(name=str, lhs_id=str, rhs_id=str)])) # List of commit runs (a run is a linear series of single-parent commits)
log = logging.getLogger(__name__) # Collection definitions ArtifactReferenceDoc = collection( str('artifact_reference'), main_doc_session, Field('_id', str), Field( 'artifact_reference', dict(cls=S.Binary(), project_id=S.ObjectId(), app_config_id=S.ObjectId(), artifact_id=S.Anything(if_missing=None))), Field('references', [str], index=True), Index('artifact_reference.project_id'), # used in ReindexCommand ) ShortlinkDoc = collection( str('shortlink'), main_doc_session, Field('_id', S.ObjectId()), # index needed for from_artifact() and index_tasks.py:del_artifacts Field('ref_id', str, index=True), Field('project_id', S.ObjectId()), Field('app_config_id', S.ObjectId()), Field('link', str), Field('url', str), # used by from_links() More helpful to have project_id first, for other # queries Index('project_id', 'link'),
artifact_id=S.Anything(if_missing=None))), Field('references', [str], index=True)) ShortlinkDoc = collection( 'shortlink', main_doc_session, Field('_id', S.ObjectId()), Field( 'ref_id', str, index=True ), # index needed for from_artifact() and index_tasks.py:del_artifacts Field('project_id', S.ObjectId()), Field('app_config_id', S.ObjectId()), Field('link', str), Field('url', str), Index( 'project_id', 'link' ), # used by from_links() More helpful to have project_id first, for other queries ) # Class definitions class ArtifactReference(object): @classmethod def from_artifact(cls, artifact): '''Upsert logic to generate an ArtifactReference object from an artifact''' obj = cls.query.get(_id=artifact.index_id()) if obj is not None: return obj try: obj = cls(_id=artifact.index_id(), artifact_reference=dict( cls=bson.Binary(dumps(artifact.__class__)),
'artifact_reference', main_doc_session, Field('_id', str), Field( 'artifact_reference', dict(cls=S.Binary(), project_id=S.ObjectId(), app_config_id=S.ObjectId(), artifact_id=S.Anything(if_missing=None))), Field('references', [str], index=True)) ShortlinkDoc = collection('shortlink', main_doc_session, Field('_id', S.ObjectId()), Field('ref_id', str, index=True), Field('project_id', S.ObjectId()), Field('app_config_id', S.ObjectId()), Field('link', str), Field('url', str), Index('link', 'project_id', 'app_config_id')) # Class definitions class ArtifactReference(object): @classmethod def from_artifact(cls, artifact): '''Upsert logic to generate an ArtifactReference object from an artifact''' obj = cls.query.get(_id=artifact.index_id()) if obj is not None: return obj try: obj = cls(_id=artifact.index_id(), artifact_reference=dict( cls=bson.Binary(dumps(artifact.__class__)), project_id=artifact.app_config.project_id, app_config_id=artifact.app_config._id,
log = logging.getLogger(__name__) # Collection definitions ArtifactReferenceDoc = collection( 'artifact_reference', main_doc_session, Field('_id', str), Field( 'artifact_reference', dict(cls=S.Binary(), project_id=S.ObjectId(), app_config_id=S.ObjectId(), artifact_id=S.Anything(if_missing=None))), Field('references', [str], index=True), Index('artifact_reference.project_id'), # used in ReindexCommand ) ShortlinkDoc = collection( 'shortlink', main_doc_session, Field('_id', S.ObjectId()), Field( 'ref_id', str, index=True ), # index needed for from_artifact() and index_tasks.py:del_artifacts Field('project_id', S.ObjectId()), Field('app_config_id', S.ObjectId()), Field('link', str), Field('url', str), Index( 'project_id', 'link'