def setup_user(): user = User() user.create('test_user','test_pass','*****@*****.**') project = Project() project.create('scraped','scraped') project.add_entry('entry','entry','localhost') user.add_project(project.get_id())
def setup_project_update(): user = User() user.create('test_update_user','test_password','*****@*****.**') project = Project() project.create('project update','test project update') user.add_project(project.get_id()) project.add_entry('data','test data','data')
def setup_test_update(): mongo = MongoModel(project='test_api_update',collection='test_api_entry') mongo.insert({'a':1}) user = User() user.create('test_user_api_update','test_pass','*****@*****.**') project = Project() project.create('test api update','scraped') project.add_entry('test api entry','entry','localhost') user.add_project(project.get_id())
def setup_user_project(): # now create user user = User() user.create('test_user_update_project','test_pass','*****@*****.**') # create project project = Project() project.create('project update','project update content') # associate project user.add_project(project.get_id())
def post(self): api_key = request.args.get('api_key') user = User() user.api_login(api_key) if not user.is_authenticated(): return jsonify({'status':False}) data = request.json project = Project() project.create(data['name'],data['description']) user.add_project(str(project.get_id())) return jsonify({'status':True})
def test_user_project_withdraw(): user = User() user.login('test_user_list','test_pass') project = Project() project.find('project list 3') user.add_project(project.get_id()) api_key = user.user.auth_token test_client = webapp.app.test_client() url = '/api/project/%s/?api_key=%s' % (project.get_id(),api_key) data = {'project':'project_list_3','action':'withdraw'} result = test_client.put(url,data=json.dumps(data),content_type='application/json') print result.data user.login('test_user_list','test_pass') print user.user.project print project.get_id() print project.project.name assert not str(project.get_id()) in user.user.project
def put(self,project_id): api_key = request.args.get('api_key') project = Project() project.get(project_id) user = User() user.api_login(api_key) data = request.json if data.get('action') == 'join': user.add_project(project.get_id()) return jsonify({'status':True,'msg':'join project'}) elif data.get('action') == 'withdraw': user.remove_project(project.get_id()) return jsonify({'status':True,'msg':'withdrawn from project'}) if not authorized(api_key,project_id): return jsonify({'status':False,'msg':'unauthorized'}) if not project.get_id() in user.user.project: return jsonify({'status':False,'msg':'project not in user'}) project.project.description = data['description'] project.save() return jsonify({'status':True})
def setup_user_project_list(): user = User() user.create('test_user_list','test_pass','*****@*****.**') project = Project() project.create('project list 1','project content 1') user.add_project(project.get_id()) project = Project() project.create('project list 2','project content 2') user.add_project(project.get_id()) project = Project() project.create('project list 3','project content 3') user.add_project(project.get_id())
def setup_project_delete(): user = User() user.create('test_user_delete_api_project','test_pass','*****@*****.**') project = Project() project.create('project 1','project content 1') user.add_project(project.get_id())