def init_database(): # create the database and the database table db.drop_all() db.create_all() salt = uuid.uuid4().hex encoded = ('%s%s' % ("password", salt)).encode('utf-8') hash_pass = hashlib.sha512(encoded).hexdigest() # insert user data client_internal = Clients(client_key="internal", client_secret=hash_pass, status="True", salt=salt) client_noninternal = Clients(client_key="noninternal", client_secret=hash_pass, status="False", salt=salt) db.session.add(client_internal) db.session.add(client_noninternal) db.session.commit() user = Users(name="andre", age=23, sex="male", client_id=1) book = Books(title="elektro", isbn=123456, writer="watt") db.session.add(user) db.session.add(book) db.session.commit() rent = Rent(book_id=1, user_id=1) db.session.add(rent) db.session.commit()
def init_database() : db.drop_all() db.create_all() strdata = 'rahasia0' strdata2 = 'rahasia1' salt = uuid.uuid4().hex hs = ('%s%s' % (strdata, salt)).encode('utf-8') clientsec = hashlib.sha512(hs).hexdigest() randstr = clientsec.encode('utf-8') client1 = Clients(status=1, client_secret=randstr, client_key=strdata, salt=salt, password=randstr) hs2 = ('%s%s' % (strdata2, salt)).encode('utf-8') clientsec2 = hashlib.sha512(hs2).hexdigest() randstr2 = clientsec2.encode('utf-8') client2 = Clients(status=0, client_secret=randstr2, client_key=strdata2, salt=salt, password=randstr2) db.session.add(client1) db.session.add(client2) db.session.commit()
def init_database(): db.drop_all() db.create_all() salt = uuid.uuid4().hex encoded = ('%s%s' % ('12345', salt)).encode('utf-8') hash_pass = hashlib.sha512(encoded).hexdigest() client_int = Clients(client_key= "altarest", client_secret=hash_pass, status="True", salt=salt) client_noint = Clients(client_key= "alul", client_secret=hash_pass, status="False", salt=salt) db.session.add(client_int) db.session.add(client_noint) db.session.commit() book = Books(title='Judul Buku', isbn="123-456-789", writer="Alul") db.session.add(book) db.session.commit() user = Users (name='Alul', age=23 , sex='Male' , client_id=1 ) db.session.add(user) db.session.commit() rent = Rent(book_id=1, user_id=1) db.session.add(rent) db.session.commit() yield db db.drop_all()
def init_database(): db.drop_all() db.create_all() salt = uuid.uuid4().hex encoded = ('%s%s' % ("super_secret_client", salt)).encode('utf-8') hashpass = hashlib.sha512(encoded).hexdigest() encoded2 = ('%s%s' % ("alta123", salt)).encode('utf-8') hashpass2 = hashlib.sha512(encoded2).hexdigest() client_internal = Clients(client_key='internal', client_secret=hashpass, salt=salt, status="True") client_noninternal = Clients(client_key='client1', client_secret=hashpass2, salt=salt, status="False") db.session.add(client_internal) db.session.add(client_noninternal) db.session.commit() user = Users(client_id=1, name='client', age=11, sex='male') db.session.add(user) db.session.commit() yield db db.drop_all()
def test_is_user_already_exist(self): client = Clients("tes1", "tes1", "tes1") db.session.add(client) db.session.commit() username = "******" assert Clients.is_exists(username) == True
def post(self): parser = reqparse.RequestParser() parser.add_argument('full_name', location='json') parser.add_argument('username', location='json', required=True) parser.add_argument('password', location='json') parser.add_argument('status', type=bool, location='json') parser.add_argument('email', location='json') parser.add_argument('address', location='json') parser.add_argument('city', location='json') parser.add_argument('telephone', location='json') parser.add_argument('is_deleted', type=bool, location='json') args = parser.parse_args() salt = uuid.uuid4().hex encoded = ('%s%s' % (args['password'], salt)).encode('utf-8') hash_pass = hashlib.sha512(encoded).hexdigest() client = Clients(args['username'], hash_pass, args['status'], salt) db.session.add(client) db.session.flush() user = Users(client.id, args['full_name'], args['email'], args['address'], args['city'], args['telephone'], args['is_deleted']) db.session.add(user) db.session.commit() app.logger.debug('DEBUG: %s', client) app.logger.debug('DEBUG: %s', user) return {'message': 'SUCCESS'}, 200
def init_database(): db.drop_all() db.create_all() salt = uuid.uuid4().hex encoded = ('%s%s' % ("admin", salt)).encode('utf-8') hashpass = hashlib.sha512(encoded).hexdigest() encoded2 = ('%s%s' % ("alta123", salt)).encode('utf-8') hashpass2 = hashlib.sha512(encoded2).hexdigest() client_internal = Clients(username='******', password=hashpass, salt=salt, status=True) client_noninternal = Clients(username='******', password=hashpass2, salt=salt, status=False) db.session.add(client_internal) db.session.add(client_noninternal) db.session.commit() category = Categories(imgURL="google.com", name='Makanan') db.session.add(category) db.session.commit() subcategory = SubCategories(name="makanan", category_id=1) db.session.add(subcategory) db.session.commit() product = Products(seller_id=1, category_id=1, subcategory_id=1, url_image="google.com", name="makan", price=10, stock=12, promo="Ya") db.session.add(product) db.session.commit() yield db db.drop_all()
def reset_db(): db.drop_all() db.create_all() secret = hashlib.md5('FIRST01'.encode()).hexdigest() client = Clients(key='NUMBER01', secret=secret, status=True) db.session.add(client) db.session.commit() user = Users(name='Akira', age=26, sex='Male', client_id=1) db.session.add(user) db.session.commit() book = Books(title='Book01', isbn='123-456-789', writer='Unknown') db.session.add(book) db.session.commit()
def reset_database(): db.drop_all() db.create_all() admin = Admins("tes", "tes", "*****@*****.**") client = Clients("tes", "tes", "*****@*****.**") # client_detail = ClientDetails(1, "fullname", "081208520813", "address") product = Products("name", "description", "category", "image", 10000, 10, 9000, 20) # save users to database db.session.add(admin) db.session.add(client) # db.session.add(client_detail) db.session.add(product) db.session.commit()
def test_if_get_last_balance_is_none(self, mock_is_exists): username = "******" mock_is_exists.return_value = True assert Clients.is_exists(username) == True