예제 #1
0
 def test_updateElement_with1emptyField_elementUpdated1fieldUnchanged(self):
     repository = Repository()
     movie = Movie(1, 'Frozen', 'Ice queen with magical powers',
                   'Animation')
     repository.add(movie)
     repository.update(movie, Movie(1, '', 'a', 'b'))
     expected_result = Movie(1, 'Frozen', 'a', 'b')
     self.assertTrue(repository.get_all()[0].identical(expected_result))
예제 #2
0
 def test_updateElement_withAllFields_elementUpdated(self):
     repository = Repository()
     movie = Movie(1, 'Frozen', 'Ice queen with magical powers',
                   'Animation')
     repository.add(movie)
     movieUpdate = Movie(1, '-', '-', '-')
     repository.update(movie, movieUpdate)
     self.assertTrue(repository.get_all()[0].identical(movieUpdate))
예제 #3
0
    def _saveFile(self):
        '''
        1. Open text file for writing 'w'
        2. for each element in the repository:
            a. transform it into one-line string
            b. write it to the file
        3. close file
        '''
        filepath = self._fileName
        file = open(filepath, 'wb')

        for element in Repository.get_all(self):
            pickle.dump(element, file)

        file.close()
    def all_students(self, discipline_id):
        """
        This function returns a repository that contains all the students that have a grade at the given discipline
        :param discipline_id: The id of the discipline
        :return: A Repository containing the students sorted by student name
        """
        full = self.__repository.get_all()
        new = Repository()
        for i in full:
            if i.discipline_id == discipline_id:
                ret = new.get_all()
                s = self.__studentRepository.find(i.student_id)
                if s not in ret:
                    new.store(s)

        return new.sort_()
예제 #5
0
 def get(self, training=None):
     training = training or Training()
     parts = Participants()
     org = Organization()
     sched = Schedules()
     when = When()
     costs = Costs()
     list_catg = [(item.value, item.name) for item in CategoryType]
     with Session(database='training') as session:
         repo = Repository(session)
         operator = repo.get_all(coll_name='organization', conditions={},
                                 projection={'org_identity': 1, 'org_name': 1, '_id': 0})
     list_op = [(item['org_identity'], item['org_name']) for item in operator]
     return self.render_response("training/add.html",
                                 training=training,
                                 list_catg=list_catg,
                                 list_op=list_op,
                                 parts=parts,
                                 org=org,
                                 sched=sched,
                                 when=when,
                                 costs=costs)
예제 #6
0
 def test_add_newMovie_movieIsAdded(self):
     movie = Movie(1, 'a', 'a', 'a')
     repo = Repository()
     repo.add(movie)
     self.assertEqual(repo.size(), 1)
     self.assertEqual(repo.get_all()[repo.size() - 1], movie)
예제 #7
0
 def get_all(self):
     self.__read_all_from_file()
     return Repository.get_all(self)