Completing tests
This commit is contained in:
parent
1231b963d0
commit
72b59deeaf
|
@ -6,7 +6,10 @@ from crc.services.approval_service import ApprovalService
|
|||
|
||||
|
||||
def get_approvals(approver_uid = None):
|
||||
db_approvals = ApprovalService.get_all_approvals()
|
||||
if not approver_uid:
|
||||
db_approvals = ApprovalService.get_all_approvals()
|
||||
else:
|
||||
db_approvals = ApprovalService.get_approvals_per_user(approver_uid)
|
||||
approvals = [Approval.from_model(approval_model) for approval_model in db_approvals]
|
||||
results = ApprovalSchema(many=True).dump(approvals)
|
||||
return results
|
||||
|
|
|
@ -69,7 +69,6 @@ class Approval(object):
|
|||
if model.study:
|
||||
instance.title = model.study.title
|
||||
|
||||
# TODO: Use ldap lookup
|
||||
ldap_service = LdapService()
|
||||
try:
|
||||
user_info = ldap_service.user_info(model.approver_uid)
|
||||
|
|
|
@ -2,7 +2,7 @@ import json
|
|||
from tests.base_test import BaseTest
|
||||
|
||||
from crc import app, db, session
|
||||
from crc.models.approval import ApprovalModel
|
||||
from crc.models.approval import ApprovalModel, ApprovalSchema, ApprovalStatus
|
||||
|
||||
|
||||
APPROVAL_PAYLOAD = {
|
||||
|
@ -43,23 +43,54 @@ class TestApprovals(BaseTest):
|
|||
self.approval = ApprovalModel(
|
||||
study=self.study,
|
||||
workflow=self.workflow,
|
||||
approver_uid='bgb22',
|
||||
status='WAITING', # TODO: Use enumerate options
|
||||
approver_uid='arc93',
|
||||
status=ApprovalStatus.WAITING.value,
|
||||
version=1
|
||||
)
|
||||
session.add(self.approval)
|
||||
|
||||
self.approval_2 = ApprovalModel(
|
||||
study=self.study,
|
||||
workflow=self.workflow,
|
||||
approver_uid='dhf8r',
|
||||
status=ApprovalStatus.WAITING.value,
|
||||
version=1
|
||||
)
|
||||
session.add(self.approval_2)
|
||||
|
||||
session.commit()
|
||||
|
||||
def test_list_approvals_per_approver(self):
|
||||
"""Only approvals associated with approver should be returned"""
|
||||
rv = self.app.get('/v1.0/approval', headers=self.logged_in_headers())
|
||||
approver_uid = self.approval_2.approver_uid
|
||||
rv = self.app.get(f'/v1.0/approval?approver_uid={approver_uid}', headers=self.logged_in_headers())
|
||||
self.assert_success(rv)
|
||||
|
||||
response = json.loads(rv.get_data(as_text=True))
|
||||
|
||||
# Stored approvals are 2
|
||||
approvals_count = ApprovalModel.query.count()
|
||||
self.assertEqual(approvals_count, 2)
|
||||
|
||||
# but Dan's approvals should be only 1
|
||||
self.assertEqual(len(response), 1)
|
||||
|
||||
# Confirm approver UID matches returned payload
|
||||
approval = ApprovalSchema().load(response[0])
|
||||
self.assertEqual(approval.approver['uid'], approver_uid)
|
||||
|
||||
def test_list_approvals_per_admin(self):
|
||||
"""All approvals will be returned"""
|
||||
rv = self.app.get('/v1.0/approval', headers=self.logged_in_headers())
|
||||
self.assert_success(rv)
|
||||
|
||||
response = json.loads(rv.get_data(as_text=True))
|
||||
|
||||
# Returned approvals should match what's in the db
|
||||
approvals_count = ApprovalModel.query.count()
|
||||
response_count = len(response)
|
||||
self.assertEqual(approvals_count, response_count)
|
||||
|
||||
def test_update_approval(self):
|
||||
"""Approval status will be updated"""
|
||||
approval_id = self.approval.id
|
||||
|
|
Loading…
Reference in New Issue