Skip to content

Commit b4dc2f9

Browse files
committed
Finally done created test suites
1 parent 7ccce94 commit b4dc2f9

7 files changed

Lines changed: 190 additions & 32 deletions

File tree

app/controllers/main_routes/alterLSF.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def alterLSF(laborStatusKey):
2626
if not currentUser.isLaborAdmin: # Not an admin
2727
if currentUser.student and not currentUser.supervisor: # If a student is logged in and trying to get to this URL then send them back to their own page.
2828
return redirect("/laborHistory/" + currentUser.student.ID)
29-
3029
currentDate = date.today()
3130
#If logged in....
3231
#Step 1: get form attached to the student (via labor history modal)
@@ -71,8 +70,7 @@ def alterLSF(laborStatusKey):
7170
(Department.ORG == form.department.ORG)
7271
)
7372
)
74-
positions = [position for position in positions]
75-
positions = set(positions)
73+
positions = {position for position in positions}
7674
departments = Department.select()
7775
# supervisors from the old system WILL have a Supervisor record, but might not have a Tracy record
7876
oldSupervisor = Supervisor.get_or_none(ID = form.supervisor.ID)

app/controllers/main_routes/laborHistory.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ def populateModal(statusKey):
127127
to create the modal, and append all of the data gathered here form the database to the modal. It also sets a button state which decides which buttons
128128
to put on the modal depending on what form is in the history.
129129
"""
130-
print("Status Key: ", statusKey)
131130
try:
132131
currentUser = require_login()
133132
if not currentUser: # Not logged in
@@ -161,7 +160,6 @@ def populateModal(statusKey):
161160
.where(LaborStatusForm.POSN_CODE == newValue)
162161
.first()
163162
)
164-
print("wewewe", oldValue, "lolo")
165163
try:
166164
oldPosition = LaborStatusForm.get_or_none(
167165
LaborStatusForm.POSN_CODE == oldValue

app/controllers/main_routes/laborStatusForm.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,21 @@ def getDates(termcode):
118118
def getPositions(departmentOrg, departmentAcct):
119119
""" Get all of the positions that are in the selected department """
120120
currentUser = require_login()
121-
print("ikikik", departmentAcct, "fefefe", departmentOrg, "lili")
122-
positions = (
123-
FormHistory
121+
positions = set(
122+
LaborStatusForm
124123
.select(FormHistory, LaborStatusForm, Department)
125-
.join(LaborStatusForm, on=(FormHistory.formID == LaborStatusForm.laborStatusFormID))
124+
.join(FormHistory, on=(FormHistory.formID == LaborStatusForm.laborStatusFormID))
125+
.switch(LaborStatusForm)
126126
.join(Department, on=(LaborStatusForm.department == Department.departmentID))
127127
.where(
128128
(Department.ACCOUNT == departmentAcct) &
129129
(Department.ORG == departmentOrg)
130130
)
131131
)
132-
positions = set(positions)
133132
positionDict = {}
134133
for position in positions:
135-
print(position.formID.POSN_CODE, "positionsssssss")
136-
if position.formID.POSN_CODE != "S12345" or currentUser.isLaborAdmin:
137-
positionDict[position.formID.POSN_CODE] = {"position": position.formID.POSN_TITLE, "WLS":position.formID.WLS, "positionCode":position.formID.POSN_CODE}
138-
print(positionDict, "seeeeeee")
134+
if position.POSN_CODE != "S12345" or currentUser.isLaborAdmin:
135+
positionDict[position.POSN_CODE] = {"position": position.POSN_TITLE, "WLS":position.WLS, "positionCode":position.POSN_CODE}
139136
return json.dumps(positionDict)
140137

141138
@main_bp.route("/laborstatusform/getstudents/<termCode>/<student>", methods=["POST"])
@@ -170,7 +167,6 @@ def checkTotalHours(termCode, student, hours):
170167
((FormHistory.status == "Approved") | (FormHistory.status == "Pending"))
171168
)
172169
term = Term.get(Term.termCode == termCode)
173-
print("yeet", positions)
174170
totalHours = 0
175171
for item in positions:
176172
formID = item.formID
@@ -201,7 +197,6 @@ def releaseAndRehire():
201197

202198
# Create new labor status form
203199
student = Student.get(Student.ID == studentDict['stuBNumber'])
204-
print("## app/controllers/mainroutes/releaseandrehire##")
205200
supervisor = Supervisor.get(Supervisor.ID == studentDict['stuSupervisorID'])
206201
department, created = Department.get_or_create(DEPT_NAME = studentDict['stuDepartment'])
207202
term, created = Term.get_or_create(termCode = studentDict['stuTermCode'])

app/logic/adminManagement.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ def searchForAdmin(rsp):
1111
adminType = rsp[0]
1212
userList = []
1313
if adminType == "addlaborAdmin":
14-
print("starts1")
15-
print("##need to work on this there is a chance we need to strip the string app/logic/adminManagement/searchForAdmin##")
1614
databaseStudents = Student.select().where(Student.legal_name.contains(userInput) | Student.preferred_name.contains(userInput)| Student.LAST_NAME.contains(userInput))
1715
students = []
1816
for student in databaseStudents:
@@ -31,7 +29,6 @@ def searchForAdmin(rsp):
3129
'lastName': student.LAST_NAME,
3230
'type': 'Student'
3331
})
34-
print("#chapapa#need to work on this there is a chance we need to strip the string app/logic/adminManagement/searchForAdmin##")
3532
databaseSupervisors = Supervisor.select().where(Supervisor.legal_name.contains(userInput) | Supervisor.preferred_name.contains(userInput)| Supervisor.LAST_NAME.contains(userInput))
3633
supervisors = []
3734
for supervisor in databaseSupervisors:

app/logic/allPendingForms.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def overrideOriginalStatusFormOnAdjustmentFormApproval(form, LSF):
9090
9191
The only fields that will ever be changed in an adjustment form are: supervisor, department, position, and hours.
9292
"""
93-
print(form.adjustedForm.newValue, "heheee")
9493
currentUser = require_login()
9594
if not currentUser: # Not logged in
9695
return render_template('errors/403.html'), 403
@@ -107,14 +106,9 @@ def overrideOriginalStatusFormOnAdjustmentFormApproval(form, LSF):
107106

108107
if form.adjustedForm.fieldAdjusted == "position":
109108
LSF.POSN_CODE = form.adjustedForm.newValue
110-
position = (
111-
FormHistory
112-
.select(FormHistory, LaborStatusForm, Department)
113-
.join(LaborStatusForm, on=(FormHistory.formID == LaborStatusForm.laborStatusFormID))
114-
.join(Department, on=(LaborStatusForm.department == Department.departmentID))
115-
.where(LaborStatusForm.POSN_CODE == form.adjustedForm.newValue)
116-
.get_or_none()
117-
)
109+
position = LaborStatusForm.get_or_none(
110+
LaborStatusForm.POSN_CODE == fieldsChanged[fieldName]["newValue"]
111+
)
118112
LSF.POSN_TITLE = position.POSN_TITLE
119113
LSF.WLS = position.WLS
120114
LSF.save()
@@ -292,10 +286,10 @@ def checkAdjustment(allForms):
292286
newPositionCode = allForms.adjustedForm.newValue
293287
newPosition = (
294288
LaborStatusForm
295-
.select(LaborStatusForm.POSN_CODE, LaborStatusForm.WLS, LaborStatusForm.POSN_TITLE)
289+
.select()
296290
.where(LaborStatusForm.POSN_CODE == newPositionCode)
297291
.first()
298-
)
292+
)
299293
# temporarily storing the position code and wls in new value, and position name in old value
300294
# because we want to show these information in the hmtl template.
301295
allForms.adjustedForm.newValue = newPosition.POSN_CODE +" (" + newPosition.WLS+")"

app/logic/emailHandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ def __init__(self, formHistoryKey):
7474
elif self.formHistory.adjustedForm.fieldAdjusted == "position":
7575
currentPosition = (
7676
LaborStatusForm
77-
.select(LaborStatusForm.POSN_CODE, LaborStatusForm.POSN_TITLE, LaborStatusForm.WLS)
77+
.select()
7878
.where(LaborStatusForm.POSN_CODE == self.formHistory.adjustedForm.oldValue)
7979
.first()
8080
)
8181
newPosition = (
8282
LaborStatusForm
83-
.select(LaborStatusForm.POSN_CODE, LaborStatusForm.POSN_TITLE, LaborStatusForm.WLS)
83+
.select()
8484
.where(LaborStatusForm.POSN_CODE == self.formHistory.adjustedForm.newValue)
8585
.first()
8686
)

tests/code/test_laborStatusForm.py

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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

Comments
 (0)