def test_greaterthan0quota(self, quota):
     '''
     ValueError is raised when quota of 0 or less is passed
     '''
     with pytest.raises(ValueError, match=r'quota must be larger than 0'):
         submission.stop_submission_over_quota(SYN,
                                               self.fileview_id,
                                               quota=quota)
 def test_noneintquota(self):
     '''
     ValueError is raised when none integer quota is passed in
     '''
     with pytest.raises(ValueError, match=r'quota must be an integer'):
         submission.stop_submission_over_quota(SYN,
                                               self.fileview_id,
                                               quota="foo")
 def test_queryfail(self):
     '''
     ValueError is raised tableQuery fails
     '''
     with patch.object(SYN, "tableQuery",
                       side_effect=SynapseHTTPError),\
          pytest.raises(ValueError,
                        match=r'Submission view must have columns:*'):
         submission.stop_submission_over_quota(SYN, self.fileview_id)
 def test_noquota(self):
     '''
     Time remaining annotation should not be added
     if no quota is set, the default is sys.maxsize.
     '''
     with patch.object(SYN, "tableQuery",
                       return_value=self.mock_tablequery) as patch_query,\
          patch.object(self.mock_tablequery, "asDataFrame",
                       return_value=self.submission_viewdf),\
          patch.object(annotations, "annotate_submission") as patch_store:
         submission.stop_submission_over_quota(SYN, self.fileview_id)
         query = (f"select {submission.WORKFLOW_LAST_UPDATED_KEY}, "
                  f"{submission.WORKFLOW_START_KEY}, id, "
                  f"status from {self.fileview_id} where "
                  "status = 'EVALUATION_IN_PROGRESS'")
         patch_query.assert_called_once_with(query)
         patch_store.assert_not_called()
 def test_underquota(self):
     '''
     Time remaining annotation should not be added
     if the model is not over quota
     '''
     with patch.object(SYN, "tableQuery",
                       return_value=self.mock_tablequery) as patch_query,\
          patch.object(self.mock_tablequery, "asDataFrame",
                       return_value=self.submission_viewdf),\
          patch.object(annotations, "annotate_submission") as patch_store:
         quota = self.last_updated_time - self.start_time + 9000
         submission.stop_submission_over_quota(SYN,
                                               self.fileview_id,
                                               quota=quota)
         query = (f"select {submission.WORKFLOW_LAST_UPDATED_KEY}, "
                  f"{submission.WORKFLOW_START_KEY}, id, "
                  f"status from {self.fileview_id} where "
                  "status = 'EVALUATION_IN_PROGRESS'")
         patch_query.assert_called_once_with(query)
         patch_store.assert_not_called()
 def test_notstartedsubmission(self):
     '''
     Time remaining annotation should not be added
     if a submission is not validated/scored by the workflowhook
     the submission will not have the right annotations,
     '''
     self.submission_viewdf.loc[
         0, submission.WORKFLOW_LAST_UPDATED_KEY] = float('nan')
     with patch.object(SYN, "tableQuery",
                       return_value=self.mock_tablequery) as patch_query,\
          patch.object(self.mock_tablequery, "asDataFrame",
                       return_value=self.submission_viewdf),\
          patch.object(annotations, "annotate_submission") as patch_store:
         submission.stop_submission_over_quota(SYN, self.fileview_id)
         query = (f"select {submission.WORKFLOW_LAST_UPDATED_KEY}, "
                  f"{submission.WORKFLOW_START_KEY}, id, "
                  f"status from {self.fileview_id} where "
                  "status = 'EVALUATION_IN_PROGRESS'")
         patch_query.assert_called_once_with(query)
         patch_store.assert_not_called()