Beispiel #1
0
def add_player(body: AcceptCreate):
    blizzard_id = BlizzardUsersUtils.id__safe(body.token)
    db = blizzard_db()
    qs = DatabaseUtils.core_query(db.query(StaticIndexModel)) \
        .filter(StaticIndexModel.owner_blizzard_id == blizzard_id)

    if qs.count() < 1:
        raise HTTPException(503, 'You cant accept player to not your static')

    q = DatabaseUtils.core_query(db.query(StaticMemberModel)) \
        .filter(StaticMemberModel.id == body.member_id)
    if q.count() < 1:
        raise HTTPException(404, 'You have not got this player')
    q.update({'request_state': 2})
    db.commit()
    return True
Beispiel #2
0
 def get_categories():
     """
     Returns the categories
     :return:
     """
     db = blizzard_db()
     return DatabaseUtils.core_query(db.query(PostCategoryModel)).all()
Beispiel #3
0
def get_full_user(blizzard_id: int, token: str):
    BlizzardUsersUtils.id__safe(token)
    WAccountUtils.eval_token(token)
    db = blizzard_db()
    return DatabaseUtils.core_query(
        db.query(WAccountModel).filter(
            WAccountModel.user_id == blizzard_id)).all()
Beispiel #4
0
 def test_deleteUser(self):
     userid = 1
     count = self.countPeople()
     with DatabaseUtils(self.connection) as db:
         self.assertTrue(db.deleteUser(userid))
         # Removed 1 user so the current count should - 1
         self.assertTrue((count - 1) == self.countPeople())
Beispiel #5
0
 def list(db: Session):
     """
     Returns all variables
     :param db:
     :return:
     """
     return DatabaseUtils.core_query(db.query(DataModel)).all()
Beispiel #6
0
 def test_updateCar(self):
     carid = 1
     make = "BMW"
     model = "c125"
     cartype = "Coupe"
     seats = "2"
     color = "Blue"
     location = "Geelong East"
     cost = "149"
     available = "False"
     lat = "145.098101"
     lng = "159.239102"
     with DatabaseUtils(self.connection) as db:
         self.assertTrue(db.updateCar(carid, make, model, cartype, seats, color, location, cost, available, lat, lng))
         updateCar = self.getCar(carid)
         # Compare updated value to original arguments
         self.assertEqual(updateCar[1], make)
         self.assertEqual(updateCar[2], model)
         self.assertEqual(updateCar[3], cartype)
         self.assertEqual(updateCar[4], seats)
         self.assertEqual(updateCar[5], color)
         self.assertEqual(updateCar[6], location)
         self.assertEqual(updateCar[7], int(cost))
         self.assertEqual(updateCar[8], available)
         self.assertEqual(updateCar[9], lat)
         self.assertEqual(updateCar[10], lng)
Beispiel #7
0
 def test_cancelBooking(self):
     counter = self.countTrueBooking()
     with DatabaseUtils(self.connection) as db:
         self.assertTrue(db.cancelBooking(2))
         self.assertEqual(counter - 1, self.countTrueBooking())
         self.assertTrue(db.cancelBooking(3))
         self.assertEqual(counter - 2, self.countTrueBooking())
Beispiel #8
0
 def test_getCar(self):
     with DatabaseUtils(self.connection) as db:
         self.assertEqual(self.getCar(1), db.getCar(1))
         self.assertEqual(self.getCar(2), db.getCar(2))
         rawData20 = (20, "Ferrari", "F1", "SUV", "5", "Red", "South Yarra", 1299, "False", "-145.087459", "123.123292")
         rawData10 = (10, "Volvo", "XC60", "SUV", "5", "White", "Carlton", 199, "True", "-145.087459", "123.123292")
         self.assertEqual(rawData10, db.getCar(10))
         self.assertEqual(rawData20, db.getCar(20))
Beispiel #9
0
 def test_checkUsername(self):
     with DatabaseUtils(self.connection) as db:
         self.assertFalse(db.checkUsername("TestUser1"))
         self.assertFalse(db.checkUsername("TestUser2"))
         self.assertFalse(db.checkUsername("TestUser3"))
         self.assertTrue(db.checkUsername("FakeUser"))
         self.assertTrue(db.checkUsername("FakeUserAccount"))
         self.assertTrue(db.checkUsername("FakeUserRoot"))
Beispiel #10
0
 def test_getUser(self):
     with DatabaseUtils(self.connection) as db:
         user1 = 1
         user2 = 2
         user3 = 3
         self.assertEqual("TestUser1", db.getUser(user1)[1])
         self.assertEqual("TestUser2", db.getUser(user2)[1])
         self.assertEqual("TestUser3", db.getUser(user3)[1])
Beispiel #11
0
 def test_checkPerson(self):
     with DatabaseUtils(self.connection) as db:
         self.assertTrue(db.checkPerson("TestUser1", "TestPassword"))
         self.assertTrue(db.checkPerson("TestUser2", "TestPassword"))
         self.assertTrue(db.checkPerson("TestUser3", "TestPassword"))
         self.assertFalse(db.checkPerson("TestUser1", "WrongPassword1"))
         self.assertFalse(db.checkPerson("TestUser2", "WrongPassword2"))
         self.assertFalse(db.checkPerson("TestUser3", "WrongPassword3"))
Beispiel #12
0
 def set(db: Session, field: str, value: str):
     """
     Sets the  value
     :param db:
     :param field:
     :param value:
     :return:
     """
     db_meta = DatabaseUtils.core_query(
         db.query(DataModel).filter(DataModel.field == field))
     if db_meta.count() > 0:
         db_meta.update({"value": value})
         db.commit()
         return db_meta.first()
     return DatabaseUtils.insert(db,
                                 db_item=DataModel(field=field,
                                                   value=value))
 def check(db: Session, user_id: int):
     q = DatabaseUtils.core_query(
         db.query(UserModel).filter(UserModel.id == user_id))
     if q.count() > 0:
         return True
     raise HTTPException(
         status_code=404,
         detail=f"User with user_id [{user_id}] is undefined!")
Beispiel #14
0
 def add(db: Session, group: UserGroupCreate):
     """
     Creates the user group
     :param db:
     :param group:
     :return:
     """
     return DatabaseUtils.insert(db, UserGroupModel(title=group.title))
Beispiel #15
0
 def test_insertBooking(self):
     startDate = datetime.strptime('2020-05-01', '%Y-%m-%d').date()
     endDate = datetime.strptime('2020-05-06', '%Y-%m-%d').date()
     counter = self.countBooking()
     with DatabaseUtils(self.connection) as db:
         self.assertTrue(
             db.insertBooking(4, 4, 199, startDate, endDate,
                              'Google Calendar EventID'))
         self.assertEqual(counter + 1, self.countBooking())
Beispiel #16
0
 def test_deleteCar(self):
     CarID_1 = 1
     CarID_10 = 10
     # Record down current number of cars
     count = self.countCar()
     with DatabaseUtils(self.connection) as db:
         self.assertTrue(db.deleteCar(CarID_1))
         self.assertEqual((count-1), self.countCar())
         self.assertTrue(db.deleteCar(CarID_10))
         self.assertEqual((count-2), self.countCar())
Beispiel #17
0
 def get(blizzard_id):
     """
     Returns the blizzard user by blizzard_id
     :param blizzard_id:
     :return:
     """
     db = blizzard_db()
     return DatabaseUtils.core_query(
         db.query(BlizzardUserModel).filter(
             BlizzardUserModel.blizzard_id == blizzard_id)).first()
Beispiel #18
0
 def test_getFaultyCar(self):
     carid = 1
     count = len(self.getFaultyCar())
     with DatabaseUtils(self.connection) as db:
         # Verify that there is no Faulty car in the database
         self.assertTrue(count == 0)
         # Report a car and set it to Faulty
         self.assertTrue(db.reportCar(carid))
         # Verify if faulty car is in the system by checking database rows
         self.assertEqual((count+1), len(self.getFaultyCar()))
Beispiel #19
0
 def recover(db: Session, field: str):
     """
     Recovers the value
     :param db:
     :param field:
     :return:
     """
     return DatabaseUtils.recover_query(
         db,
         db.query(DataModel).filter(DataModel.field == field))
Beispiel #20
0
 def test_checkCarAvail(self):
     carTrue1 = 1
     carTrue2 = 2
     carFalse19 = 19
     carFalse20 = 20
     with DatabaseUtils(self.connection) as db:
         self.assertTrue(db.checkCarAvail(carTrue1))
         self.assertTrue(db.checkCarAvail(carTrue2))
         self.assertFalse(db.checkCarAvail(carFalse19))
         self.assertFalse(db.checkCarAvail(carFalse20))
Beispiel #21
0
 def test_insertEngineer(self):
     with DatabaseUtils(self.connection) as db:
         count = self.countEngineer()
         username = sha256_crypt.hash("TestEngineer")
         password = sha256_crypt.hash("TestPassword")
         # Perform test
         self.assertTrue(
             db.insertEngineer(username, password, "TestFirstName",
                               "TestLastName", "TestPhone",
                               "*****@*****.**", "TestAddress"))
         self.assertTrue((count + 1) == self.countEngineer())
Beispiel #22
0
    def update_characters_images(path=default_characters_images_path):
        """
        Downloads the characters images

        Characters are getting from the database
        :param path:
        :return:
        """
        MediaDownloader.download_characters_images(
            DatabaseUtils.core_query(
                blizzard_db().query(CharacterModel)).all(), path)
Beispiel #23
0
 def get(db: Session, group_id: int, show_removed=False):
     """
     Returns the user group by id
     :param db:
     :param group_id:
     :param show_removed:
     :return:
     """
     return DatabaseUtils.core_query(
         db.query(UserGroupModel),
         show_removed).filter(UserGroupModel.id == group_id).first()
Beispiel #24
0
 def add_like(user_id: int, post_id: int):
     """
     Adds like
     :param user_id:
     :param post_id:
     :return:
     """
     db = blizzard_db()
     val = db.query(PostLikeModel) \
         .filter(PostLikeModel.user_id == user_id) \
         .filter(PostLikeModel.post_id == post_id).count()
     if val == 0:
         DatabaseUtils.insert(
             db, PostLikeModel(
                 post_id=post_id,
                 user_id=user_id,
             ))
         return True
     else:
         return False
Beispiel #25
0
 def get(db: Session, token: str) -> UserAuth:
     """
     Returns the token
     :param db:
     :param token:
     :return:
     """
     db_obj = DatabaseUtils.core_query(db.query(UserAuthModel).filter(UserAuthModel.token == token)).first()
     if db_obj is None:
         raise HTTPException(status_code=201, detail="User's token is undefined!")
     return db_obj
Beispiel #26
0
    def test_showBooking(self):
        with DatabaseUtils(self.connection) as db:
            # UserID 1 booked 1 car is False
            self.assertEqual(0, len(db.showBooking(1)))
            # UserID 10 booking doesn't exist
            self.assertEqual(0, len(db.showBooking(10)))

            # UserID 2 booked 1 car is True
            self.assertEqual(1, len(db.showBooking(2)))
            # UserID 3 booked 1 car is True
            self.assertEqual(1, len(db.showBooking(3)))
Beispiel #27
0
    def test_showHistory(self):
        with DatabaseUtils(self.connection) as db:
            # UserID 1 have an canceled booking:'False'
            self.assertEqual(1, len(db.showHistory(1)))
            # UserID 2 have an active booking:'True'
            self.assertEqual(0, len(db.showHistory(2)))

            # Cancel UserID 2's booking and test again
            # Should be 1 canceled booking now instead of previous 0
            self.assertTrue(db.cancelBooking(2))
            self.assertEqual(1, len(db.showHistory(2)))
Beispiel #28
0
 def update_characters_mythic():
     data = DatabaseUtils.core_query(
         blizzard_db().query(CharacterModel)).all()
     logger.info("Starting update characters mythic...")
     logger.info(f"Total count: {len(data)}")
     bar = Bar('Characters mythic updating', max=len(data), fill='█')
     for member in data:
         name = member.name
         MythicUpdater.update_mythic_character(name)
         bar.next()
     print("")
 def get(db: Session, user_id: int, show_removed=False):
     """
     Returns the user by id
     :param show_removed:
     :param db:
     :param user_id:
     :return:
     """
     return DatabaseUtils.core_query(
         db.query(UserModel).filter(UserModel.id == user_id),
         show_removed).first()
Beispiel #30
0
 def get_posts_limit(offset: int = 0, limit: int = 100):
     """
     Returns the posts by limit
     :param offset:
     :param limit:
     :return:
     """
     db = blizzard_db()
     return DatabaseUtils.limited_results_query(
         db.query(PostModel).order_by(PostModel.id.desc()),
         offset=offset,
         limit=limit)