Esempio n. 1
0
 def xtestSimple(self):
     ga = phylesystem.create_git_action(_SID)
     ga.acquire_lock()
     try:
         curr, sha, wip_map = ga.return_study(_SID, return_WIP_map=True)
     finally:
         ga.release_lock()
     curr_obj = json.loads(curr)
     ac = curr_obj['nexml'].get("^acount", 0)
     ac += 1
     curr_obj['nexml']["^acount"] = ac
     commit_and_try_merge2master(ga, curr_obj, _SID, _AUTH, sha)
Esempio n. 2
0
 def xtestSimple(self):
     ga = phylesystem.create_git_action(_SID)
     ga.acquire_lock()
     try:
         curr, sha, wip_map = ga.return_study(_SID, return_WIP_map=True)
     finally:
         ga.release_lock()
     curr_obj = json.loads(curr)
     ac = curr_obj['nexml'].get("^acount", 0)
     ac += 1
     curr_obj['nexml']["^acount"] = ac
     commit_and_try_merge2master(ga, curr_obj, _SID, _AUTH, sha)
Esempio n. 3
0
 def annotate_and_write(self, #pylint: disable=R0201
                        git_data,
                        nexson,
                        study_id,
                        auth_info,
                        adaptor,
                        annotation,
                        parent_sha,
                        commit_msg='',
                        master_file_blob_included=None):
     '''
     This is the heart of the api's __finish_write_verb
     It was moved to phylesystem to make it easier to coordinate it
         with the caching decisions. We have been debating whether
         to cache @id and @dateCreated attributes for the annotations
         or cache the whole annotation. Since these decisions are in
         add_validation_annotation (above), it is easier to have
         that decision and the add_or_replace_annotation call in the
         same repo.
     '''
     adaptor.add_or_replace_annotation(nexson,
                                       annotation['annotationEvent'],
                                       annotation['agent'],
                                       add_agent_only=True)
     return commit_and_try_merge2master(git_action=git_data,
                                        file_content=nexson,
                                        study_id=study_id,
                                        auth_info=auth_info,
                                        parent_sha=parent_sha,
                                        commit_msg=commit_msg,
                                        merged_sha=master_file_blob_included)
 def testSimple(self):
     ga = phylesystem.create_git_action(_SID)
     ga.acquire_lock()
     try:
         curr, sha, wip_map = ga.return_study(_SID, return_WIP_map=True)
     finally:
         ga.release_lock()
     curr_obj = json.loads(curr)
     ac = curr_obj['nexml'].get("^acount", 0)
     ac += 1
     curr_obj['nexml']["^acount"] = ac
     try:
         commit_and_try_merge2master(ga, curr_obj, _SID, _AUTH, sha)
     except GitWorkflowError:
         if not COMMITS_SHOULD_FAIL:
             raise
Esempio n. 5
0
 def testSimple(self):
     ga = phylesystem.create_git_action(_SID)
     ga.acquire_lock()
     try:
         curr, sha, wip_map = ga.return_study(_SID, return_WIP_map=True)
     finally:
         ga.release_lock()
     curr_obj = json.loads(curr)
     ac = curr_obj['nexml'].get("^acount", 0)
     ac += 1
     curr_obj['nexml']["^acount"] = ac
     try:
         commit_and_try_merge2master(ga, curr_obj, _SID, _AUTH, sha)
     except GitWorkflowError:
         if not COMMITS_SHOULD_FAIL:
             raise
Esempio n. 6
0
 def annotate_and_write(
         self,  #pylint: disable=R0201
         git_data,
         nexson,
         study_id,
         auth_info,
         adaptor,
         annotation,
         parent_sha,
         commit_msg='',
         master_file_blob_included=None):
     '''
     This is the heart of the api's __finish_write_verb
     It was moved to phylesystem to make it easier to coordinate it
         with the caching decisions. We have been debating whether
         to cache @id and @dateCreated attributes for the annotations
         or cache the whole annotation. Since these decisions are in
         add_validation_annotation (above), it is easier to have
         that decision and the add_or_replace_annotation call in the
         same repo.
     '''
     adaptor.add_or_replace_annotation(nexson,
                                       annotation['annotationEvent'],
                                       annotation['agent'],
                                       add_agent_only=True)
     return commit_and_try_merge2master(
         git_action=git_data,
         file_content=nexson,
         study_id=study_id,
         auth_info=auth_info,
         parent_sha=parent_sha,
         commit_msg=commit_msg,
         merged_sha=master_file_blob_included)
Esempio n. 7
0
 def commit_and_try_merge2master(self,
                                 file_content,
                                 study_id,
                                 auth_info,
                                 parent_sha,
                                 commit_msg='',
                                 merged_sha=None):
     git_action = self.create_git_action(study_id)
     resp = commit_and_try_merge2master(git_action,
                                        file_content,
                                        study_id,
                                        auth_info,
                                        parent_sha,
                                        commit_msg,
                                        merged_sha=merged_sha)
     if not resp['merge_needed']:
         self._study_merged_hook(git_action, study_id)
     return resp
Esempio n. 8
0
 def commit_and_try_merge2master(self,
                                 file_content,
                                 study_id,
                                 auth_info,
                                 parent_sha,
                                 commit_msg='',
                                 merged_sha=None):
     git_action = self.create_git_action(study_id)
     resp = commit_and_try_merge2master(git_action,
                                        file_content,
                                        study_id,
                                        auth_info,
                                        parent_sha,
                                        commit_msg,
                                        merged_sha=merged_sha)
     if not resp['merge_needed']:
         self._study_merged_hook(git_action, study_id)
     return resp
Esempio n. 9
0
 def testDelStudy(self):
     ga = phylesystem.create_git_action(_SID)
     ga.acquire_lock()
     try:
         curr, sha, wip_map = ga.return_study(_SID, return_WIP_map=True)
     finally:
         ga.release_lock()
     _LOG.debug('test sha = "{}"'.format(sha))
     self.assertEquals(wip_map.keys(), ['master'])
     acurr_obj = json.loads(curr)
     zcurr_obj = copy.deepcopy(acurr_obj)
     ac = acurr_obj['nexml'].get("^acount", 0)
     # add a commit that should merge to master
     acount_at_sha = ac
     ac += 1
     acurr_obj['nexml']["^acount"] = ac
     v1b = commit_and_try_merge2master(ga, acurr_obj, _SID, _AUTH, sha)
     v1bsha = v1b['sha']
     acount_at_v1bsha = ac
     self.assertFalse(v1b['merge_needed'])
     sidl = phylesystem.get_study_ids()
     self.assertIn(_SID, sidl)
     v2b = phylesystem.delete_study(_SID, _AUTH, sha)
     v2bsha = v2b['sha']
     self.assertTrue(v2b['merge_needed'])
     sidl = phylesystem.get_study_ids()
     self.assertIn(_SID, sidl)
     curr, naked_get_sha, wip_map = phylesystem.return_study(
         _SID, return_WIP_map=True)
     self.assertEquals(naked_get_sha, v1bsha)
     v3b = phylesystem.delete_study(_SID, _AUTH, naked_get_sha)
     v3bsha = v3b['sha']
     self.assertFalse(v3b['merge_needed'])
     sidl = phylesystem.get_study_ids()
     self.assertNotIn(_SID, sidl)
     self.assertRaises(KeyError,
                       phylesystem.return_study,
                       _SID,
                       return_WIP_map=True)
     self.assertRaises(KeyError,
                       phylesystem.return_study,
                       _SID,
                       commit_sha=v2bsha,
                       return_WIP_map=True)
     self.assertRaises(KeyError,
                       phylesystem.return_study,
                       _SID,
                       commit_sha=v3bsha,
                       return_WIP_map=True)
     curr, naked_get_sha, wip_map = phylesystem.return_study(
         _SID, commit_sha=sha, return_WIP_map=True)
     self.assertEquals(acount_at_sha, curr['nexml'].get("^acount", 0))
     curr, naked_get_sha, wip_map = phylesystem.return_study(
         _SID, commit_sha=v1bsha, return_WIP_map=True)
     self.assertEquals(acount_at_v1bsha, curr['nexml']["^acount"])
     ga = phylesystem.create_git_action(_SID)  # assert no raise
     sidl = phylesystem.get_study_ids()
     self.assertNotIn(_SID, sidl)
     ac += 1
     curr['nexml']["^acount"] = ac
     ga = phylesystem.create_git_action(_SID)
     v4b = commit_and_try_merge2master(ga, curr, _SID, _AUTH, v1bsha)
     v4bsha = v4b['sha']
     self.assertTrue(v4b['merge_needed'])
     curr, naked_get_sha, wip_map = phylesystem.return_study(
         _SID, commit_sha=v4bsha, return_WIP_map=True)
     self.assertEquals(ac, curr['nexml']["^acount"])
     ac += 1
     curr['nexml']["^acount"] = ac
     ga = phylesystem.create_git_action(_SID)
     v5b = phylesystem.commit_and_try_merge2master(curr, _SID, _AUTH,
                                                   v3bsha)
     self.assertFalse(v5b['merge_needed'])
     sidl = phylesystem.get_study_ids()
     self.assertIn(_SID, sidl)
     curr, naked_get_sha, wip_map = phylesystem.return_study(
         _SID, commit_sha=v5b['sha'], return_WIP_map=True)
     self.assertEquals(ac, curr['nexml']["^acount"])
     curr, naked_get_sha, wip_map = phylesystem.return_study(
         _SID, return_WIP_map=True)
     self.assertEquals(ac, curr['nexml']["^acount"])
     self.assertRaises(KeyError,
                       phylesystem.return_study,
                       _SID,
                       commit_sha=v2bsha,
                       return_WIP_map=True)
     self.assertRaises(KeyError,
                       phylesystem.return_study,
                       _SID,
                       commit_sha=v3bsha,
                       return_WIP_map=True)
Esempio n. 10
0
    def testBranched(self):
        ga = phylesystem.create_git_action(_SID)
        ga.acquire_lock()
        try:
            curr, sha, wip_map = ga.return_study(_SID, return_WIP_map=True)
        finally:
            ga.release_lock()
        _LOG.debug('test sha = "{}"'.format(sha))
        self.assertEquals(wip_map.keys(), ['master'])
        acurr_obj = json.loads(curr)
        zcurr_obj = copy.deepcopy(acurr_obj)
        ac = acurr_obj['nexml'].get("^acount", 0)
        # add a second commit that should merge to master
        ac += 1
        acurr_obj['nexml']["^acount"] = ac
        v1b = commit_and_try_merge2master(ga, acurr_obj, _SID, _AUTH, sha)
        self.assertFalse(v1b['merge_needed'])
        
        # add a third commit that should NOT merge to master
        zc = zcurr_obj['nexml'].get("^zcount", 0)
        zc += 1
        zcurr_obj['nexml']["^zcount"] = zc
        v2b = commit_and_try_merge2master(ga, zcurr_obj, _SID, _AUTH, sha)
        
        self.assertNotEqual(v1b['branch_name'], v2b['branch_name'])
        self.assertNotEqual(v1b['sha'], v2b['sha'])
        self.assertEqual(v1b['sha'], ga.get_master_sha()) # not locked!
        self.assertTrue(v2b['merge_needed'])

        # fetching studies (GETs in the API) should report 
        # the existence of multiple branches for this study...
        ga.acquire_lock()
        try:
            t, ts, wip_map = ga.return_study(_SID, return_WIP_map=True)
        finally:
            ga.release_lock()
        self.assertEquals(wip_map['master'], v1b['sha'])
        self.assertEquals(wip_map['test_gh_login_study_{}_0'.format(_SID)], v2b['sha'])
        
        # but not for other studies...
        ga.acquire_lock()
        try:
            t, ts, wip_map = ga.return_study('10', return_WIP_map=True)
        finally:
            ga.release_lock()
        self.assertEquals(wip_map['master'], v1b['sha'])
        self.assertEquals(wip_map.keys(), ['master'])
        
        # add a fourth commit onto commit 2. This should merge to master
        ac += 1
        acurr_obj['nexml']["^acount"] = ac
        v3b = commit_and_try_merge2master(ga, acurr_obj, _SID, _AUTH, v1b['sha'])
        self.assertFalse(v3b['merge_needed'])
        
        # add a fifth commit onto commit 3. This should still NOT merge to master
        zc += 1
        zcurr_obj['nexml']["^zcount"] = zc
        v4b = commit_and_try_merge2master(ga, zcurr_obj, _SID, _AUTH, v2b['sha'])
        
        self.assertNotEqual(v3b['branch_name'], v4b['branch_name'])
        self.assertEqual(v2b['branch_name'], v4b['branch_name'])
        self.assertNotEqual(v3b['sha'], v4b['sha'])
        self.assertEqual(v3b['sha'], ga.get_master_sha()) # not locked!
        self.assertTrue(v4b['merge_needed'])
        
        # sixth commit is the merge
        mblob = merge_from_master(ga, _SID, _AUTH, v4b['sha'])
        self.assertEqual(mblob["error"], 0)
        self.assertEqual(mblob["resource_id"], _SID)
        
        
        # add a 7th commit onto commit 6. This should NOT merge to master because we don't give it the secret arg.
        zc += 1
        zcurr_obj['nexml']["^zcount"] = zc
        v5b = commit_and_try_merge2master(ga, zcurr_obj, _SID, _AUTH, mblob['sha'])
        self.assertNotEqual(v3b['sha'], v5b['sha'])
        self.assertTrue(v5b['merge_needed'])
        
        # add a 7th commit onto commit 6. This should merge to master because we don't give it the secret arg.
        zc += 1
        zcurr_obj['nexml']["^zcount"] = zc
        v6b = commit_and_try_merge2master(ga, zcurr_obj, _SID, _AUTH, v5b['sha'], merged_sha=mblob['merged_sha'])
        self.assertNotEqual(v3b['sha'], v6b['sha'])
        self.assertEqual(v6b['sha'], ga.get_master_sha()) # not locked!
        self.assertFalse(v6b['merge_needed'])
        self.assertEqual(v6b['branch_name'], 'master')
        
        # after the merge we should be back down to 1 branch for this study
        ga.acquire_lock()
        try:
            t, ts, wip_map = ga.return_study(_SID, return_WIP_map=True)
        finally:
            ga.release_lock()
        self.assertEquals(wip_map.keys(), ['master'])
Esempio n. 11
0
    def testBranched(self):
        ga = phylesystem.create_git_action(_SID)
        ga.acquire_lock()
        try:
            curr, sha, wip_map = ga.return_study(_SID, return_WIP_map=True)
        finally:
            ga.release_lock()
        _LOG.debug('test sha = "{}"'.format(sha))
        self.assertEquals(wip_map.keys(), ['master'])
        acurr_obj = json.loads(curr)
        zcurr_obj = copy.deepcopy(acurr_obj)
        ac = acurr_obj['nexml'].get("^acount", 0)
        # add a second commit that should merge to master
        ac += 1
        acurr_obj['nexml']["^acount"] = ac
        try:
            v1b = commit_and_try_merge2master(ga, acurr_obj, _SID, _AUTH, sha)
        except GitWorkflowError:
            if not COMMITS_SHOULD_FAIL:
                raise
            return
        self.assertFalse(v1b['merge_needed'])

        # add a third commit that should NOT merge to master
        zc = zcurr_obj['nexml'].get("^zcount", 0)
        zc += 1
        zcurr_obj['nexml']["^zcount"] = zc
        v2b = commit_and_try_merge2master(ga, zcurr_obj, _SID, _AUTH, sha)

        self.assertNotEqual(v1b['branch_name'], v2b['branch_name'])
        self.assertNotEqual(v1b['sha'], v2b['sha'])
        self.assertEqual(v1b['sha'], ga.get_master_sha())  # not locked!
        self.assertTrue(v2b['merge_needed'])

        # fetching studies (GETs in the API) should report
        # the existence of multiple branches for this study...
        ga.acquire_lock()
        try:
            t, ts, wip_map = ga.return_study(_SID, return_WIP_map=True)
        finally:
            ga.release_lock()
        self.assertEquals(wip_map['master'], v1b['sha'])
        self.assertEquals(wip_map['test_gh_login_study_{}_0'.format(_SID)],
                          v2b['sha'])

        # but not for other studies...
        ga.acquire_lock()
        try:
            t, ts, wip_map = ga.return_study('10', return_WIP_map=True)
        finally:
            ga.release_lock()
        self.assertEquals(wip_map['master'], v1b['sha'])
        self.assertEquals(wip_map.keys(), ['master'])

        # add a fourth commit onto commit 2. This should merge to master
        ac += 1
        acurr_obj['nexml']["^acount"] = ac
        v3b = commit_and_try_merge2master(ga, acurr_obj, _SID, _AUTH,
                                          v1b['sha'])
        self.assertFalse(v3b['merge_needed'])

        # add a fifth commit onto commit 3. This should still NOT merge to master
        zc += 1
        zcurr_obj['nexml']["^zcount"] = zc
        v4b = commit_and_try_merge2master(ga, zcurr_obj, _SID, _AUTH,
                                          v2b['sha'])

        self.assertNotEqual(v3b['branch_name'], v4b['branch_name'])
        self.assertEqual(v2b['branch_name'], v4b['branch_name'])
        self.assertNotEqual(v3b['sha'], v4b['sha'])
        self.assertEqual(v3b['sha'], ga.get_master_sha())  # not locked!
        self.assertTrue(v4b['merge_needed'])

        # sixth commit is the merge
        mblob = merge_from_master(ga, _SID, _AUTH, v4b['sha'])
        self.assertEqual(mblob["error"], 0)
        self.assertEqual(mblob["resource_id"], _SID)

        # add a 7th commit onto commit 6. This should NOT merge to master because we don't give it the secret arg.
        zc += 1
        zcurr_obj['nexml']["^zcount"] = zc
        v5b = commit_and_try_merge2master(ga, zcurr_obj, _SID, _AUTH,
                                          mblob['sha'])
        self.assertNotEqual(v3b['sha'], v5b['sha'])
        self.assertTrue(v5b['merge_needed'])

        # add a 7th commit onto commit 6. This should merge to master because we don't give it the secret arg.
        zc += 1
        zcurr_obj['nexml']["^zcount"] = zc
        v6b = commit_and_try_merge2master(ga,
                                          zcurr_obj,
                                          _SID,
                                          _AUTH,
                                          v5b['sha'],
                                          merged_sha=mblob['merged_sha'])
        self.assertNotEqual(v3b['sha'], v6b['sha'])
        self.assertEqual(v6b['sha'], ga.get_master_sha())  # not locked!
        self.assertFalse(v6b['merge_needed'])
        self.assertEqual(v6b['branch_name'], 'master')

        # after the merge we should be back down to 1 branch for this study
        ga.acquire_lock()
        try:
            t, ts, wip_map = ga.return_study(_SID, return_WIP_map=True)
        finally:
            ga.release_lock()
        self.assertEquals(wip_map.keys(), ['master'])
Esempio n. 12
0
 def testDelStudy(self):
     ga = phylesystem.create_git_action(_SID)
     ga.acquire_lock()
     try:
         curr, sha, wip_map = ga.return_study(_SID, return_WIP_map=True)
     finally:
         ga.release_lock()
     _LOG.debug('test sha = "{}"'.format(sha))
     self.assertEquals(wip_map.keys(), ["master"])
     acurr_obj = json.loads(curr)
     zcurr_obj = copy.deepcopy(acurr_obj)
     ac = acurr_obj["nexml"].get("^acount", 0)
     # add a commit that should merge to master
     acount_at_sha = ac
     ac += 1
     acurr_obj["nexml"]["^acount"] = ac
     v1b = commit_and_try_merge2master(ga, acurr_obj, _SID, _AUTH, sha)
     v1bsha = v1b["sha"]
     acount_at_v1bsha = ac
     self.assertFalse(v1b["merge_needed"])
     sidl = phylesystem.get_study_ids()
     self.assertIn(_SID, sidl)
     v2b = phylesystem.delete_study(_SID, _AUTH, sha)
     v2bsha = v2b["sha"]
     self.assertTrue(v2b["merge_needed"])
     sidl = phylesystem.get_study_ids()
     self.assertIn(_SID, sidl)
     curr, naked_get_sha, wip_map = phylesystem.return_study(_SID, return_WIP_map=True)
     self.assertEquals(naked_get_sha, v1bsha)
     v3b = phylesystem.delete_study(_SID, _AUTH, naked_get_sha)
     v3bsha = v3b["sha"]
     self.assertFalse(v3b["merge_needed"])
     sidl = phylesystem.get_study_ids()
     self.assertNotIn(_SID, sidl)
     self.assertRaises(KeyError, phylesystem.return_study, _SID, return_WIP_map=True)
     self.assertRaises(KeyError, phylesystem.return_study, _SID, commit_sha=v2bsha, return_WIP_map=True)
     self.assertRaises(KeyError, phylesystem.return_study, _SID, commit_sha=v3bsha, return_WIP_map=True)
     curr, naked_get_sha, wip_map = phylesystem.return_study(_SID, commit_sha=sha, return_WIP_map=True)
     self.assertEquals(acount_at_sha, curr["nexml"].get("^acount", 0))
     curr, naked_get_sha, wip_map = phylesystem.return_study(_SID, commit_sha=v1bsha, return_WIP_map=True)
     self.assertEquals(acount_at_v1bsha, curr["nexml"]["^acount"])
     ga = phylesystem.create_git_action(_SID)  # assert no raise
     sidl = phylesystem.get_study_ids()
     self.assertNotIn(_SID, sidl)
     ac += 1
     curr["nexml"]["^acount"] = ac
     ga = phylesystem.create_git_action(_SID)
     v4b = commit_and_try_merge2master(ga, curr, _SID, _AUTH, v1bsha)
     v4bsha = v4b["sha"]
     self.assertTrue(v4b["merge_needed"])
     curr, naked_get_sha, wip_map = phylesystem.return_study(_SID, commit_sha=v4bsha, return_WIP_map=True)
     self.assertEquals(ac, curr["nexml"]["^acount"])
     ac += 1
     curr["nexml"]["^acount"] = ac
     ga = phylesystem.create_git_action(_SID)
     v5b = phylesystem.commit_and_try_merge2master(curr, _SID, _AUTH, v3bsha)
     self.assertFalse(v5b["merge_needed"])
     sidl = phylesystem.get_study_ids()
     self.assertIn(_SID, sidl)
     curr, naked_get_sha, wip_map = phylesystem.return_study(_SID, commit_sha=v5b["sha"], return_WIP_map=True)
     self.assertEquals(ac, curr["nexml"]["^acount"])
     curr, naked_get_sha, wip_map = phylesystem.return_study(_SID, return_WIP_map=True)
     self.assertEquals(ac, curr["nexml"]["^acount"])
     self.assertRaises(KeyError, phylesystem.return_study, _SID, commit_sha=v2bsha, return_WIP_map=True)
     self.assertRaises(KeyError, phylesystem.return_study, _SID, commit_sha=v3bsha, return_WIP_map=True)