Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update departments account and org from Tracy. #406

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/logic/tracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def getDepartments(self):
return STUPOSN.query.with_entities(STUPOSN.ORG, STUPOSN.DEPT_NAME, STUPOSN.ACCOUNT) \
.distinct().order_by(STUPOSN.DEPT_NAME).all()

def getDepartmentsFromName(self, deptName):
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might consider correcting the name of the function. getDepartmentsFromName implies that you are getting multiple departments, which is not true.

Return a list of departments, ordered by department name.
"""
return STUPOSN.query.with_entities(STUPOSN.ORG, STUPOSN.DEPT_NAME, STUPOSN.ACCOUNT) \
.filter(STUPOSN.DEPT_NAME == deptName).first()

def getPositionsFromDepartment(self, departmentOrg: str, departmentAcct: str):
"""
Return a list of position objects for the given department name, sorted by position title
Expand Down
30 changes: 24 additions & 6 deletions app/logic/userInsertFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from app.models.term import *
from app.models.student import Student
from app.models.supervisor import Supervisor
from app.models.department import Department
from app.models.department import *
from flask import json, jsonify
from flask import request
Expand Down Expand Up @@ -52,28 +53,45 @@ def createUser(username, student=None, supervisor=None):

def updateDBRecords():
"""
This function will update all student and supervisor records according to
This function will update all student, supervisor and department records according to
Tracy data.
"""
studentsInDB = Student.select()
supervisorsInDB = Supervisor.select()
departmentsInDB = Department.select()
studentsUpdated = 0
studentsFailed = 0
supervisorsUpdated = 0
supervisorsFailed = 0
departmentsUpdated = 0
departmentsFailed = 0

for student in studentsInDB:
try:
updateStudentRecord(student)
studentsUpdated = studentsUpdated + 1
studentsUpdated +=1
except Exception as e:
studentsFailed = studentsFailed + 1
studentsFailed +=1
for supervisor in supervisorsInDB:
try:
updateSupervisorRecord(supervisor)
supervisorsUpdated = supervisorsUpdated + 1
supervisorsUpdated +=1
except Exception as e:
supervisorsFailed = supervisorsFailed + 1
return studentsUpdated, studentsFailed, supervisorsUpdated, supervisorsFailed
supervisorsFailed +=1
for department in departmentsInDB:
try:
updateDepartment(department)
departmentsUpdated +=1
except:
departmentsFailed +=1

return studentsUpdated, studentsFailed, supervisorsUpdated, supervisorsFailed, departmentsUpdated, departmentsFailed

def updateDepartment(department):
tracyDept = Tracy().getDepartmentsFromName(department.DEPT_NAME)
department.ACCOUNT = tracyDept.ACCOUNT
department.ORG = tracyDept.ORG
department.save()

def updateUserFromTracy(user):
"""
Expand Down
8 changes: 8 additions & 0 deletions database/demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@
"DEPT_NAME":"Computer Science"
},
{
"POSN_CODE": "S10000",
"POSN_TITLE": "Reader",
"WLS": "1",
"ORG" : "2123",
"ACCOUNT":"6123",
"DEPT_NAME":"English"
},
{
"POSN_CODE": "S61408",
"POSN_TITLE": "Research Associate",
"WLS": "5",
Expand Down
2 changes: 1 addition & 1 deletion tests/code/test_tracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_getPositionsFromDepartment(self, tracy):
@pytest.mark.integration
def test_getDepartments(self, tracy):
departments = tracy.getDepartments()
assert ['Biology','Computer Science','Mathematics','Technology and Applied Design'] == [d.DEPT_NAME for d in departments]
assert ['Biology','Computer Science','English','Mathematics','Technology and Applied Design'] == [d.DEPT_NAME for d in departments]
assert '2107' == departments[0].ORG
assert '6740' == departments[0].ACCOUNT

Expand Down
9 changes: 8 additions & 1 deletion tests/code/test_userInsertFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from app.models import mainDB
from app.models.student import Student
from app.models.supervisor import Supervisor
from app.models.department import Department
from app.models.Tracy import db
from app.models.Tracy.studata import STUDATA
from app.logic.tracy import Tracy
Expand Down Expand Up @@ -205,7 +206,7 @@ def test_updateStudentFromTracy():
dbuser.student.save()

@pytest.mark.integration
def test_updateStudentDBRecords():
def test_updateDBRecords():
with mainDB.atomic() as transaction:
incorrectStudent = Student.create(ID="B00751360", PIDM=2345, FIRST_NAME="NotTyler", LAST_NAME="Parton")
updateRecordIncorrectly = Supervisor.update(FIRST_NAME="NotMadina").where(Supervisor.ID == "B00769499").execute()
Expand All @@ -216,4 +217,10 @@ def test_updateStudentDBRecords():
assert incorrectStudent.FIRST_NAME == "Tyler"
assert incorrectSupervisor.FIRST_NAME == "Madina"

incorrectDepartment = Department.create(DEPT_NAME="English", ACCOUNT="0000", ORG="0000", departmentCompliance = 1)
updateDepartment(incorrectDepartment)

assert "0000" != incorrectDepartment.ACCOUNT
assert "0000" != incorrectDepartment.ORG

transaction.rollback()
8 changes: 5 additions & 3 deletions updateStudentRecords.py → updateDBRecords.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from app.logic.userInsertFunctions import updateDBRecords

studentsUpdated, studentsFailed, supervisorsUpdated, supervisorsFailed = updateDBRecords()
studentsUpdated, studentsFailed, supervisorsUpdated, supervisorsFailed, departmentsUpdated, departmentsFailed = updateDBRecords()
print("Students updated: " + str(studentsUpdated))
print("Students failed: " + str(studentsFailed))
print("Supervisors updated: " + str(supervisorsUpdated))
print("Supervisors failed: " + str(supervisorsFailed))
print("Total updates: " + str(studentsUpdated + supervisorsUpdated))
print("Total fails: " + str(studentsFailed + supervisorsFailed))
print("Departments Updated: " + str(departmentsUpdated))
print("Departments Failed: " + str(departmentsFailed))
print("Total updates: " + str(studentsUpdated + supervisorsUpdated + departmentsUpdated))
print("Total fails: " + str(studentsFailed + supervisorsFailed + departmentsFailed))