Exemplo n.º 1
0
def run():
    try:
        get_a_user('a')
    except Exception as e:
        if 'no such table' in str(e):
            print('INITIALIZING DATABASE')
            db.create_all()
        else:
            raise e

    app.run(host='0.0.0.0')
Exemplo n.º 2
0
 def get(self, public_id):
     """get a user given its identifier"""
     user = get_a_user(public_id)
     if not user:
         api.abort(404)
     else:
         return user
Exemplo n.º 3
0
    def test_get_a_user(self):
        user_1 =  User(fb_id='123', email=None, name='Jake')
        db.session.add(user_1)
        db.session.commit()

        resp, status_code = user_service.get_a_user(1)
        expected = {'fb_id': '123', 'email': None, 'id': 1, 'name': 'Jake'}

        assert resp == expected
        assert status_code == 200
Exemplo n.º 4
0
    def decorated(*args, **kwargs):
        data, status = Auth.get_logged_in_user(request)
        token = data.get('data')
        current_user = None

        if not token:
            response_object = {'status': 'fail', 'message': 'token required'}
            return response_object, 401
        else:
            user_id = token.get('user_id')
            current_user = get_a_user(user_id)

        return f(*args, **kwargs, current_user=current_user)
Exemplo n.º 5
0
    def test_get_a_user(self):
        self.assertEqual([], get_all_users())

        user1 = Users(
            user_id='eamanu',
            password_hash='hola',
            register_on=datetime.datetime.utcnow(),
            last_pass_change=datetime.datetime.utcnow(),
            name='Emmanuel',
            surname='Arias',
            email='eamanu@yaerobi',
            country_city_id='1',
        )
        user2 = Users(
            user_id='eamanu2',
            password_hash='hola',
            register_on=datetime.datetime.utcnow(),
            last_pass_change=datetime.datetime.utcnow(),
            name='Emmanuel',
            surname='Arias',
            email='eamanu2@yaerobi',
            country_city_id='1',
        )

        user3 = Users(
            user_id='eamanu3',
            password_hash='hola',
            register_on=datetime.datetime.utcnow(),
            last_pass_change=datetime.datetime.utcnow(),
            name='Emmanuel',
            surname='Arias',
            email='eamanu3@yaerobi',
            country_city_id='1',
        )
        db.session.add(user1)
        db.session.add(user2)
        db.session.add(user3)

        db.session.commit()

        user = get_a_user('eamanu')
        self.assertEqual('Emmanuel', user.name)
        self.assertEqual('Arias', user.surname)
        self.assertEqual('eamanu@yaerobi', user.email)
        self.assertEqual('hola', user.password_hash)
Exemplo n.º 6
0
def assign_member(card_list_id, user_id, assign):
    card_list = get_a_card_list_by_id(card_list_id)
    if not card_list:
        response_object = {
            'status': 'fail',
            'message': 'card list not exists'
        }
        return response_object, 400
    user = get_a_user(user_id)
    if not user:
        response_object = {
            'status': 'fail',
            'message': 'user not exists'
        }
        return response_object, 400

    if assign:
        card_list.users.append(user)
    else:
        card_list.users.remove(user)
    db.session.commit()
    return card_list.json(), 200
Exemplo n.º 7
0
 def get(self, public_id):
     user = get_a_user(public_id)
     if not user:
         api.abort(404)
     else:
         return user
Exemplo n.º 8
0
 def get(self, public_id):
     user = get_a_user(public_id)
     if not user:
         UserNs.impl.abort(404, 'cant find user', status='fail')
     else:
         return {'status': 'success', 'message': 'list', 'data': user}