예제 #1
0
 def test_post(self):
     sr = MagCreateResource()
     res = sr.post()
     self.assertEqual(res.status_code, 201)
     sr1 = MagResource()
     mag = Mag.from_json(res.data)
     sr1.delete(str(mag.id))
예제 #2
0
 def get(self, mag_id):
     if self.exists(mag_id):
         mag = Mags.query.get(mag_id)
         seats = jsonpickle.decode(mag.seats)
         return Mag(mag_id=mag.mongo_id, kassir_id=mag.kassir_id, date_time=mag.date_time, seats=seats)
     else:
         return None
예제 #3
0
 def test_get_right(self):
     scr = MagCreateResource()
     sr = MagResource()
     res = scr.post()
     mag = Mag.from_json(res.data)
     res = sr.get(str(mag.id))
     self.assertEqual(res.status_code, 200)
     sr.delete(str(mag.id))
예제 #4
0
 def read_paginated(self, page_number, page_size):
     mags = []
     mags_paginated = Mags.query.paginate(page=page_number, per_page=page_size)
     for mag in mags_paginated.items:
         seats = jsonpickle.decode(mag.seats)
         mags.append(Mag(mag_id=mag.mongo_id, kassir_id=mag.kassir_id, date_time=mag.date_time,
                               seats=seats))
     is_prev_num = (mags_paginated.prev_num > 0)
     is_next_num = (mags_paginated.next_num <= mags_paginated.pages)
     return mags, is_prev_num, is_next_num
예제 #5
0
 def test_post(self):
     payload = {
         'kassir_id': '5bfbacaf102bd238e0238fa5',
         'datetime': '10.10.2010',
         'col': 30
     }
     res = requests.post(current_config.MAG_SERVICE_URL +
                         current_config.MAG_SERVICE_PATH +
                         current_config.CREATE_PATH,
                         data=jsonpickle.encode(payload))
     self.assertEqual(res.status_code, 201)
     mag = Mag.from_json(res.content)
     requests.delete(current_config.MAG_SERVICE_URL +
                     current_config.MAG_SERVICE_PATH + "/%s" % str(mag.id))
예제 #6
0
    def get(self, mag_id):
        app.logger.info('Получен запрос на получение подробной информации о магазине с идентификатором %s' % mag_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_mag = requests.get(current_config.MAG_SERVICE_URL + current_config.MAG_SERVICE_PATH +
                                       "/%s" % mag_id)
        if response_mag.status_code == 200:
            app.logger.info('Запрос на получение информации о магазине с идентификатором %s успешно обработан'
                            % mag_id)
        else:
            app.logger.warning('Информация о магазине с идентификатором %s не модет быть получена' % mag_id)
            result = flask.Response(status=response_mag.status_code, headers=response_mag.headers.items(),
                                    response=response_mag.content)
            return result

        mag = Mag.from_json(response_mag.content)
        kassir_id = str(mag.kassir_id)

        try:
            response_kassir = requests.get(current_config.KASSIR_SERVICE_URL + current_config.KASSIR_SERVICE_PATH +
                                          "/%s" % kassir_id)
        except:
            response_kassir = None
        if response_kassir is not None and response_kassir.status_code == 200:
            app.logger.info('Запрос на получение информации о кассире с идентификатором %s успешно обработан'
                            % kassir_id)
            kassir = Kassir.from_json(response_kassir.content)
            response = mag.to_json() + '\n' + kassir.to_json()
        else:
            app.logger.warning('Информация о касире с идентификатором %s не модет быть получена' % kassir_id)
            kassir = {'kassir_id': 'Not available', 'name': 'Not available',
                     'stage': 'Not available', 'year': 'Not available'}
            response = mag.to_json() + '\n' + json.dumps(kassir)

        result = flask.Response(status=response_mag.status_code, headers=response_mag.headers.items(),
                                response=response)
        app.logger.info('Запрос на получение подробной информации о магазине с идентификатором %s успешно обработан'
                        % mag_id)
        return result