def test_post(self): sr = FixCreateResource() res = sr.post() self.assertEqual(res.status_code, 201) sr1 = FixResource() fix = Fix.from_json(res.data) sr1.delete(str(fix.id))
def test_post(self): gsr = GatewayFixCreateResource() res = gsr.post() self.assertEqual(res.status_code, 201) sr = FixResource() mag = Fix.from_json(res.data) sr.delete(str(mag.id))
def test_get_right(self): scr = FixCreateResource() sr = FixResource() res = scr.post() fix = Fix.from_json(res.data) res = sr.get(str(fix.id)) self.assertEqual(res.status_code, 200) sr.delete(str(fix.id))
def test_post(self): payload = {'date_time': '10.10.2010'} res = requests.post(current_config.FIX_SERVICE_URL + current_config.FIX_SERVICE_PATH + current_config.CREATE_PATH, data=jsonpickle.encode(payload)) self.assertEqual(res.status_code, 201) fix = Fix.from_json(res.content) requests.delete(current_config.FIX_SERVICE_URL + current_config.FIX_SERVICE_PATH + "/%s" % str(fix.id))
def test_post_right(self): payload = { 'meh_id': '5c409e117162372684e0d0a9', 'date_time': '22.11.2018_10:15' } res = requests.post( current_config.GATEWAY_URL + current_config.GATEWAY_PATH + current_config.FIX_SERVICE_PATH + current_config.CREATE_PATH, data=jsonpickle.encode(payload)) self.assertEqual(res.status_code, 201) fix = Fix.from_json(res.content) requests.delete(current_config.GATEWAY_URL + current_config.GATEWAY_PATH + current_config.FIX_SERVICE_PATH + "/%s" % str(fix.id))
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 test_patch_return_right(self): payload = {'date_time': '10.10.2010'} res = requests.post(current_config.FIX_SERVICE_URL + current_config.FIX_SERVICE_PATH + current_config.CREATE_PATH, data=jsonpickle.encode(payload)) fix = Fix.from_json(res.content) payload = {'car_id': '14832288', 'status': 'fix'} requests.patch(current_config.FIX_SERVICE_URL + current_config.FIX_SERVICE_PATH + "/%s" % fix.id, data=jsonpickle.encode(payload)) payload['status'] = 'return' res = requests.patch(current_config.FIX_SERVICE_URL + current_config.FIX_SERVICE_PATH + "/%s" % fix.id, data=jsonpickle.encode(payload)) self.assertEqual(res.status_code, 201) requests.delete(current_config.FIX_SERVICE_URL + current_config.FIX_SERVICE_PATH + "/%s" % str(fix.id))
def test_delete_right(self): sr = FixResource() ur = UserResource() scr = FixCreateResource() r = scr.post() fix = Fix.from_json(r.data) u = UserCreateResource() us = u.post() user = User.from_json(us.data) payload = {'fix_id': fix.id, 'name': 'suzuki', 'user_id': user.id} res = requests.post(current_config.GATEWAY_URL + current_config.GATEWAY_PATH + '/cars/add', data=jsonpickle.encode(payload)) #sr.delete(fix.id) car = Car.from_json(res.content) ret_prod = GatewayReturnCar() res = ret_prod.delete(car.id) self.assertEqual(res.status_code, 204) ur.delete(user.id) sr.delete(fix.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