How to use tag_user method in localstack

Best Python code snippet using localstack_python

api_tags.py

Source:api_tags.py Github

copy

Full Screen

1from . import post2from app.models.tag_model import Tags, Tag_user3from flask import request4from flask import jsonify5from app.helper.auth_connector import verify_jwt6from app.helper.auth_connector import Permission7from app.helper.Exception import CustomException8from app import db9from app.helper.Connection import get_connection10from app.helper.auth_connector import ServiceURL11from app.models.post_model import Post12from sqlalchemy import desc, func, text13from app.models.tag_model import Tag_post14@post.route('/tags')15def get_tag():16 query_tag = request.args.get('query_tag', '')17 page = int(request.args.get('page', 0))18 current_user_id = int(request.args.get('current_user_id', '0'))19 result = db.session.query(Tags, func.count(Tag_post.post_id).label('total_post')).outerjoin(Tag_post) \20 .filter(Tags.name.like(f'%{query_tag}%')) \21 .group_by(Tags.tag_id) \22 .order_by(text('total_post desc')) \23 .paginate(page=page, per_page=30, error_out=False)24 tag_list = result.items25 return jsonify({26 'page': page,27 'total_tags': result.total,28 'total_pages': result.total // 30 + 1,29 'tags': list(map(lambda d: d[0].to_json(current_user_id), tag_list))})30@post.route('/tags/<tag_id>/follow', methods=['POST'])31@verify_jwt(blueprint=post, permissions=[Permission.WRITE])32def follow_tag(user_id, tag_id):33 print(tag_id, user_id)34 tags = Tags.query.filter_by(tag_id=tag_id).first()35 if tags is None:36 raise CustomException('Cannot found tags', 404)37 tags_user = Tag_user.query.filter(Tag_user.tag_id == tag_id, Tag_user.user_id == user_id).first()38 if tags_user is not None:39 print(tags_user)40 raise CustomException('User followed tags', 500)41 try:42 tag_user = Tag_user(user_id=user_id, tag_id=tag_id)43 db.session.add(tag_user)44 db.session.commit()45 return jsonify({'message': 'Success'}), 20046 except:47 db.session.rollback()48 return jsonify({'error': 'Error'}), 50049@post.route('/tags/<tag_id>/follow', methods=['DELETE'])50@verify_jwt(blueprint=post, permissions=[Permission.WRITE])51def unfollow_tag(user_id, tag_id):52 tag_user = Tag_user.query.filter(Tag_user.tag_id == tag_id, Tag_user.user_id == user_id).first()53 if tag_user is None:54 raise CustomException('Cannot find user_tag', 404)55 try:56 db.session.delete(tag_user)57 db.session.commit()58 return jsonify({'message': 'Success'}), 20059 except:60 db.session.rollback()61 return jsonify({'error': 'Error'}), 50062@post.route('/tags/<tag_id>/post')63def get_post_by_tag(tag_id):64 page = int(request.args.get('page', '0'))65 current_user_id = int(request.args.get('current_user_id', '0'))66 itemPerPage = 2067 tags = Tags.query.filter(Tags.tag_id == tag_id).first()68 num_user = tags.tag_user.count()69 posts = tags.posts \70 .order_by(Post.date_post.desc()) \71 .paginate(page, itemPerPage, error_out=False)72 post_paginated = posts.items73 total = posts.total74 num_page = total // itemPerPage + 175 list = [str(x.author_id) for x in post_paginated]76 str_list = ','.join(set(list))77 with get_connection(post, name='profile') as conn:78 resp = conn.get(ServiceURL.PROFILE_SERVICE + 'list_user_profile?list=' + str_list)79 if resp.status_code != 200:80 raise CustomException('Cannot found post', 404)81 data = resp.json().get('profile')82 list_post = []83 data_index = [x.get('user_id') for x in data]84 for element in post_paginated:85 index = data_index.index(element.author_id)86 json = element.to_json_summary(data[index])87 json['is_liked'] = False88 if current_user_id is not None:89 like = element.like.filter_by(user_id=current_user_id).first()90 if like is not None:91 json['is_liked'] = True92 list_post.append(json)93 is_followed = False94 if current_user_id is not None:95 print(current_user_id)96 tag_user = Tag_user.query.filter(Tag_user.tag_id == tag_id, Tag_user.user_id == current_user_id).first()97 print(tag_user)98 if tag_user is not None:99 is_followed = True100 return jsonify({101 'tag_id': tags.tag_id,102 'tag_name': tags.name,103 'url_image': tags.url_image,104 'Post': list_post,105 'is_followed': is_followed,106 'page': page,107 'itemPerPage': itemPerPage,108 'total_pages': num_page,109 'total': total,...

Full Screen

Full Screen

test_tags_api.py

Source:test_tags_api.py Github

copy

Full Screen

...10TAGS_URL = reverse('recipe:tag-list')11def detail_url(tag_id):12 return reverse('recipe:tag-detail', args=[tag_id])13@pytest.fixture14def tag_user():15 email = 'testme@example.com'16 password = 'passme123'17 user = get_user_model().objects.create_user(18 email=email,19 password=password,20 )21 return user22@pytest.fixture23def api_client(tag_user):24 client = APIClient()25 client.force_authenticate(user=tag_user)26 return client27class TestPublicTagAPI:28 def test_auth_required(self, client):...

Full Screen

Full Screen

109_have_you_bought.py

Source:109_have_you_bought.py Github

copy

Full Screen

1#!/usr/bin/env python32# -*- coding: utf-8 -*-3"""4Created on Fri Jul 21 00:54:02 20175@author: konodera6pid freq7-------------824852 57186913176 470631021137 398711121903 380951247209 300471347626 287411447766 284781526209 261991616797 256211724964 210901822935 208241927966 201932039275 201342145007 196522249683 17508234605 161762427845 161342540706 16054265876 15765274920 151502828204 148022942265 147663030391 140893131717 13949328277 13900338518 137703427104 137193517794 136423646979 134913745066 1328938"""39import pandas as pd40import numpy as np41from tqdm import tqdm42import utils43utils.start(__file__)44#==============================================================================45# load46#==============================================================================47col = [ 'order_id', 'user_id', 'product_id', 'order_number', 'reordered', 'order_number_rev']48log = utils.read_pickles('../input/mk/log', col)49#==============================================================================50# def51#==============================================================================52def make(T):53 """54 T = 055 folder = 'trainT-0'56 """57 58 if T==-1:59 folder = 'test'60 else:61 folder = 'trainT-'+str(T)62 63 log_ = log[log.order_number_rev>T]64 65 user = log_.drop_duplicates('user_id')[['user_id']].reset_index(drop=True)66 67 # have you bought -> hyb68 tag_user = log_[log_.product_id==24852].user_id69 user['hyb_Banana'] = 070 user.loc[user.user_id.isin(tag_user), 'hyb_Banana'] = 171 72 tag_user = log_[log_.product_id==13176].user_id73 user['hyb_BoO-Bananas'] = 074 user.loc[user.user_id.isin(tag_user), 'hyb_BoO-Bananas'] = 175 76 tag_user = log_[log_.product_id==21137].user_id77 user['hyb_Organic-Strawberries'] = 078 user.loc[user.user_id.isin(tag_user), 'hyb_Organic-Strawberries'] = 179 80 tag_user = log_[log_.product_id==21903].user_id81 user['hyb_Organic-Baby-Spinach'] = 082 user.loc[user.user_id.isin(tag_user), 'hyb_Organic-Baby-Spinach'] = 183 84 tag_user = log_[log_.product_id==47209].user_id85 user['hyb_Organic-Hass-Avocado'] = 086 user.loc[user.user_id.isin(tag_user), 'hyb_Organic-Hass-Avocado'] = 187 88 user.to_pickle('../feature/{}/f109_user.p'.format(folder))89#==============================================================================90# main91#==============================================================================92make(0)93make(1)94make(2)95make(-1)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful