Beispiel #1
0
 def test_post(self):
     ur = UserCreateResource()
     res = ur.post()
     self.assertEqual(res.status_code, 201)
     ur1 = UserResource()
     user = User.from_json(res.data)
     ur1.delete(str(user.id))
Beispiel #2
0
 def test_get_right(self):
     ur = UserResource()
     ucr = UserCreateResource()
     res = ucr.post()
     user = User.from_json(res.data)
     res = ur.get(str(user.id))
     self.assertEqual(res.status_code, 200)
     ur.delete(str(user.id))
Beispiel #3
0
 def test_post(self):
     payload = {'name': 'test', 'password': '******'}
     res = requests.post(current_config.USER_SERVICE_URL +
                         current_config.USER_SERVICE_PATH +
                         current_config.CREATE_PATH,
                         data=jsonpickle.encode(payload))
     self.assertEqual(res.status_code, 201)
     user = User.from_json(res.content)
     requests.delete(current_config.USER_SERVICE_URL +
                     current_config.USER_SERVICE_PATH +
                     "/%s" % str(user.id))
Beispiel #4
0
 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)
Beispiel #5
0
    def post(self):
        app.logger.info('Получен запрос на починку автомобиля')
        paybuy = jsonpickle.decode(flask.request.data)
        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
        user = User.from_json(response.content)

        paybuy1 = {
            'fix_id': str(paybuy["fix_id"]),
            'user_id': user.id,
            'name': str(paybuy["name"])
        }

        response = requests.post(
            current_config.CAR_SERVICE_URL + current_config.CAR_SERVICE_PATH +
            current_config.CREATE_PATH, jsonpickle.encode(paybuy1))
        car = Car.from_json(response.content)
        if response.status_code == 201:
            app.logger.info('Товар с идентификатором %s успешно создан' %
                            str(car.id))
        else:
            app.logger.warning('Товар не может быть создан')
            result = flask.Response(status=response.status_code,
                                    headers=response.headers.items(),
                                    response=response.content)
            return result
        result = flask.Response(status=response.status_code,
                                headers=response.headers.items(),
                                response=response.content)

        paybuy2 = {'car_id': str(car.id), 'status': 'fix'}

        response = requests.patch(
            current_config.FIX_SERVICE_URL + current_config.FIX_SERVICE_PATH +
            "/%s" % paybuy["fix_id"], jsonpickle.encode(paybuy2))
        if response.status_code == 201:
            app.logger.error('Заявки в мастерскую %s  оформлена' %
                             paybuy["fix_id"])
        else:
            result = flask.Response(status=response.status_code,
                                    headers=response.headers.items(),
                                    response=response.content)
            app.logger.info('Магазин %s не существуета' % (paybuy["fix_id"]))
            requests.delete(current_config.CAR_SERVICE_URL +
                            current_config.CAR_SERVICE_PATH + "/" +
                            paybuy2['car_id'])
            return result

        paybuy3 = {'status': 'fix'}
        response = requests.patch(
            current_config.USER_SERVICE_URL +
            current_config.USER_SERVICE_PATH + "/%s" % paybuy1["user_id"],
            jsonpickle.encode(paybuy3))
        if response.status_code == 201:
            app.logger.info('Услуга успешно заказана')
        else:
            result = flask.Response(status=response.status_code,
                                    headers=response.headers.items(),
                                    response=response.content)
            paybuy2['status'] = 'return'
            requests.patch(
                current_config.FIX_SERVICE_URL +
                current_config.FIX_SERVICE_PATH + "/%s" % paybuy["fix_id"],
                jsonpickle.encode(paybuy1))
            requests.delete(current_config.CAR_SERVICE_URL +
                            current_config.CAR_SERVICE_PATH + "/" +
                            paybuy2['car_id'])
            app.logger.warning('Услуга не может быть заказана')
        return result
Beispiel #6
0
    def delete(self, prod_id):
        app.logger.info('Получен запрос на возврат товара')
        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
        user = User.from_json(response.content)
        user_id = user.id

        response = requests.get(current_config.PROD_SERVICE_URL + current_config.PROD_SERVICE_PATH +
                                "/%s" % prod_id)
        if response.status_code == 200:
            app.logger.info('Запрос на получение информации о товаре с идентификатором %s успешно обработан'
                            % prod_id)
        else:
            app.logger.warning('Информация о товаре с идентификатором %s не может быть получена' % prod_id)
            result = flask.Response(status=response.status_code, headers=response.headers.items(),
                                    response=response.content)
            return result

        prod = Prod.from_json(response.content)
        payload1 = {'cell': prod.cell, 'status': 'return'}
        try:
            response = requests.patch(current_config.MAG_SERVICE_URL + current_config.MAG_SERVICE_PATH +
                                    "/%s" % prod.mag_id, jsonpickle.encode(payload1))
            if response.status_code == 201:
                app.logger.info('Освобождение места на витрине в магазине успешно завершен')
            else:
                app.logger.warning('Освобождение места на витрине в магазине не может быть завершено, добавляем запрос в очередь')
                replay_request_queue.send_message(
                    jsonpickle.encode(Request("PROD_RETURN", data={"mag_id": prod.mag_id,
                                                                    "payload": payload1})),
                    "prod_return_handling_request")
        except:
            app.logger.warning(
                'Освобождение места на витрине в магазине не может быть завершено, добавление запроса в очередь')
            replay_request_queue.send_message(jsonpickle.encode(Request("PROD_RETURN", data={"mag_id": prod.mag_id,
                                                                                               "payload": payload1})),
                                              "prod_return_handling_request")
        finally:

            payload3 = {'prod_id': prod_id, 'status': 'return'}
            response = requests.patch(current_config.USER_SERVICE_URL + current_config.USER_SERVICE_PATH +
                                      "/%s" % user_id, jsonpickle.encode(payload3))
            if response.status_code == 201:
                app.logger.info('Возврат товара для пользователя %s успешно произведен' % user_id)
            else:
                payload1['status'] = 'buy'
                requests.patch(current_config.MAG_SERVICE_URL + current_config.MAG_SERVICE_PATH +
                               "/%s" % prod.mag_id, jsonpickle.encode(payload1))
                app.logger.warning('Возврат товара для пользователя %s не может быть произведен' % user_id)
                result = flask.Response(status=response.status_code, headers=response.headers.items(),
                                        response=response.content)
                return result

            response = requests.delete(current_config.PROD_SERVICE_URL + current_config.PROD_SERVICE_PATH +
                                       "/%s" % prod_id)
            result = flask.Response(status=response.status_code, headers=response.headers.items(),
                                    response=response.content)
            if response.status_code == 204:
                app.logger.info('Товар с идентификатором %s успешно удален' % prod_id)
            else:
                payload1['status'] = 'buy'
                requests.patch(current_config.MAG_SERVICE_URL + current_config.MAG_SERVICE_PATH +
                               "/%s" % prod.mag_id, jsonpickle.encode(payload1))
                payload3['status'] = 'buy'
                requests.patch(current_config.USER_SERVICE_URL + current_config.USER_SERVICE_PATH +
                               "/%s" % user_id, jsonpickle.encode(payload3))
                app.logger.warning('Товар с идентификатором %s не может быть удален' % prod_id)
            return result
Beispiel #7
0
    def post(self):
        app.logger.info('Получен запрос на покупку билета')
        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
        user = User.from_json(response.content)
        user_id = user.id
        payload = jsonpickle.decode(flask.request.data)
        payload1 = {'cell': payload["cell"], 'status': 'buy'}
        response = requests.patch(current_config.MAG_SERVICE_URL + current_config.MAG_SERVICE_PATH +
                                  "/%s" % payload["mag_id"], jsonpickle.encode(payload1))
        result = flask.Response(status=response.status_code, headers=response.headers.items(),
                                response=response.content)
        if result.status_code != 201:
            app.logger.error('Покупка товара в магазине с идентификатором %s не может быть выполнена'
                             % payload["mag_id"])
            return result
        else:
            app.logger.info('Пользователь %s взял товар с полки в магазине с идентификатором %s'
                            % (user_id, payload["mag_id"]))

        response = requests.post(current_config.PROD_SERVICE_URL + current_config.PROD_SERVICE_PATH +
                                 current_config.CREATE_PATH, jsonpickle.encode(payload))
        prod = Prod.from_json(response.content)
        if response.status_code == 201:
            app.logger.info('Товра с идентификатором %s успешно создан' % str(prod.id))
        else:
            payload1['status'] = 'return'
            requests.patch(current_config.MAG_SERVICE_URL + current_config.MAG_SERVICE_PATH + "/" +
                           payload["mag_id"], jsonpickle.encode(payload1))
            app.logger.warning('Товар не может быть создан')
            result = flask.Response(status=response.status_code, headers=response.headers.items(),
                                    response=response.content)
            return result

        result = flask.Response(status=response.status_code, headers=response.headers.items(),
                                response=response.content)

        payload3 = {'prod_id': str(prod.id), 'status': 'buy'}
        response = requests.patch(current_config.USER_SERVICE_URL + current_config.USER_SERVICE_PATH +
                                  "/%s" % user_id, jsonpickle.encode(payload3))
        if response.status_code == 201:
            app.logger.info('Покупка товара для пользователя успешно произведена')
        else:
            result = flask.Response(status=response.status_code, headers=response.headers.items(),
                                    response=response.content)
            payload1['status'] = 'return'
            requests.patch(current_config.MAG_SERVICE_URL + current_config.MAG_SERVICE_PATH + "/" +
                           payload["mag_id"], jsonpickle.encode(payload1))
            requests.delete(current_config.PROD_SERVICE_URL + current_config.PROD_SERVICE_PATH + "/" +
                            payload3['prod_id'])
            app.logger.warning('Покупка товара не может быть завершена')
        return result