|
| 1 | +import pytest |
| 2 | +from app import app |
| 3 | +from app.controllers.main_routes.laborStatusForm import getPositions |
| 4 | +from app.logic.statusFormFunctions import createOverloadForm |
| 5 | +from app.models.user import User |
| 6 | +from app.models.laborStatusForm import LaborStatusForm |
| 7 | +from app.models.notes import Notes |
| 8 | +from app.models.adjustedForm import AdjustedForm |
| 9 | +from app.models.formHistory import FormHistory |
| 10 | +from datetime import date, datetime |
| 11 | +from app.logic.statusFormFunctions import createOverloadForm |
| 12 | +from app.models import mainDB |
| 13 | +from app.models.supervisor import Supervisor |
| 14 | +from app.models.department import Department |
| 15 | +from app.models.laborStatusForm import LaborStatusForm |
| 16 | +from app.models.term import Term |
| 17 | +from app.models.student import Student |
| 18 | +from app.models.historyType import HistoryType |
| 19 | +from app.models.status import Status |
| 20 | +from flask import json, template_rendered |
| 21 | +from contextlib import contextmanager |
| 22 | + |
| 23 | +@pytest.fixture |
| 24 | +def setup(): |
| 25 | + delete_forms() |
| 26 | + |
| 27 | + yield |
| 28 | + |
| 29 | +@pytest.fixture |
| 30 | +def cleanup(): |
| 31 | + yield |
| 32 | + delete_forms() |
| 33 | + |
| 34 | + |
| 35 | +def delete_forms(): |
| 36 | + formHistories = FormHistory.select().where((FormHistory.formID == 2) & (FormHistory.historyType == "Labor Adjustment Form")) |
| 37 | + FormHistory.delete().where((FormHistory.formID == 2) & (FormHistory.historyType == "Labor Overload Form")).execute() |
| 38 | + for form in formHistories: |
| 39 | + # form.delete().execute() |
| 40 | + AdjustedForm.delete().where(AdjustedForm.adjustedFormID == form.adjustedForm.adjustedFormID).execute() |
| 41 | + Notes.delete().where(Notes.formID.cast('char').contains("2")).execute() |
| 42 | + |
| 43 | +def resetLSF(): |
| 44 | + lsfInfo = { |
| 45 | + "supervisorNotes":"", |
| 46 | + "supervisor" : "B12361006", |
| 47 | + "position":"S61419", |
| 48 | + "weeklyHours":10, |
| 49 | + "contractHours": None |
| 50 | + } |
| 51 | + |
| 52 | + lsf.supervisorNotes = lsfInfo["supervisorNotes"] |
| 53 | + lsf.save() |
| 54 | + lsf.supervisor = lsfInfo["supervisor"] |
| 55 | + lsf.save() |
| 56 | + lsf.position = lsfInfo["position"] |
| 57 | + lsf.save() |
| 58 | + lsf.weeklyHours = lsfInfo["weeklyHours"] |
| 59 | + lsf.save() |
| 60 | + lsf.contractHours = lsfInfo["contractHours"] |
| 61 | + lsf.save() |
| 62 | + |
| 63 | + |
| 64 | +currentUser = User.get(User.userID == 1) # Scott Heggen's entry in User table |
| 65 | +lsf = LaborStatusForm.get(LaborStatusForm.laborStatusFormID == 2) |
| 66 | +fieldsChanged = {'supervisor':{'oldValue':'B12361006', 'newValue':'B12365892','date':'07/21/2020'}, |
| 67 | + 'weeklyHours':{'oldValue': '10', 'newValue': '12', 'date': '07/21/2020'}, |
| 68 | + 'position':{'oldValue': 'S61419', 'newValue': 'S61407', 'date': '07/21/2020'}, |
| 69 | + 'supervisorNotes':{'oldValue':'old notes.', 'newValue':'new notes.'} |
| 70 | + } |
| 71 | + |
| 72 | +fieldsChangedOverload = {'weeklyHours': {'oldValue':'10', 'newValue':'20', 'date': '07/21/2020'}} |
| 73 | + |
| 74 | +fieldsChangedContractHours = {'contractHours':{'oldValue': '40', 'newValue': '60', 'date': '07/21/2020'}} |
| 75 | + |
| 76 | +@pytest.mark.integration |
| 77 | +def test_getPositions(setup): |
| 78 | + with mainDB.transaction() as transaction: |
| 79 | + deptOk = Department.create(DEPT_NAME="SSDT", ACCOUNT="SSDTACC", ORG="SSDTORG") |
| 80 | + deptOther = Department.create(DEPT_NAME="OTHER", ACCOUNT="OTHERACC", ORG="OTHERORG") |
| 81 | + term = Term.create( |
| 82 | + termCode=22332, |
| 83 | + termName="Fall 2020", |
| 84 | + termStart=date(2020, 7, 1), |
| 85 | + termEnd=date(2020, 12, 31), |
| 86 | + termState=True, |
| 87 | + adjustmentCutOff=date(2099, 1, 1), |
| 88 | + ) |
| 89 | + student = Student.create( |
| 90 | + ID="B12332123", |
| 91 | + preferred_name="Nyan", |
| 92 | + legal_name="Nyan", |
| 93 | + LAST_NAME="Zaw", |
| 94 | + STU_EMAIL="imran@berea.edu" |
| 95 | + ) |
| 96 | + supervisor1 = Supervisor.get_or_none(Supervisor.ID == "B12361007") |
| 97 | + if supervisor1 is None: |
| 98 | + supervisor1 = Supervisor.create(ID="B12361007", PIDM = 14578, LAST_NAME = "Bledsoe", legal_name = "Finn", preferred_name = "Finn", EMAIL="bledsoef@berea.edu", CPO="5467", DEPT_Name="SSDT") |
| 99 | + supervisor2 = Supervisor.get_or_none(Supervisor.ID == "B12365892") |
| 100 | + if supervisor2 is None: |
| 101 | + supervisor2 = Supervisor.create(ID="B12365892", PIDM = 14579, LAST_NAME = "Bledsoe", legal_name = "Jason", preferred_name = "Jason", EMAIL="bledsoej@berea.edu", CPO="5468", DEPT_Name="SSDT") |
| 102 | + currentUser = User.get(User.userID == 3) |
| 103 | + status, _ = Status.get_or_create(statusName="Approved") |
| 104 | + historyType, _ = HistoryType.get_or_create(historyTypeName="Labor Status Form") |
| 105 | + lsfGood = LaborStatusForm.create( |
| 106 | + laborStatusFormID=98765, |
| 107 | + termCode=term, |
| 108 | + studentSupervisee=student, |
| 109 | + supervisor=supervisor1, |
| 110 | + department=deptOk, |
| 111 | + jobType="Primary", |
| 112 | + WLS="W1", |
| 113 | + POSN_TITLE="Good Position", |
| 114 | + POSN_CODE="S61407", |
| 115 | + contractHours=40, |
| 116 | + weeklyHours=10, |
| 117 | + supervisorNotes="old notes.", |
| 118 | + ) |
| 119 | + lsfDummy = LaborStatusForm.create( |
| 120 | + laborStatusFormID=98766, |
| 121 | + termCode=term, |
| 122 | + studentSupervisee=student, |
| 123 | + supervisor=supervisor1, |
| 124 | + department=deptOk, |
| 125 | + jobType="Primary", |
| 126 | + WLS="WD", |
| 127 | + POSN_TITLE="Dummy Position", |
| 128 | + POSN_CODE="S12345", |
| 129 | + contractHours=40, |
| 130 | + weeklyHours=10, |
| 131 | + supervisorNotes="old notes.", |
| 132 | + ) |
| 133 | + lsfOther = LaborStatusForm.create( |
| 134 | + laborStatusFormID=98767, |
| 135 | + termCode=term, |
| 136 | + studentSupervisee=student, |
| 137 | + supervisor=supervisor1, |
| 138 | + department=deptOther, |
| 139 | + jobType="Primary", |
| 140 | + WLS="WO", |
| 141 | + POSN_TITLE="Other Dept Position", |
| 142 | + POSN_CODE="S99999", |
| 143 | + contractHours=40, |
| 144 | + weeklyHours=10, |
| 145 | + supervisorNotes="old notes.", |
| 146 | + ) |
| 147 | + FormHistory.create( |
| 148 | + formID=lsfGood, |
| 149 | + historyType=historyType, |
| 150 | + createdBy=currentUser, |
| 151 | + createdDate=date.today(), |
| 152 | + status=status, |
| 153 | + ) |
| 154 | + FormHistory.create( |
| 155 | + formID=lsfDummy, |
| 156 | + historyType=historyType, |
| 157 | + createdBy=currentUser, |
| 158 | + createdDate=date.today(), |
| 159 | + status=status, |
| 160 | + ) |
| 161 | + FormHistory.create( |
| 162 | + formID=lsfOther, |
| 163 | + historyType=historyType, |
| 164 | + createdBy=currentUser, |
| 165 | + createdDate=date.today(), |
| 166 | + status=status, |
| 167 | + ) |
| 168 | + with app.test_request_context(): |
| 169 | + positions = json.loads(getPositions("SSDTORG", "SSDTACC")) |
| 170 | + assert "S12345" in positions |
| 171 | + assert "S61407" in positions |
| 172 | + |
| 173 | + assert positions["S12345"]["position"] == "Dummy Position" |
| 174 | + assert positions["S61407"]["position"] == "Good Position" |
| 175 | + resetLSF() |
| 176 | + transaction.rollback() |
0 commit comments