def setUp(self):
        self.repo = Repository()
        self.brepo = Repository()
        self.crepo = Repository()
        self.Ucontroller = UndoController()
        self.book = Book(21, 'titlu', 'descriere', 'author')
        self.book2 = Book(22, 'titlu2', 'descriere2', 'author')
        self.brepo.add(self.book)
        self.brepo.add(self.book2)
        self.client = Client(23, 'alex')
        self.client2 = Client(24, 'ana')
        self.client3 = Client(29, 'ana')

        self.crepo.add(self.client)
        self.crepo.add(self.client2)
        self.rental = Rental(21236, 21, 24, date(2017, 11, 5),
                             date(2017, 12, 6), date(2017, 12, 5))
        self.rental2 = Rental(21238, 22, 24, date(2017, 11, 5),
                              date(2017, 12, 6), date(2017, 12, 5))
        self.rental3 = Rental(21238, 23, 24, date(2017, 11, 5),
                              date(2017, 12, 6), date(2017, 12, 5))
        self.rental4 = Rental(21238, 21, 29, date(2017, 11, 5),
                              date(2017, 12, 6), date(2017, 12, 5))
        self.rental5 = Rental(21231, 21, 23, date(2017, 11, 5),
                              date(2017, 10, 6), None)

        self.controller = RentalController(self.repo, self.brepo, self.crepo,
                                           self.Ucontroller)
        self.ceva = LateRentalCount(12, 32)
        self.altceva = BookRentalCount(12, 23)
        self.nu = AuthorRentalCount('da', 23)
        self.da = ClientRentalCount(32, 12)
示例#2
0
    def setUp(self):
        unittest.TestCase.setUp(self)
        undoController = UndoController()

        self.rentalList = Repository()
        self.bookList = Repository()
        self.clientList = Repository()

        self.rentalList.add(
            Rental(0, 0, 1, datetime.datetime.strptime("2017-10-10",
                                                       '%Y-%m-%d'),
                   datetime.datetime.strptime("2017-10-20", '%Y-%m-%d'), ""))
        self.rentalList.add(
            Rental(1, 1, 1, datetime.datetime.strptime("2017-10-10",
                                                       '%Y-%m-%d'),
                   datetime.datetime.strptime("2017-10-20", '%Y-%m-%d'), ""))

        self.bookList.add(Book(0, "book0", "desc0", "author0"))
        self.bookList.add(Book(1, "book1", "desc1", "author1"))
        self.bookList.add(Book(2, "book2", "desc2", "author2"))

        self.clientList.add(Client(0, "name0"))
        self.clientList.add(Client(1, "name1"))
        self.clientList.add(Client(2, "name2"))

        self.rentalController = RentalController(self.rentalList,
                                                 self.bookList,
                                                 self.clientList,
                                                 undoController)
        self.bookController = BookController(self.bookList, undoController,
                                             self.rentalController)
        self.clientController = ClientController(self.clientList,
                                                 undoController,
                                                 self.rentalController)
    def testRentBook(self):
        client1 = Client(1, "Name1")
        client2 = Client(2, "Name2")

        book1 = Book(1, "Title", "Description", "Author")
        book2 = Book(2, "Title1", "Description1", "Author1")

        clientRepo = Repository()
        bookRepo = Repository()
        functions = ClientController(clientRepo, Statistics(clientRepo))
        functiom = BookController(bookRepo, Statistics(bookRepo))

        functions.addClient(client2.getId(), client2.getName())
        functions.addClient(client1.getId(), client1.getName())

        functiom.addBook(book1.getId(), book1.getTitle(), book1.getDescription(), book1.getAuthor())
        functiom.addBook(book2.getId(), book2.getTitle(), book2.getDescription(), book2.getAuthor())
        rentalRepo = Repository()
        functionsr = RentalController(bookRepo, clientRepo, rentalRepo, Statistics(rentalRepo))

        msg1 = functionsr.rentBook(book1.getId(), client1.getId(), createDateFromString("23.11.2017"), "30.11.2017")

        self.assertTrue(len(msg1) == 0)
        self.assertTrue(functionsr.getRentals()[0].getBookId() == book1.getId())
        self.assertTrue(functionsr.getRentals()[0].getClientId() == client1.getId())

        msg2 = functionsr.rentBook(book2.getId, client2.getId(), createDateFromString("20.11.2017"), "19.11.2017")
        self.assertTrue(msg2 == "Inconsistent dates")
示例#4
0
    def setUp(self):
        self.person_repository = Repository(PersonValidator)
        self.person_controller = PersonController(self.person_repository)

        self.activity_repository = Repository(ActivityValidator)
        self.activity_controller = ActivityController(self.activity_repository)

        self.repository = Repository(ParticipationValidator)
        self.controller = ParticipationController(self.repository,
                                                  self.person_controller,
                                                  self.activity_controller)

        # add test data
        self.person_controller.add(1, "John", "1234567890", "street 1")
        self.person_controller.add(2, "John", "1234567890", "street 1")
        self.person_controller.add(3, "John", "1234567890", "street 1")

        self.activity_controller.add(1, Common.convert_to_date("15.11.2016"),
                                     Common.convert_to_time("06:03"),
                                     "description")
        self.activity_controller.add(2, Common.convert_to_date("16.11.2016"),
                                     Common.convert_to_time("06:03"),
                                     "description")
        #self.activity_controller.add(3,Common.convert_to_date("16.11.2016"),Common.convert_to_time("06:04"),"description")
        #self.activity_controller.add(4,Common.convert_to_date("16.11.2016"),Common.convert_to_time("06:06"),"description")

        return super().setUp()
示例#5
0
 def __init__(self):
     pass
     repository = Repository()
     pulls = Pulls()
     repos_url = response['pull_request']['head']['repo']['url']
     pulls_url = response['pull_request']['url']
     files_url = pulls_url + '/files'
     #user = response["pull_request"]["user"]["login"]
     #contributor_url =repos_url + TestData.contributor_parameter
     repo_name = response['pull_request']['head']['repo']['name']
     owner_name = response['pull_request']['head']['repo']['owner']['login']
     last_page = Utils().pagination(owner_name, repo_name)
     feature_dict.update(Repository().open_pr_count(repos_url, last_page))
     #print(pulls.changed_lines_in_file(files_url))
     feature_dict['forks_count'] = response['pull_request']['head']['repo']['forks_count']
     feature_dict['commits'] = response['pull_request']['commits']
     feature_dict['changed_files'] = response['pull_request']['changed_files']
     feature_dict.update(repository.pushed_time(response['pull_request']['head']['repo']['pushed_at']))
     feature_dict['watchers_count'] = response['pull_request']['head']['repo']['watchers_count']
     feature_dict['open_issue_count'] = response['pull_request']['head']['repo']['open_issues_count']
     feature_dict.update(Pulls().pull_request_size(response["pull_request"]))
     parameter_dict = {}
     parameter_dict['feature_dict'] = feature_dict
     parameter_dict['comment_url'] = comment_url
     return parameter_dict
 def setUp(self):
     self.repo = Repository()
     self.rentalRepo = Repository()
     self.Ucontroller = UndoController()
     self.client = Client(11, 'alex')
     self.client2 = Client(12, 'ana')
     self.controller = ClientController(self.repo, self.Ucontroller,
                                        self.rentalRepo)
示例#7
0
 def setUp(self):
     self.repo = Repository()
     self.rentalRepo = Repository()
     self.Ucontroller = UndoController()
     self.book = Book(21, 'titlu', 'descriere', 'author')
     self.book2 = Book(22, 'titlu2', 'descriere2', 'author2')
     self.controller = BookController(self.repo, self.Ucontroller,
                                      self.rentalRepo)
示例#8
0
 def setUp(self):
     super().setUp()
     self.__student_repository = Repository(StudentValidator)
     self.__student_controller = StudentController(
         self.__student_repository)
     self.__discipline_repository = Repository(DisciplineValidator)
     self.__discipline_controller = DisciplineController(
         self.__discipline_repository)
     self.__grade_repository = Repository(GradeValidator)
     self.__grade_controller = GradeController(self.__grade_repository,
                                               self.__student_repository,
                                               self.__discipline_repository)
示例#9
0
    def testRental(self):
        repo = Repository()
        book1 = Book(1, "ala", "mala", "dala")

        rentList = Repository()
        rentList.addElement(Rental(2, book1, 0))

        lis1 = rentList.getElementList()
        self.assertEqual(len(lis1), 1)

        rentList.addElement(Rental(2, book1, 1))
        lis1 = rentList.getElementList()
        self.assertEqual(len(lis1), 2)
        self.assertEqual(lis1[0].getRenterId(), 2)
        self.assertEqual(lis1[0].getRentedBook(), book1)
        self.assertEqual(lis1[0].getId(), 0)
示例#10
0
    def __test_repo():
        """
        Function to test repository
        :return:
        """
        val = BookValidator()
        repo = Repository(val)
        b = Book("Ion", "Liviu Rebreanu", "Drama", 1912)
        b.set_id(0)
        repo.store_book(b)
        assert len(repo.get_all()) == 1
        b.set_id(2)
        repo.store_book(b)

        assert len(repo.get_all()) == 2
        assert repo.search_book(1) is not None
        assert repo.search_book(2) is None
        assert repo.delete_book(1) is not None
        assert repo.delete_book(1) is None

        b.set_id(2)
        repo.store_book(b)
        assert len(repo.get_all()) == 2
        b.set_year(2018)
        assert repo.update_book(1, b) is not None
        assert repo.update_book(2, b) is None
        b1 = repo.search_book(1)
        assert b1.get_year() == 2018

        try:
            repo.store_book(b)
            assert False
        except RepositoryException:
            assert True
示例#11
0
    def __init__(self, **kwargs):
        self.host = kwargs.get('host')
        self.database = kwargs.get('database')

        self.db = Repository(self.host, self.database)
        self.recipes = self.db.get_collection(kwargs.get('recipes'))
        self.combinations = self.db.get_collection(kwargs.get('combinations'))
示例#12
0
    def test_get_repo_probability(self, mock_get, mock_response):
        '''Test for Repository class inside repository package'''
        mock_reponses = []
        mock_res = RepositoryTest.MockResponse([{'state':'closed',
                                                 "merged_at":'2018-08-29T20:05:38Z'}], 200)
        type(mock_response).return_value = mock.PropertyMock(
            return_value=mock_res)
        type(mock_get).return_value = mock.PropertyMock(
            return_value=type(mock_response).return_value)
        mock_reponses.append(type(mock_get).return_value)

        mock_res = RepositoryTest.MockResponse([{'state':'closed', "merged_at":None}], 200)
        type(mock_response).return_value = mock.PropertyMock(return_value=mock_res)
        type(mock_get).return_value = mock.PropertyMock(
            return_value=type(mock_response).return_value)
        mock_reponses.append(type(mock_get).return_value)
        mock_get.side_effect = mock_reponses
        mock_res = RepositoryTest.MockResponse([{'state':'closed',
                                                 "merged_at":'2018-08-29T20:05:38Z'}], 200)
        type(mock_response).return_value = mock.PropertyMock(return_value=mock_res)
        type(mock_get).return_value = mock.PropertyMock(
            return_value=type(mock_response).return_value)
        mock_reponses.append(type(mock_get).return_value)
        mock_get.side_effect = mock_reponses
        response_push = Repository().get_repo_probability('3', RepositoryTest.repos_url)
        self.assertEqual(response_push, {'pull_request_acceptance_rate': 66.66666666666666})
示例#13
0
def runTest1():
    repo = Repository("test1.txt")
    service = Service(repo)
    c = service.simulate(20, 10, 30)
    assert (c.get_genes() == [0, 1, 2, 3, 0])
    assert (c.get_distance() == 4)
    assert (c.fitness() == 1 / c.get_distance())
示例#14
0
    def testBookController(self):
        repo = Repository()
        controller = BookController(repo)
        undoController = Undo()
        controller.addUndoController(undoController)

        self.assertEqual(controller.addBook(Book(1, "ala", "mala", "dala")),
                         True)
        self.assertNotEqual(controller.searchById(1), False)

        found = controller.searchById(1)
        self.assertEqual(found, Book(1, "ala", "mala", "dala"))
        self.assertEqual(controller.searchByTitle("ala"),
                         Book(1, "ala", "mala", "dala"))

        self.assertNotEqual(
            controller.modifyBookAuthor(Book(1, "ala", "mala", "dala"),
                                        "Mercan"), False)

        self.assertEqual(
            controller.modifyBookTitle(Book(1, "ala", "mala", "Mercan"),
                                       "Newt"), True)
        self.assertEqual(controller.findExistingId(1), True)

        self.assertEqual(
            controller.removeElement(Book(1, "Newt", "mala", "Mercan")), True)
        self.assertEqual(controller.searchById(1), False)
        self.assertEqual(controller.checkIdExists(1), False)
示例#15
0
    def testRepositoryClients(self):
        repoClient = Repository()
        client = Client(1, "Name")
        client1 = Client(2, "Name1")

        self.assertTrue(repoClient.size() == 0)
        repoClient.add(client)
        self.assertTrue(repoClient.size() == 1)
        repoClient.add(client1)

        self.assertTrue(repoClient.existsById(1))
        self.assertTrue(repoClient.existsById(2))
        self.assertTrue(repoClient.getById(1).getName() == "Name")

        repoClient.removeById(1)
        self.assertTrue(repoClient.size() == 1)
        repoClient.remove(client1)
        self.assertTrue(repoClient.size() == 0)

        self.assertTrue(repoClient.existsById(1) == False)

        repoClient.add(client)
        repoClient.update(Client(1, "Updated Name"))

        self.assertTrue(repoClient.findById(1) == 0)
        self.assertTrue(repoClient.getById(1).getName() == "Updated Name")

        self.assertTrue(str(repoClient.getById(1)) == "CLIENT ID: " + str(
            repoClient.getById(1).getId()) + "| Name: " + repoClient.getById(1).getName())
示例#16
0
def runTest2():
    repo = Repository("test2.txt")
    service = Service(repo)
    c = service.simulate(50, 10, 100)
    assert (c.get_genes() == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
    assert (c.get_distance() == 10)
    assert (c.fitness() == 1 / c.get_distance())
示例#17
0
文件: tester.py 项目: crssic/courses
 def test(self):
     x = Route(1, "24b", 93, 3)
     assert (x.getId() == 1)
     x.setId(2)
     assert (x.getId() == 2)
     assert (x.getRouteCode() == "24b")
     x.setRouteCode("24")
     assert (x.getRouteCode() == "24")
     assert (x.getUsage() == 93)
     x.setUsage(95)
     assert (x.getUsage() == 95)
     assert (x.getBuses() == 3)
     x.setBuses(x.getBuses() + 1)
     assert (x.getBuses() == 4)
     x = Route(1, "24b", 93, 3)
     repo = Repository()
     repo.add(x)
     assert (repo.getRoutes() == [Route(1, "24b", 93, 3)])
     y = Route(13, "25", 93, 7)
     repo.add(y)
     assert (repo.getRoutes() == [
         Route(1, "24b", 93, 3),
         Route(13, "25", 93, 7)
     ])
     repo.add(y)
     assert (repo.getRoutes() == [
         Route(1, "24b", 93, 3),
         Route(13, "25", 93, 7),
         Route(13, "25", 93, 7)
     ])
示例#18
0
    def testRemoveBook(self):
        book1 = Book(1, "Title", "Description", "Author")
        book2 = Book(2, "Title1", "Description1", "Author1")
        book3 = Book(3, "Title2", "Description2", "Author2")
        repo = Repository()
        functions = BookController(repo, Statistics(repo))

        functions.addBook(book1.getId(), book1.getTitle(), book1.getDescription(), book1.getAuthor())
        functions.addBook(book2.getId(), book2.getTitle(), book2.getDescription(), book2.getAuthor())
        functions.addBook(book3.getId(), book3.getTitle(), book3.getDescription(), book3.getAuthor())

        msg1 = functions.removeBook(1)

        self.assertTrue(len(msg1) == 0)
        self.assertTrue(functions.getBooks()[0].getId() == book2.getId())
        self.assertTrue(functions.getBooks()[0].getTitle() == book2.getTitle())
        self.assertTrue(functions.getBooks()[0].getDescription() == book2.getDescription())
        self.assertTrue(functions.getBooks()[0].getAuthor() == book2.getAuthor())

        msg2 = functions.removeBook(1)

        self.assertTrue(msg2 == "The provided ID does not exist")
        self.assertTrue(functions.getBooks()[0].getId() == book2.getId())
        self.assertTrue(functions.getBooks()[0].getTitle() == book2.getTitle())
        self.assertTrue(functions.getBooks()[0].getDescription() == book2.getDescription())
        self.assertTrue(functions.getBooks()[0].getAuthor() == book2.getAuthor())
示例#19
0
    def testRentalRepository(self):
        rentalRepo = Repository()
        book1 = Book(0, "The Q", "Albert", "Heinrich")
        book2 = Book(1, "The D", "Elbert", "Reinsich")
        client1 = Client(0, "Mihai", 1854987548795)
        client2 = Client(1, "Alex", 1987548759658)

        rentalRepo.addElement(Rental(1, book1, 0))
        rentalRepo.addElement(Rental(0, book2, 1))

        # _find(_id) returns the Rental from the repository
        # that has the client Id equal to _id

        self.assertEqual(rentalRepo._find(0).getRentedBook(), book1)
        self.assertEqual(rentalRepo._find(1).getId(), 1)

        self.assertEqual(rentalRepo._find(1).getRentedBook(), book2)
        self.assertEqual(rentalRepo._find(0).getId(), 0)

        # findId() function for Repository class
        self.assertEqual(rentalRepo.findId(12), False)
        self.assertEqual(rentalRepo.findId(0), True)

        # elementFromId()
        self.assertEqual(rentalRepo.elementFromId(0).getRentedBook(), book1)

        rentalRepo.addElement(Rental(1, book2, 2))
示例#20
0
 def __init__(self, **kwargs):
     self.db = Repository(kwargs.get('host'), kwargs.get('database'))
     self.recipes = self.db.get_collection(kwargs.get('recipes'))
     self.combinations = self.db.get_collection(kwargs.get('combinations'))
     self.skip = kwargs.get('skip')
     self.r_min = kwargs.get('r_min')
     self.r_max = kwargs.get('r_max')
示例#21
0
def testRentalRepository():
    rentalRepo = Repository()
    book1 = Book(0, "The Q", "Albert", "Heinrich")
    book2 = Book(1, "The D", "Elbert", "Reinsich")
    client1 = Client(0, "Mihai", 1854987548795)
    client2 = Client(1, "Alex", 1987548759658)

    rentalRepo.addElement(Rental(1, book1, 0))
    rentalRepo.addElement(Rental(0, book2, 1))

    # _find(_id) returns the Rental from the repository
    # that has the client Id equal to _id

    assert rentalRepo._find(0).getRentedBook() == book1 
    assert rentalRepo._find(1).getId() == 1

    assert rentalRepo._find(1).getRentedBook() == book2
    assert rentalRepo._find(0).getId() == 0

    # findId() function for Repository class
    assert rentalRepo.findId(12) == False
    assert rentalRepo.findId(0) == True

    # elementFromId()
    assert rentalRepo.elementFromId(0).getRentedBook() == book1

    rentalRepo.addElement(Rental(1, book2, 2)) 

    print ("Rental repository tests ran successfully!")
def runApplicationWithUndo():
    settings = Settings()
    undoController = UndoController()

    if str(settings.mode_repository) == "inmemory":
        student_repository = Repository(StudentValidator)
        discipline_repository = Repository(DisciplineValidator)
        grade_repository = Repository(GradeValidator)

    elif settings.mode_repository == "textfiles":
        student_repository = FileRepository(StudentValidator, settings.students, Student)
        discipline_repository = FileRepository(DisciplineValidator, settings.disciplines, Discipline)
        grade_repository = FileRepository(GradeValidator, settings.grades, Grade)

    elif settings.mode_repository == "binaryfiles":
        student_repository = BinaryRepository(StudentValidator, settings.students, Student)
        discipline_repository = BinaryRepository(DisciplineValidator, settings.disciplines, Discipline)
        grade_repository = BinaryRepository(GradeValidator, settings.grades, Grade)


    elif settings.mode_repository == "sqlfiles":
        student_repository = SQLRepository(StudentValidator, settings.students, Student, "Students", 1)
        discipline_repository = SQLRepository(DisciplineValidator, settings.disciplines, Discipline, "Disciplines", 1)
        grade_repository = SQLRepository(GradeValidator, settings.grades, Grade, "Grades", 2)



    elif settings.mode_repository == "jsonfiles":
        student_repository = JSONRepository(StudentValidator, settings.students, Student)
        discipline_repository = JSONRepository(DisciplineValidator, settings.disciplines, Discipline)
        grade_repository = JSONRepository(GradeValidator, settings.grades, Grade)

    else:
        print("You have to insert a valid repository mode!!!")

    student_controller = StudentController(student_repository, undoController)
    discipline_controller = DisciplineController(discipline_repository, undoController)
    grade_controller = GradeController(grade_repository, student_repository, discipline_repository, undoController)

    if settings.interface_mode == "gui":
        ui_gui = GUI(student_controller, discipline_controller, grade_controller, undoController)
        ui_gui.run_app()
    elif settings.interface_mode == "console":
        console = Console(student_controller, discipline_controller, grade_controller, undoController)
        console.runApp()
    else:
        print("You have to insert a valid interface!!!")
示例#23
0
    def testUtils(self):
        bList = []
        self.assertTrue(len(bList) == 0)
        bookRepo = Repository()
        bc = BookController(bookRepo, Statistics(bookRepo))
        bc.populateBookRepository()

        self.assertTrue(0 < len(bookRepo.getAll()) < 100)
    def __init__(self, **kwargs):
        self.host = kwargs.get('host')
        self.database = kwargs.get('database')

        self.db = Repository(self.host, self.database)
        self.collection = self.db.get_collection(kwargs.get('collection'))

        self.skip = kwargs.get("skip")
示例#25
0
    def testClientController(self):
        repo = Repository()
        contr = ClientController(repo)
        undoController = Undo()
        contr.addUndoController(undoController)

        self.assertEqual(contr.addClient(Client(1, "alice", 1111111111111)),
                         True)
示例#26
0
    def __init__(self, **kwargs):
        self.host = kwargs.get('host')
        self.database = kwargs.get('database')
        self.r_min = int(kwargs["r_min"])
        self.r_max = int(kwargs["r_max"])

        self.db = Repository(self.host, self.database)
        self.combinations = self.db.get_collection(kwargs.get('combinations'))
    def __init__(self, **kwargs):
        self.host = kwargs.get('host')
        self.neoHost = kwargs.get('neoHost')
        self.database = kwargs.get('database')
        self.resume = kwargs.get('resume')

        self.db = Repository(self.host, self.database)
        self.recipes = self.db.get_collection(kwargs.get('recipes'))
示例#28
0
 def test_forks_count(self, mock_get, mock_response):
     '''Test for Repository class inside repository package'''
     mock_res = RepositoryTest.MockResponse([{"base":{"repo":{"forks_count":371}}}], 200)
     forks_count = 371
     type(mock_response).return_value = mock.PropertyMock(return_value=mock_res)
     type(mock_get).return_value = mock.PropertyMock(
         return_value=type(mock_response).return_value)
     response_push = Repository().get_forks_count(forks_count)
     self.assertEqual(response_push, {"forks_count":371})
示例#29
0
 def test_watchers_count(self, mock_get, mock_response):
     '''Test for Repository class inside repository package'''
     mock_res = RepositoryTest.MockResponse({"watchers_count":6525}, 200)
     watchers_count = 6525
     type(mock_response).return_value = mock.PropertyMock(return_value=mock_res)
     type(mock_get).return_value = mock.PropertyMock(
         return_value=type(mock_response).return_value)
     response_push = Repository().watchers_count(watchers_count)
     self.assertEqual(response_push, {"watchers_count":6525})
示例#30
0
 def test_get_open_issue_count(self, mock_get, mock_response):
     '''Test for Repository class inside repository package'''
     mock_res = RepositoryTest.MockResponse({'open_issues_count':556}, 200)
     open_issues_count = 556
     type(mock_response).return_value = mock.PropertyMock(return_value=mock_res)
     type(mock_get).return_value = mock.PropertyMock(
         return_value=type(mock_response).return_value)
     response_push = Repository().get_open_issue_count(open_issues_count)
     self.assertEqual(response_push, {'open_issue_count': 556})