コード例 #1
0
def testValidateStudent():
    """
      Testing method for validate
      Feature 1 - add a student
      Task2 - Validate Student
    """
    val = StudentValidator()
    #student invalid if id is empty
    st = Student("", "Ion", Address("Adr", 1, "Cluj"))
    try:
        val.validate(st)
        assert False
    except ValidationException:
        assert True

    #student invalid if name is empty
    st = Student("3", "", Address("Adr", 1, "Cluj"))
    try:
        val.validate(st)
        assert False
    except ValidationException:
        assert True

    #student invalid if adr is empty
    st = Student("3", "Ion", Address("", 1, "Cluj"))
    try:
        val.validate(st)
        assert False
    except ValidationException:
        assert True
コード例 #2
0
ファイル: file.py プロジェクト: ot3107487/FP--py-
def testGetStudentGrades():
    """
     Test function for getForDisc
    """
    rep = GradeFileRepository("testgrade.txt")
    rep.removeAll()

    st = Student("1", "Ion", Address("Adr", 1, "Cluj"))
    gr = Grade(st, "FP", 10)
    rep.store(gr)
    gr = Grade(st, "SO", 9.5)
    rep.store(gr)

    studentGrades = rep.getAllForDisc("FP")
    assert len(studentGrades) == 1
    assert studentGrades[0].getStudentID() == "1"
    assert studentGrades[0].getGrade() == 10
    assert studentGrades[0].getDiscipline() == "FP"

    st = Student("2", "Ionel", Address("Adr2", 22, "Cluj"))
    gr = Grade(st, "SO", 9.5)
    rep.store(gr)
    studentGrades = rep.getAllForDisc("SO")
    assert len(studentGrades) == 2
    assert studentGrades[0].getStudentID() == "1"
    assert studentGrades[1].getStudentID() == "2"
コード例 #3
0
def testValidateGrade():
    st = Student("1", "Ion", Address("Adr", 1, "Cluj"))
    gr = Grade(st, "FP", 11)
    val = GradeValidator()
    try:
        val.validate(gr)
        assert False
    except ValidationException:
        assert True
コード例 #4
0
ファイル: inmemory.py プロジェクト: ot3107487/FP--py-
def testGetGrades():
    st = Student("1", "Ion", Address("Adr", 1, "Cluj"))
    gr = Grade(st, "FP", 10)
    rep = GradeRepository()
    rep.store(gr)
    gr = Grade(st, "SO", 9.5)
    rep.store(gr)
    grades = rep.getAll(st)
    assert grades[0].getStudent() == st
    assert grades[0].getGrade() == 10
    assert grades[0].getDiscipline() == "FP"
コード例 #5
0
ファイル: inmemory.py プロジェクト: ot3107487/FP--py-
def testDeleteStudent():
    """
      Test function for delete
      Feature 2 - delete student
      Task 1 - remove student from the repository
    """
    rep = StudentRepository()
    st = Student("1", "Ion", Address("Adr", 1, "Cluj"))
    rep.store(st)
    st = Student("2", "Ion2", Address("Adr2", 1, "Cluj"))
    rep.store(st)
    assert rep.size() == 2
    rep.remove("1")
    assert rep.size() == 1
    #try to remove an inexistent student
    try:
        rep.remove("3")
        assert False
    except ValueError:
        assert True
コード例 #6
0
ファイル: inmemory.py プロジェクト: ot3107487/FP--py-
def testUpdate():
    """
     test function for update
     Feature 4 - update a student information
     Task 1 - update student in the repository
    """
    rep = StudentRepository()
    st = Student("1", "Ion", Address("Adr", 1, "Cluj"))
    rep.store(st)
    st = Student("1", "Ionel", Address("Addrr", 1, "Cluj"))
    rep.update("1", st)
    sts = rep.getAll()
    assert rep.find("1").getName() == "Ionel"
    assert rep.find("1").getAdr().getStreet() == "Addrr"

    #use case for a wrong id
    try:
        rep.update("2", st)
        assert False
    except ValueError:
        assert True
コード例 #7
0
ファイル: inmemory.py プロジェクト: ot3107487/FP--py-
def testStoreStudent():
    """
      test function for store
      Feature 1 - add a student
      Task 3 - Store Student
    """
    st = Student("1", "Ion", Address("Adr", 1, "Cluj"))
    rep = StudentRepository()
    assert rep.size() == 0
    rep.store(st)
    assert rep.size() == 1
    st2 = Student("2", "Vasile", Address("Adr2", 1, "Cluj"))
    rep.store(st2)
    assert rep.size() == 2
    #can not store 2 students with the same id
    st3 = Student("2", "Ana", Address("Adr3", 1, "Cluj"))
    try:
        rep.store(st3)
        assert False
    except DuplicatedIDException:
        pass
コード例 #8
0
ファイル: file.py プロジェクト: ot3107487/FP--py-
def testStore():
    fileName = "teststudent.txt"
    repo = StudentFileRepository(fileName)
    repo.removeAll()

    st = Student("1", "Ion", Address("str", 3, "Cluj"))
    repo.store(st)
    assert repo.size() == 1
    assert repo.find("1") == st
    #verify if the student is stored in the file
    repo2 = StudentFileRepository(fileName)
    assert repo2.size() == 1
    assert repo2.find("1") == st
コード例 #9
0
ファイル: inmemory.py プロジェクト: ot3107487/FP--py-
def testListStudent():
    """
      test function for getAll
      Feature 3 - List students for a criteria
      Task 1 - retrieve all the students from the repository
    """
    rep = StudentRepository()
    st = Student("1", "Ion", Address("Adr", 1, "Cluj"))
    rep.store(st)
    st = Student("2", "Ion2", Address("Adr2", 1, "Cluj"))
    rep.store(st)

    all = rep.getAll()
    assert len(all) == 2
    st1 = rep.find("1")
    assert st1.getId() == "1"
    assert st1.getName() == "Ion"
    assert st1.getAdr().getStreet() == "Adr"
    st2 = rep.find("2")
    assert st2.getId() == "2"
    assert st2.getName() == "Ion2"
    assert st2.getAdr().getStreet() == "Adr2"
コード例 #10
0
ファイル: controllers.py プロジェクト: ot3107487/FP--py-
 def create(self, id, name, street, nr, city):
     """
       Create validate and store a student
       id,name, street,city- strings
       nr - int
       return Student
       raise ValueEror if the data is invalid, on duplicated id
     """
     #create Student instance
     st = Student(id, name, Address(street, nr, city))
     #validate, raise exception if student is invalid
     self.__val.validate(st)
     #store the student, raise exception if duplicated id
     self.__repo.store(st)
     return st
コード例 #11
0
ファイル: inmemory.py プロジェクト: ot3107487/FP--py-
def testStoreGrade():
    st = Student("1", "Ion", Address("Adr", 1, "Cluj"))
    gr = Grade(st, "FP", 9.5)
    rep = GradeRepository()
    assert rep.size() == 0
    rep.store(gr)
    assert rep.size() == 1
    gr2 = rep.find(st, "FP")
    assert gr2 == gr

    gr = Grade(st, "FP", 9)
    try:
        rep.store(gr)
        assert False
    except GradeAlreadyAssigned:
        assert True
コード例 #12
0
ファイル: controllers.py プロジェクト: ot3107487/FP--py-
    def update(self, id, name, street, nr, city):
        """
          Update student with the given id
          id,name, adr strings
          return the old student
          raise ValueError if the student is invalid, if there is no student with the given id
        """
        newSt = Student(id, name, Address(street, nr, city))

        #validate the student
        self.__val.validate(newSt)

        #get the old student
        oldSt = self.__repo.find(id)

        #update the student
        self.__repo.update(id, newSt)
        return oldSt
コード例 #13
0
ファイル: file.py プロジェクト: ot3107487/FP--py-
 def __loadFromFile(self):
     """
       Load students from file
       raise CorruptedFileException if there is an error when reading from the file
     """
     try:
         f = open(self.__fName, "r")
     except IOError:
         #file not exist
         return
     line = f.readline().strip()
     rez = []
     while line != "":
         attrs = line.split(";")
         st = Student(attrs[0], attrs[1],
                      Address(attrs[2], attrs[3], attrs[4]))
         rez.append(st)
         line = f.readline().strip()
     f.close()
     return rez