Beispiel #1
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()
Beispiel #2
0
def main():

    # configure logging
    root = logging.getLogger()
    root.setLevel(logging.DEBUG)

    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)
    root.addHandler(handler)

    logging.info("Start 2eat App")

    # Init db
    logging.info("Init database")
    database_engine = DatabaseEngine(url='sqlite:///database.db')
    database_engine.create_database()

    # controller
    restaurant_controller = RestaurantController(database_engine)
    product_controller = ProductController(database_engine)
    person_controller = PersonController(database_engine)
    basket_controller = BasketController(database_engine)
    order_controller = OrderController(database_engine)
    # init vue
    root = RootFrame(restaurant_controller, product_controller,
                     person_controller, basket_controller, order_controller)
    root.master.title("2eat subscription app")
    root.show_auth_portal()

    # start
    root.mainloop()
Beispiel #3
0
def main():

    # configure logging
    root = logging.getLogger()
    root.setLevel(logging.DEBUG)

    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)
    root.addHandler(handler)

    logging.info("Start BDS App")

    # Init db
    logging.info("Init database")
    database_engine = DatabaseEngine(url='sqlite:///bds.db')
    database_engine.create_database()

    # controller
    person_controller = PersonController(database_engine)
    sport_controller = SportController(database_engine)

    # init vue
    root = RootFrame(person_controller, sport_controller)
    root.master.title("bds subscription app")
    root.show_menu_connexion()

    # start
    root.mainloop()
    def start_session(self):
        # profile may be:
        # - a string if loging is invalid OR user is ADMIN
        # - an Account object, if a customer performed a successful login
        # - a person object, if a manager performed a successful login
        profile = self.login()
        if profile == 'invalid':
            return

        option = -1
        while option != 0:
            # Shows main menu according to profile
            option = self.view.show_main_menu(profile)
            # client - account deposit
            if option == 1:
                AccountController().create_transaction(profile, 'Deposit')
            # client - account withdrawal
            elif option == 2:
                AccountController().create_transaction(profile, 'Withdrawal')
            # client - account balance
            elif option == 3:
                AccountController().list_balance(profile)
            # client - account history
            elif option == 4:
                AccountController().list_statement(profile)
            # admin - create branch
            elif option == 100:
                BranchController().create_branch()
            # admin - list branches
            elif option == 101:
                BranchController().list_branches()
            # admin - create manager
            elif option == 102:
                PersonController().create_person('Manager')
            # admin - list managers
            elif option == 103:
                PersonController().list_people('Manager')
            # manager-create account
            elif option == 200:
                AccountController().create_account()
            # manager-list accounts
            elif option == 201:
                AccountController().list_client_accounts()
            elif option != 0:
                self.view.show_message('Error',
                                       'Invalid option. Please try again.',
                                       True)
Beispiel #5
0
def main():
    print("Welcome in BDS App")

    # Init db
    database_engine = DatabaseEngine(url='sqlite:///bds.db')
    database_engine.create_database()


    # controller
    person_controller = PersonController(database_engine)
    sport_controller = SportController(database_engine)
    planning_controller = SportController(database_engine) #a changer

    # init vue
    root = RootFrame(person_controller, sport_controller, planning_controller)
    root.master.title("bds subscription app")
    root.show_menu()

    # start
    root.mainloop()
Beispiel #6
0
 def setUp(self) -> None:
     """
     Function called before each test
     """
     self.person_controller = PersonController(self._database_engine)
Beispiel #7
0
class TestPersonController(unittest.TestCase):
    """
    Unit Tests sport controller
    https://docs.python.org/fr/3/library/unittest.html
    """
    @classmethod
    def setUpClass(cls) -> None:
        cls._database_engine = DatabaseEngine()
        cls._database_engine.create_database()
        with cls._database_engine.new_session() as session:
            # Person
            # Password is 'password'
            john = Person(
                id=str(uuid.uuid4()),
                firstname="john",
                lastname="do",
                email="*****@*****.**",
                user=User(
                    username="******",
                    password_hash=
                    '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',
                    admin=False))
            session.add(john)

            # Sport to test person-sport association
            swimming = Sport(id=str(uuid.uuid4()),
                             name="Swimming",
                             description="Water",
                             persons=[])
            session.add(swimming)
            session.flush()

            session.flush()
            cls.john_id = john.id

    def setUp(self) -> None:
        """
        Function called before each test
        """
        self.person_controller = PersonController(self._database_engine)

    def test_list_persons(self):
        persons = self.person_controller.list_persons()
        self.assertGreaterEqual(len(persons), 1)

    def test_get_person(self):
        person = self.person_controller.get_person(self.john_id)
        self.assertEqual(person['firstname'], "john")
        self.assertEqual(person['lastname'], "do")
        self.assertEqual(person['id'], self.john_id)

    def test_get_person_not_exists(self):
        with self.assertRaises(ResourceNotFound):
            self.person_controller.get_person(str(uuid.uuid4()))

    def test_create_person(self):
        data = {
            "firstname": "Han",
            "lastname": "Solo",
            "email": "*****@*****.**"
        }
        person_data = self.person_controller.create_person(data)
        self.assertIn('id', person_data)
        self.assertEqual(data['firstname'], person_data['firstname'])
        self.assertEqual(data['lastname'], person_data['lastname'])
        self.assertEqual(data['email'], person_data['email'])

    def test_create_person_missing_data(self):
        data = {}
        with self.assertRaises(InvalidData):
            self.person_controller.create_person(data)

    def test_create_person_error_already_exists(self):
        data = {
            "firstname": "john",
            "lastname": "do",
            "email": "*****@*****.**"
        }
        with self.assertRaises(Error):
            self.person_controller.create_person(data)

    def test_update_person(self):
        person_data = self.person_controller.update_person(
            self.john_id, {"email": "*****@*****.**"})
        self.assertEqual(person_data['email'], "*****@*****.**")

    def test_update_person_invalid_data(self):
        with self.assertRaises(InvalidData):
            self.person_controller.update_person(self.john_id,
                                                 {"email": "test"})

    def test_update_person_not_exists(self):
        with self.assertRaises(ResourceNotFound):
            self.person_controller.update_person("test",
                                                 {"description": "test foot"})

    def test_delete_person(self):
        with self._database_engine.new_session() as session:
            rob = Person(id=str(uuid.uuid4()),
                         firstname="rob",
                         lastname="stark",
                         email="*****@*****.**")
            session.add(rob)
            session.flush()
            rob_id = rob.id

        self.person_controller.delete_person(rob_id)
        with self.assertRaises(ResourceNotFound):
            self.person_controller.delete_person(rob_id)

    def test_delete_person_not_exists(self):
        with self.assertRaises(ResourceNotFound):
            self.person_controller.delete_person(str(uuid.uuid4()))

    def test_search_person(self):
        person = self.person_controller.search_person("john", "do")
        self.assertEqual(person['id'], self.john_id)

    def test_search_person_not_exists(self):
        with self.assertRaises(ResourceNotFound):
            self.person_controller.search_person("john", "snow")

    def test_search_person_by_username(self):
        person = self.person_controller.get_person_by_username("john")
        self.assertEqual(person['firstname'], "john")
        self.assertEqual(person['lastname'], "do")
        self.assertEqual(person['id'], self.john_id)

    def test_add_delete_sport(self):
        # Test to add a sport to a person
        sport_controller = SportController(self._database_engine)
        sport = sport_controller.search_sport("Swimming")

        # Add
        self.person_controller.add_person_sport(self.john_id, sport.get('id'),
                                                "Master")
        person = self.person_controller.get_person_by_username("john")
        sport = sport_controller.search_sport("Swimming")
        self.assertNotEqual(person.get('sports'), [])

        # Delete
        self.person_controller.delete_person_sport(self.john_id,
                                                   sport.get('id'))
        person = self.person_controller.get_person_by_username("john")
        sport = sport_controller.search_sport("Swimming")
        self.assertEqual(person.get('sports'), [])
Beispiel #8
0
from repository.file_repository import FileRepository
from repository.pickle_repository import PickleRepository
from ui.Config import Config, StorageType

if __name__=="__main__":
    #try:
        config = Config("settings.properties")
        config.parse_config()

        print(config.storage_type)

        if(config.storage_type=="inmemory"):
            person_repository = Repository(PersonValidator)
            activity_repository = Repository(ActivityValidator)
            participation_repository = Repository(ParticipationValidator)
            person_controller = PersonController(person_repository)
            activity_controller = ActivityController(activity_repository)
            participation_controller=ParticipationController(participation_repository,person_controller,activity_controller)
            console = Console(person_controller,activity_controller,participation_controller)
            console.run()
            print("True")
        
        if(config.storage_type=="infile"):
            person_repository = FileRepository(config.person_repository,PersonController.read_entity,PersonController.write_entity,PersonValidator)
            activity_repository = FileRepository(config.activity_repository,ActivityController.read_entity,ActivityController.write_entity,ActivityValidator)
            participation_repository = FileRepository(config.participation_repository,ParticipationController.read_entity,ParticipationController.write_entity,ParticipationController)
            person_controller = PersonController(person_repository)
            activity_controller = ActivityController(activity_repository)
            participation_controller=ParticipationController(participation_repository,person_controller,activity_controller)
            console = Console(person_controller,activity_controller,participation_controller)
            console.run()
Beispiel #9
0
class TestPersonController(unittest.TestCase):
    """
    Unit Tests sport controller
    https://docs.python.org/fr/3/library/unittest.html
    """

    @classmethod
    def setUpClass(cls) -> None:
        cls._database_engine = DatabaseEngine()
        cls._database_engine.create_database()
        with cls._database_engine.new_session() as session:



            steeve = Person(id=str(uuid.uuid4()),
                           firstname="steeve",
                           lastname="gates",
                           email="*****@*****.**")
            steeve.address = Address(street="21 rue docteur guerin",
                                     city="Laval",
                                     postal_code=53000)
            cls.steeve_id = steeve.id
            session.add(steeve)
            session.flush()

    def setUp(self) -> None:
        """
        Function called before each test
        """
        self.person_controller = PersonController(self._database_engine)

    def test_list_Persones(self):
        Persones = self.person_controller.list_people(person_type="Person")
        self.assertGreaterEqual(len(Persones), 1)

    def test_get_Person(self):

        Person = self.person_controller.get_person(self.steeve_id, person_type="Person")
        self.assertEqual(Person['firstname'], "steeve")
        self.assertEqual(Person['lastname'], "gates")
        self.assertEqual(Person['id'], self.steeve_id)
        self.assertIn("address", Person)
        self.assertEqual(Person["address"]["city"], "Laval")

    def test_get_Person_not_exists(self):
        with self.assertRaises(ResourceNotFound):
            self.person_controller.get_person(str(uuid.uuid4()))


    def test_create_Person_missing_data(self):
        data = {}
        with self.assertRaises(InvalidData):
            self.person_controller.create_person(data, person_type="Person")


    def test_update_Person(self):
        Person_data = self.person_controller.update_person(
            self.steeve_id, {"email": "*****@*****.**"})
        self.assertEqual(Person_data['email'], "*****@*****.**")

    def test_update_Person_invalid_data(self):
        with self.assertRaises(InvalidData):
            self.person_controller.update_person(self.steeve_id, {"email": "test"})

    def test_update_Person_not_exists(self):
        with self.assertRaises(ResourceNotFound):
            self.person_controller.update_member("test", {"description": "test foot"})

    def test_delete_Person(self):
        with self._database_engine.new_session() as session:
            rob = Person(id=str(uuid.uuid4()), firstname="rob", lastname="stark",
                        email="*****@*****.**")
            session.add(rob)
            session.flush()
            rob_id = rob.id

        self.person_controller.delete_person(rob_id)
        with self.assertRaises(ResourceNotFound):
            self.person_controller.delete_person(rob_id)

    def test_delete_Person_not_exists(self):
        with self.assertRaises(ResourceNotFound):
            self.person_controller.delete_person(str(uuid.uuid4()))
Beispiel #10
0
class TestParticipationController(unittest.TestCase):
    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()

    def test_add(self):
        """Test the add function."""
        self.controller.add(1, 1, 1)
        self.assertEqual(len(self.controller.get_all()), 1,
                         "Repository size should be 1")

        self.assertRaises(ParticipationControllerException,
                          self.controller.add, 2, 4, 2)
        self.assertRaises(ParticipationControllerException,
                          self.controller.add, 2, 1, 5)

    def test_remove(self):
        """Test the remove function."""
        self.controller.add(1, 1, 1)
        self.controller.remove(1)
        self.assertEqual(len(self.controller.get_all()), 0,
                         "Repository size should be 0")

    def test_update(self):
        """Test the update function."""
        self.controller.add(1, 1, 1)
        self.controller.update(1, 2, 2)
        participation = self.controller.find_by_id(1)
        self.assertEqual(participation.entity_id, 1,
                         "Participation id should be 1.")
        self.assertEqual(participation.person_id, 2, "Person id should be 2.")
        self.assertEqual(participation.activity_id, 2,
                         "Activity id should be 2.")

    def test_get_all(self):
        """Test the get_all function."""
        self.controller.add(1, 1, 1)
        self.assertEqual(len(self.controller.get_all()), 1,
                         "get_all() size should be 1.")

    def find_by_id(self):
        """Test the find_by_id function."""
        self.controller.add(1, 1, 1)

        participation = self.controller.find_by_id(1)

        self.assertEqual(participation.entity_id, 1,
                         "Participation id should be 1.")
        self.assertEqual(participation.person_id, 1, "Person id should be 1.")
        self.assertEqual(participation.activity_id, 1,
                         "Activity id should be 1.")

    def test_find_by_activity_id(self):
        """Test the find_by_activity id function."""
        self.controller.add(1, 1, 1)

        participation = self.controller.find_by_activity_id(1)
        self.assertEqual(participation[0].entity_id, 1,
                         "Participation id should be 1.")
        self.assertEqual(participation[0].person_id, 1,
                         "Person id should be 1.")
        self.assertEqual(participation[0].activity_id, 1,
                         "Activity id should be 1.")

    def test_find_by_person_id(self):
        """Test the find_by_person_id function."""
        self.controller.add(1, 1, 1)

        participation = self.controller.find_by_person_id(1)
        self.assertEqual(participation[0].entity_id, 1,
                         "Participation id should be 1.")
        self.assertEqual(participation[0].person_id, 1,
                         "Person id should be 1.")
        self.assertEqual(participation[0].activity_id, 1,
                         "Activity id should be 1.")

    def test_find_by_activity_time(self):
        """Test the find by activity time function."""
        self.controller.add(1, 1, 1)

        participation = self.controller.find_by_activity_time(
            Common.convert_to_time("06:03"))
        self.assertEqual(participation[0].entity_id, 1,
                         "Participation id should be 1.")
        self.assertEqual(participation[0].person_id, 1,
                         "Person id should be 1.")
        self.assertEqual(participation[0].activity_id, 1,
                         "Activity id should be 1.")

    def test_find_by_activity_date(self):
        """Test the find by activity date function."""
        self.controller.add(1, 1, 1)

        participation = self.controller.find_by_activity_date(
            Common.convert_to_date("15.11.2016"))
        self.assertEqual(participation[0].entity_id, 1,
                         "Participation id should be 1.")
        self.assertEqual(participation[0].person_id, 1,
                         "Person id should be 1.")
        self.assertEqual(participation[0].activity_id, 1,
                         "Activity id should be 1.")

    def test_find_by_activity_description(self):
        """Test the find by activity description function."""
        self.controller.add(1, 1, 1)

        participation = self.controller.find_by_activity_description(
            "description")
        self.assertEqual(participation[0].entity_id, 1,
                         "Participation id should be 1.")
        self.assertEqual(participation[0].person_id, 1,
                         "Person id should be 1.")
        self.assertEqual(participation[0].activity_id, 1,
                         "Activity id should be 1.")

    def test_statistics_activity_by_day(self):
        """Test the statistics_activity_by_day function."""
        self.controller.add(1, 1, 1)

        participation = self.controller.statistics_activity_by_day(15)
        self.assertEqual(participation[0].entity_id, 1,
                         "Participation id should be 1.")
        self.assertEqual(participation[0].person_id, 1,
                         "Person id should be 1.")
        self.assertEqual(participation[0].activity_id, 1,
                         "Activity id should be 1.")

    def test_statistics_activity_by_person(self):
        """Test the statistics_activity_by_person function."""
        self.controller.add(1, 1, 1)

        participation = self.controller.statistics_activity_by_person(1)
        self.assertEqual(participation[0].entity_id, 1,
                         "Participation id should be 1.")
        self.assertEqual(participation[0].person_id, 1,
                         "Person id should be 1.")
        self.assertEqual(participation[0].activity_id, 1,
                         "Activity id should be 1.")

    def test_statistics_activity_by_week(self):
        """Test the statistics_activity_by_person function."""
        self.controller.add(1, 1, 1)

        participation = self.controller.statistics_activity_by_week(1)
        self.assertEqual(participation[0].entity_id, 1,
                         "Participation id should be 1.")
        self.assertEqual(participation[0].person_id, 1,
                         "Person id should be 1.")
        self.assertEqual(participation[0].activity_id, 1,
                         "Activity id should be 1.")

    def test_delete_by_activity_id(self):
        """Test the delete_by_activity id function."""
        self.controller.add(1, 1, 1)
        self.controller.delete_by_activity_id(1)

        self.assertEqual(len(self.controller.get_all()), 0,
                         "size of get_all() should be 0")

    def test_delete_by_person_id(self):
        """Test the delete_by_person_id function."""
        self.controller.add(1, 1, 1)
        self.controller.delete_by_person_id(1)
        self.assertEqual(len(self.controller.get_all()), 0,
                         "size of get_all() should be 0")

    def test_statistics_sorted_busiest(self):
        """Test the statistics_sorted_busiest function."""
        self.controller.add(1, 1, 1)

        self.assertEqual(self.controller.statistics_sorted_busiest()[0],
                         Common.convert_to_date("16.11.2016"),
                         "Date should be 16.11.2016")

    def test_statistics_sorted_persons(self):
        """Test the statistics_sorted_persons function."""
        self.controller.add(1, 1, 1)
        self.assertEqual(
            self.controller.statistics_sorted_persons()[0].entity_id, 1,
            "Person id should be 1.")
Beispiel #11
0
def _create_person_controller():
    return PersonController(DatabaseEngine(url='sqlite:///bds.db'))