Ejemplo n.º 1
0
def testCreateStudent():
    """
     test function for create student
     Feature 1 - add a student
     Task 4 - Create student - controller
    """
    #create the controller and inject the validator and repository
    ctr = StudentController(StudentValidator(), StudentRepository())
    st = ctr.create("1", "Ion", "Adr", 1, "Cluj")
    assert st.getId() == "1"
    assert st.getName() == "Ion"
    assert st.getAdr().getStreet() == "Adr"
    assert ctr.getNrStudents() == 1
    #test for an invalid student
    try:
        ctr.create("1", "", "", 1, "Cluj")
        assert False
    except ValidationException:
        assert True
    #test for duplicated id
    try:
        ctr.create("1", "Ion2", "Adr2", 1, "Cluj")
        assert False
    except DuplicatedIDException:
        assert True
Ejemplo n.º 2
0
def testUpdate():
    """
     test function for update
     Feature 4 - update a student information
     Task 2 - update student - controller
    """
    ctr = StudentController(StudentValidator(), StudentRepository())
    st = ctr.create("1", "Ion", "Adr", 1, "Cluj")
    st = ctr.update("1", "Ionel", "Addrr", 1, "Cluj")

    studs = ctr.search("Ionel")
    assert len(studs) == 1
    assert studs[0].getAdr().getStreet() == "Addrr"
    #verify if the old student is returned
    assert st.getName() == "Ion"
    assert st.getAdr().getStreet() == "Adr"

    #try to opdate an inexistend student
    try:
        st = ctr.update("2", "Ionel", "Addrr", 1, "Cluj")
        assert False
    except ValueError:
        assert True

    #try to update to invalid data
    try:
        ctr.update("1", "", "", 1, "Cluj")
        assert False
    except ValidationException:
        assert True
Ejemplo n.º 3
0
def testListFirst5():
    stRep = StudentRepository()
    stctr = StudentController(StudentValidator(), stRep)
    st = stctr.create("1", "Ion", "Adr", 1, "Cluj")
    st = stctr.create("2", "Ion2", "Adr", 1, "Cluj")
    st = stctr.create("3", "Ion3", "Adr", 1, "Cluj")
    st = stctr.create("4", "Ion4", "Adr", 1, "Cluj")
    st = stctr.create("5", "Ion5", "Adr", 1, "Cluj")
    st = stctr.create("6", "Ion6", "Adr", 1, "Cluj")

    ctr = GradeController(GradeRepository(), GradeValidator(), stRep)
    gr = ctr.assign("1", "FP", 9.5)
    gr = ctr.assign("2", "FP", 7)
    gr = ctr.assign("3", "FP", 8)
    gr = ctr.assign("4", "FP", 10)
    gr = ctr.assign("5", "FP", 6)
    gr = ctr.assign("6", "FP", 9)

    stgrs = ctr.getTop5("FP")
    assert len(stgrs) == 5
    assert stgrs[0].getStudentID() == "4"
    assert stgrs[1].getStudentID() == "1"
    assert stgrs[2].getStudentID() == "6"
    assert stgrs[3].getStudentID() == "3"
    assert stgrs[4].getStudentID() == "2"
Ejemplo n.º 4
0
def testSearchCriteria():
    """
      test first search
      Feature 3 - List students for a criteria
      Task 2 - all students where the name contains a given string
    """
    rep = StudentRepository()
    ctr = StudentController(StudentValidator(), rep)
    st = ctr.create("1", "Ion", "Adr", 1, "Cluj")
    st2 = ctr.create("2", "Ion2", "Adr", 1, "Cluj")
    st = ctr.create("3", "Ioana1", "Adr", 1, "Cluj")
    st4 = ctr.create("4", "Ioana2", "Adr", 1, "Cluj")
    st = ctr.create("5", "Vlad", "Adr", 1, "Cluj")

    studs = ctr.search("Ion")
    assert len(studs) == 2
    assert st2 in studs

    studs = ctr.search("Io")
    assert len(studs) == 4
    assert st4 in studs

    studs = ctr.search("Al")
    assert len(studs) == 0

    #for empty string
    studs = ctr.search("")
    assert len(studs) == 5
Ejemplo n.º 5
0
def testAssignGrade():
    stRep = StudentRepository()
    stctr = StudentController(StudentValidator(), stRep)
    st = stctr.create("1", "Ion", "Adr", 1, "Cluj")
    ctr = GradeController(GradeRepository(), GradeValidator(), stRep)

    gr = ctr.assign("1", "FP", 10)
    assert gr.getDiscipline() == "FP"
    assert gr.getGrade() == 10
    assert gr.getStudent().getId() == "1"
    assert gr.getStudent().getName() == "Ion"
Ejemplo n.º 6
0
def testListGrade():
    stRep = StudentRepository()
    stctr = StudentController(StudentValidator(), stRep)
    st = stctr.create("1", "Ion", "Adr", 1, "Cluj")

    ctr = GradeController(GradeRepository(), GradeValidator(), stRep)
    gr = ctr.assign("1", "FP", 10)
    grs = ctr.listGrades("1")
    assert len(grs) == 1
    gr = ctr.assign("1", "SO", 10)
    grs = ctr.listGrades("1")
    assert len(grs) == 2
Ejemplo n.º 7
0
def testRemoveStudent():
    """
      Test function for remove
      Feature 2 - remove student
      Task 2 - remove student controller
    """
    ctr = StudentController(StudentValidator(), StudentRepository())
    st = ctr.create("1", "Ion", "Adr", 1, "Cluj")
    #test for an invalid id
    try:
        ctr.remove("2")
        assert False
    except ValueError:
        assert True
    assert ctr.getNrStudents() == 1

    st = ctr.remove("1")
    assert ctr.getNrStudents() == 0
    assert st.getId() == "1"
    assert st.getName() == "Ion"
    assert st.getAdr().getStreet() == "Adr"
Ejemplo n.º 8
0
"""
import traceback

from console.console import Console
from controller.GradeController import GradeController
from controller.StudentController import StudentController
from controller.UndoController import UndoController
from domain.validators import GradeValidator, StudentValidator
from repository.GradeRepo import GradeRepo
from repository.StudentRepo import StudentRepo

if __name__ == '__main__':
    print("App started running.")

    grade_validator = GradeValidator()
    student_validator = StudentValidator()

    grade_repo = GradeRepo(grade_validator)
    student_repo = StudentRepo(student_validator)

    grade_controller = GradeController(grade_repo)
    student_controller = StudentController(student_repo)
    undo_controller = UndoController(student_controller, grade_controller)

    console = Console(student_controller, grade_controller, undo_controller)

    try:
        console.run()
    except Exception:
        print("An error accured.")
        traceback.print_exc()
Ejemplo n.º 9
0
from domain.validators import StudentValidator
from domain.validators import GradeValidator
from repository.inmemory import StudentRepository
from repository.inmemory import GradeRepository
from repository.file import StudentFileRepository
from repository.file import GradeFileRepository
from controllers.controllers import StudentController
from controllers.controllers import GradeController

from ui.console import ConsoleUI

#Application coordinator
#Use dependency injection pattern to asemble the application

#create a validator
val = StudentValidator()

#create repository
# repo = StudentRepository()

repo = StudentFileRepository("students.txt")

#create controller and inject dependencies
ctr = StudentController(val, repo)

#create Grade controller
#gradeRepo = GradeRepository()
gradeRepo = GradeFileRepository("grades.txt")

ctrgr = GradeController(gradeRepo, GradeValidator(), repo)