예제 #1
0
def add_following(user_id, colla_id):
    db_configuration = json.loads(open("api/db/db.json").read())
    following_ctrl = get_following_ctrl(
        DB(db_configuration).get_database_connection())
    if not following_ctrl.exists(user_id, colla_id):
        following_ctrl.insert(user_id, colla_id)
    return
예제 #2
0
    def test_get_followed_colles_by_user(self):
        test_user = User(name='Test_name',
                         surname='Test surnames',
                         email='*****@*****.**',
                         password='')
        user_ctrl = get_user_ctrl(self.cnx)
        user_ctrl.insert(test_user)

        colla1 = Colla(name='Test colla 1', uni=0, color='#FFFFFF')
        colla2 = Colla(name='Test colla 2', uni=1, color='#FFFFFF')
        colla3 = Colla(name='Test colla 3', uni=1, color='#FFFFFF')

        colla_ctrl = get_colla_ctrl(self.cnx)
        colla_ctrl.insert(colla1)
        colla_ctrl.insert(colla2)
        colla_ctrl.insert(colla3)

        sql = "INSERT INTO follows(id_user, id_colla) VALUES ('%s','%s')"
        data = [(test_user.id, colla1.id), (test_user.id, colla2.id)]

        self.cnx.cursor().executemany(sql, data)

        following_ctrl = get_following_ctrl(self.cnx)

        following_colles = following_ctrl.get_followed_by_user(test_user.id)

        self.assertEquals(2, len(following_colles))
        self.assertEquals(colla1, following_colles[0])
        self.assertEquals(colla2, following_colles[1])
예제 #3
0
def create_user(name, surname, email, password, belonging_list,
                following_list):
    db_configuration = json.loads(open("api/db/db.json").read())
    user_ctrl = get_user_ctrl(DB(db_configuration).get_database_connection())
    user = User(name, surname, email, password=password)
    user = user_ctrl.insert(user)
    user.password = None
    belonging_ctrl = get_belonging_ctrl(
        DB(db_configuration).get_database_connection())
    belonging_ctrl.insert_belonging_batch(belonging_list, user.id)
    following_ctrl = get_following_ctrl(
        DB(db_configuration).get_database_connection())
    following_ctrl.insert_following_batch(following_list, user.id)
    return user
예제 #4
0
def get_all_info(user):
    db_configuration = json.loads(open("api/db/db.json").read())
    bd_user = get_user_ctrl(
        DB(db_configuration).get_database_connection()).get(user.id)
    user = bd_user
    user.admin = get_admin_ctrl(
        DB(db_configuration).get_database_connection()).is_admin(user.id)
    user.session_token = get_token_ctrl(
        DB(db_configuration).get_database_connection()).get(user.id)
    user.belongs = get_belonging_ctrl(
        DB(db_configuration).get_database_connection()
    ).get_id_belonging_colles_by_user(user.id)
    user.follows = get_following_ctrl(
        DB(db_configuration).get_database_connection()
    ).get_id_followed_colles_by_user(user.id)
    return user
예제 #5
0
def remove_following(user_id, colla_id):
    db_configuration = json.loads(open("api/db/db.json").read())
    following_ctrl = get_following_ctrl(
        DB(db_configuration).get_database_connection())
    following_ctrl.delete(user_id, colla_id)
    return