def test_create(self): rep = FixRepository() id1 = rep.create('01.01.2018_12:00') id2 = rep.create('01.01.2018_12:00') self.assertNotEqual(id1, id2) rep.delete(id1) rep.delete(id2)
def test_rem_meh_true(self): rep = FixRepository() fix_id = rep.create('01.01.2018_12:00') rep.add_meh(fix_id, '1432288') boolean = rep.rem_meh(fix_id, '1432288') self.assertTrue(boolean) rep.delete(fix_id)
def get(self): repo = FixRepository() app.logger.info('Получен запрос на получение списка сеансов') try: args = self.parser.parse_args(strict=True) except: args = {'page': 1, 'page_size': 5} app.logger.info( 'Номер страницы: %d; количество сеансов на странице: %d' % (args['page'], args['page_size'])) fixes_list, is_prev_page, is_next_page = repo.read_paginated( page_number=args['page'], page_size=args['page_size']) fixes = '' for fix in fixes_list: fixes += fix.to_json() + '\n' dictr = {"is_prev_page": is_prev_page, "is_next_page": is_next_page} fixes += "\n" + json.dumps(dictr) response = app.make_response("") response.status_code = 200 response.content_type = "application/json" response.data = fixes app.logger.info('Запрос на получение списка сеансов успешно обработан') return response
def test_exists(self): rep = FixRepository() fix_id = rep.create('01.01.2018_12:00') boolean = rep.exists(fix_id) self.assertTrue(boolean) rep.delete(fix_id)
def test_rem_meh_false(self): rep = FixRepository() boolean = rep.rem_meh('888888888', '1488322') self.assertFalse(boolean)
def test_add_meh_false(self): rep = FixRepository() boolean = rep.add_meh('5bd897f8af', '14488322') self.assertFalse(boolean)
def test_add_car_true(self): rep = FixRepository() fix_id = rep.create('01.01.2018_12:00') boolean = rep.add_car(fix_id, '1488322') self.assertTrue(boolean) rep.delete(fix_id)
def test_delete(self): rep = FixRepository() fix_id = rep.create('01.01.2018_12:00') rep.delete(fix_id) self.assertFalse(rep.exists(fix_id))
def test_read_paginated(self): rep = FixRepository() fixes = rep.read_paginated(1, 5) self.assertLessEqual(len(fixes), 5)
def test_get_false(self): rep = FixRepository() mag = rep.get('5bd89b59af1') self.assertIsNone(mag)
from fix import app from flask_restful import Resource, abort, reqparse from fix.repository.fix_repository import FixRepository import jsonpickle import flask import json repo = FixRepository() def abort_if_fix_doesnt_exist(fix_id): if not repo.exists(fix_id): app.logger.error('Мастерская с идентификатором %s не существует!', fix_id) abort(404, message="Fix {} doesn't exist".format(fix_id)) class FixResource(Resource): def get(self, fix_id): app.logger.info( 'Получен запрос на получение информации о мастерской с идентификатором %s' % fix_id) abort_if_fix_doesnt_exist(fix_id) fix = repo.get(fix_id) response = app.make_response("") response.status_code = 200 response.content_type = "application/json" response.data = fix.to_json() #jsonpickle.encode(mag) app.logger.info( 'Запрос на получение информации о мастерской с идентификатором %s успешно обработан' % fix_id)