def test_delete_right(self): gmr = GatewayMehCreateResource() res = gmr.post() meh = Mechanic.from_json(res.data) gmr1 = GatewayMehResource() res = gmr1.delete(str(meh.id)) self.assertEqual(res.status_code, 204)
def test_post(self): mr = MechanicCreateResource() res = mr.post() self.assertEqual(res.status_code, 201) meh = Mechanic.from_json(res.data) mr1 = MechanicResource() mr1.delete(str(meh.id))
def test_get_right(self): mr1 = MechanicResource() mr2 = MechanicCreateResource() res = mr2.post() meh = Mechanic.from_json(res.data) res = mr1.get(str(meh.id)) self.assertEqual(res.status_code, 200) mr1.delete(str(meh.id))
def get(self, meh_id): if self.exists(meh_id): meh = Mechanics.query.get(meh_id) return Mechanic(meh_id=meh.mongo_id, name=meh.name, lvl=meh.lvl, year=meh.year) else: return None
def test_get_right(self): mr = MechanicResource() mcr = MechanicCreateResource() res = mcr.post() meh = Mechanic.from_json(res.data) gmr = GatewayMehResource() res = gmr.get(str(meh.id)) self.assertEqual(res.status_code, 200) mr.delete(str(meh.id))
def test_get_right(self): rep = MehRepository() meh_id = rep.create('a', 'a', '100') meh1 = rep.get(meh_id) meh2 = Mechanic(meh_id=fields.ObjectId(meh_id), name='a', lvl='a', year='100') self.assertEqual(meh1, meh2) rep.delete(meh_id)
def test_post(self): payload = {'name': 'test', 'lvl': 'test', 'year': '30'} res = requests.post(current_config.MECHANIC_SERVICE_URL + current_config.MECHANIC_SERVICE_PATH + current_config.CREATE_PATH, data=jsonpickle.encode(payload)) self.assertEqual(res.status_code, 201) meh = Mechanic.from_json(res.content) requests.delete(current_config.MECHANIC_SERVICE_URL + current_config.MECHANIC_SERVICE_PATH + "/%s" % str(meh.id))
def read_paginated(self, page_number, page_size): mehs = [] mehs_paginated = Mechanics.query.paginate(page=page_number, per_page=page_size) for meh in mehs_paginated.items: mehs.append( Mechanic(meh_id=meh.mongo_id, name=meh.name, lvl=meh.lvl, year=meh.year)) is_prev_num = (mehs_paginated.prev_num > 0) is_next_num = (mehs_paginated.next_num <= mehs_paginated.pages) return mehs, is_prev_num, is_next_num
def test_patch_add_right(self): sr = FixResource() scr = FixCreateResource() res = scr.post() fix = Fix.from_json(res.data) mr = MechanicResource() mcr = MechanicCreateResource() resm = mcr.post() meh = Mechanic.from_json(resm.data) payload = {'meh_id': meh.id, 'status': 'mehadd'} res = requests.patch(current_config.GATEWAY_URL + current_config.GATEWAY_PATH + '/fixes/add' + '/%s' % fix.id, data=jsonpickle.encode(payload)) self.assertEqual(res.status_code, 201) sr.delete(str(fix.id)) mr.delete(str(meh.id))
def get(self, fix_id): app.logger.info( 'Получен запрос на получение подробной информации о мастерской с идентификатором %s' % fix_id) req = requests.session() for cookie in flask.request.cookies: req.cookies[cookie] = flask.request.cookies[cookie] cookies = req.cookies token = cookies['token'] response = requests.get(current_config.USER_SERVICE_URL + current_config.USER_SERVICE_PATH + "/token", data=jsonpickle.encode({'token': token})) result = flask.Response(status=response.status_code, headers=response.headers.items(), response=response.content) if result.status_code != 200: return result response_fix = requests.get(current_config.FIX_SERVICE_URL + current_config.FIX_SERVICE_PATH + "/%s" % fix_id) if response_fix.status_code == 200: app.logger.info( 'Запрос на получение информации о мастерской с идентификатором %s успешно обработан' % fix_id) else: app.logger.warning( 'Информация о мастерской с идентификатором %s не модет быть получена' % fix_id) result = flask.Response(status=response_fix.status_code, headers=response_fix.headers.items(), response=response_fix.content) return result fix = Fix.from_json(response_fix.content) meh_ids = fix.meh_ids response = fix.to_json() + '\n' if meh_ids != []: for meh_id in meh_ids: try: response_meh = requests.get( current_config.MECHANIC_SERVICE_URL + current_config.MECHANIC_SERVICE_PATH + "/%s" % meh_id) except: response_meh = None if response_meh is not None and response_meh.status_code == 200: app.logger.info( 'Запрос на получение информации о механике с идентификатором %s успешно обработан' % meh_id) meh = Mechanic.from_json(response_meh.content) response = response + '\n' + meh.to_json() else: app.logger.warning( 'Информация о фильме с идентификатором %s не модет быть получена' % meh_id) meh = { 'meh_id': 'Information is not available', 'name': 'Information is not available', 'lvl': 'Information is not available', 'year': 'Information is not available' } response = response + '\n' + json.dumps(meh) response = response + '\n' result = flask.Response(status=response_fix.status_code, headers=response_fix.headers.items(), response=response) app.logger.info( 'Запрос на получение подробной информации о мезанике с идентификатором %s успешно обработан' % fix_id) return result