コード例 #1
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()
コード例 #2
0
    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'), [])
コード例 #3
0
ファイル: main_admin.py プロジェクト: Wizardgael/GL
def main():
    print("Welcome of BDS Association")

    # Init db
    database_engine = DatabaseEngine(url='sqlite:///bds.db')
    database_engine.create_database()
    sport_controller = SportController(database_engine)
    admin_controller = MemberController(database_engine, sport_controller)
    AdminVue(admin_controller, sport_controller).start()
コード例 #4
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()
コード例 #5
0
ファイル: main_member.py プロジェクト: Batclem/TD
def main():
    print("Welcome of BDS Association")

    # Init db
    database_engine = DatabaseEngine(url='sqlite:///bds.db')
    database_engine.create_database()
    member_controller = MemberController(database_engine)
    member_controller_sport = SportController(database_engine)
    admin_vue = AdminVue(member_controller, member_controller_sport)

    try:
        member = admin_vue.add_member()
        admin_vue.show_member(member)
    except Error as e:
        admin_vue.error_message(str(e))
コード例 #6
0
 def setUp(self) -> None:
     """
     Function called before each test
     """
     self.sport_controller = SportController(self._database_engine)
コード例 #7
0
class TestSportController(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:
            # Sport
            swimming = Sport(id=str(uuid.uuid4()),
                             name="Swimming",
                             description="Water",
                             persons=[])
            session.add(swimming)
            session.flush()
            cls.swimming_id = swimming.id

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

    def test_list_sports(self):
        sports = self.sport_controller.list_sports()
        self.assertGreaterEqual(len(sports), 1)

    def test_get_sport(self):
        sport = self.sport_controller.get_sport(self.swimming_id)
        self.assertEqual(sport['name'], "Swimming")
        self.assertEqual(sport['description'], "Water")
        self.assertEqual(sport['id'], self.swimming_id)

    def test_get_sport_not_exists(self):
        with self.assertRaises(ResourceNotFound):
            self.sport_controller.get_sport(str(uuid.uuid4()))

    def test_create_sport(self):
        data = {"name": "Snowboard", "description": "Haute-Savoie > Bretagne"}
        sport_data = self.sport_controller.create_sport(data)
        self.assertIn('id', sport_data)
        self.assertEqual(data['name'], sport_data['name'])
        self.assertEqual(data['description'], sport_data['description'])

    def test_create_sport_missing_data(self):
        data = {}
        with self.assertRaises(InvalidData):
            self.sport_controller.create_sport(data)

    def test_create_sport_error_already_exists(self):
        data = {"name": "Swimming", "description": "Water"}
        with self.assertRaises(Error):
            self.sport_controller.create_sport(data)

    def test_update_sport(self):
        sport_data = self.sport_controller.update_sport(
            self.swimming_id, {"description": "Water, again"})
        self.assertEqual(sport_data['description'], "Water, again")

    def test_update_sport_invalid_data(self):
        with self.assertRaises(InvalidData):
            self.sport_controller.update_sport(self.swimming_id, {"name": 1})

    def test_update_sport_not_exists(self):
        with self.assertRaises(ResourceNotFound):
            self.sport_controller.update_sport("test",
                                               {"description": "New sport !"})

    def test_delete_sport(self):
        with self._database_engine.new_session() as session:
            ski = Sport(id=str(uuid.uuid4()),
                        name="Ski",
                        description="Snowboard is better")
            session.add(ski)
            session.flush()
            ski_id = ski.id

        self.sport_controller.delete_sport(ski_id)
        with self.assertRaises(ResourceNotFound):
            self.sport_controller.delete_sport(ski_id)

    def test_delete_sport_not_exists(self):
        with self.assertRaises(ResourceNotFound):
            self.sport_controller.delete_sport(str(uuid.uuid4()))

    def test_search_sport(self):
        sport = self.sport_controller.search_sport("Swimming")
        self.assertEqual(sport['id'], self.swimming_id)

    def test_search_sport_not_exists(self):
        with self.assertRaises(ResourceNotFound):
            self.sport_controller.search_sport("Dart")
コード例 #8
0
def _create_sport_controller():
    return SportController(DatabaseEngine(url='sqlite:///bds.db'))