def setUp(self): app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://*****:*****@localhost/giftsmarts_test" db.session.close() db.drop_all() db.create_all() FriendRelationShipTypeActions.create("relationship 1") FriendRelationShipTypeActions.create("relationship 2") FriendRelationShipTypeActions.create("relationship 3") self.profile_1 = ['118600698523151', 'Luke Skywalker Alaaaiffajfch Occhinosky', '', '', '1980-01-30'] profile_2 = {'id': '118600698523152', 'name': 'Han Solo Alaaaiffajfch Occhinosky', 'birthday': '01/30/1979'} profile_3 = {'id': '118600698523153', 'name': 'Padme Alaaaiffajfch Occhinosky', 'birthday': '01/30/1979'} self.user_1 = UserActions.create_user_from_csv(self.profile_1) user_2 = UserActions.new_facebook_user(profile_2, {'access_token': 'mock access token'}) user_3 = UserActions.new_facebook_user(profile_3, {'access_token': 'mock access token'}) FriendRelationshipActions.create(self.user_1, user_2) FriendRelationshipActions.create(self.user_1, user_3) product_1 = ProductActions.create("1") product_2 = ProductActions.create("2") category = CategoryActions.create("Book") UserProductActions.create(self.user_1, product_1, category) UserProductActions.create(self.user_1, product_2, category)
def check_user_logged_in(): if session.get('user'): g.user = session.get('user') return result = get_user_from_cookie(cookies=request.cookies, app_id=app.config["FB_APP_ID"], app_secret=app.config["FB_APP_SECRET"]) if result: user = UserActions.find_by_id(result['uid']) if not user: graph = GraphAPI(result['access_token']) args = {'fields': 'birthday, name, email'} profile = graph.get_object('me', **args) UserActions.new_facebook_user(profile, result) elif user.access_token != result['access_token']: user.access_token = result['access_token'] user = UserActions.find_by_id(result['uid']) session['user'] = dict(name=user.name, profile_url=user.profile_url, id=user.id, access_token=user.access_token) db.session.commit() g.user = session.get('user', None)
def check_user_logged_in(): if session.get('user'): g.user = session.get('user') return result = get_user_from_cookie(cookies=request.cookies, app_id=app.config["FB_APP_ID"], app_secret=app.config["FB_APP_SECRET"]) if result: user = UserActions.find_by_id(result['uid']) if not user: graph = GraphAPI(result['access_token']) args = {'fields': 'birthday, name, email'} profile = graph.get_object('me', **args); UserActions.new_facebook_user(profile, result) elif user.access_token != result['access_token']: user.access_token = result['access_token'] user = UserActions.find_by_id(result['uid']) session['user'] = dict(name=user.name, profile_url=user.profile_url, id=user.id, access_token=user.access_token) db.session.commit() g.user = session.get('user', None)
def setUp(self): app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://*****:*****@localhost/giftsmarts_test" db.session.close() db.drop_all() db.create_all() self.profile_1 = ['118600698523151', 'Luke Skywalker Alaaaiffajfch Occhinosky', '', '', '1980-01-30'] profile_2 = {'id': '118600698523152', 'name': 'Han Solo Alaaaiffajfch Occhinosky', 'birthday': '01/30/1979'} profile_3 = {'id': '118600698523153', 'name': 'Padme Alaaaiffajfch Occhinosky', 'birthday': '01/30/1979'} family_rel_name = "family" friend_rel_name = "friend" FriendRelationShipTypeActions.create(family_rel_name) FriendRelationShipTypeActions.create(friend_rel_name) FriendRelationShipTypeActions.create("acquaintance") rel_family = FriendRelationShipTypeActions.find_by_name(family_rel_name) rel_friend = FriendRelationShipTypeActions.find_by_name(friend_rel_name) self.user_1 = UserActions.create_user_from_csv(self.profile_1) user_2 = UserActions.new_facebook_user(profile_2, {'access_token': 'mock access token'}) user_3 = UserActions.new_facebook_user(profile_3, {'access_token': 'mock access token'}) FriendRelationshipActions.create(self.user_1, user_2, rel_family) FriendRelationshipActions.create(self.user_1, user_3, rel_friend) product_1 = ProductActions.create("1") product_2 = ProductActions.create("2") category = CategoryActions.create("Book") UserProductActions.create(self.user_1, product_1, category) UserProductActions.create(self.user_1, product_2, category)