def test_get_paging_0(self): '''paging番号が0またはそれ以下の場合,強制的に1のpagingを返却 ''' self.load_fixtures() thread = Thread() test_data = self.filter_test_data( table='thread', field='thread_id', target=[1, 2, 5, 6, 7, 8, 9, 10, 11, 12]) # paging = 0 actual = thread.get_all_by_c_id(category_id=1, sort_id=ID_ASC, paging=0) expect = test_data self.assertListEqual(expect, actual) # paging = -1 actual = thread.get_all_by_c_id(category_id=1, sort_id=ID_ASC, paging=0) self.assertListEqual(expect, actual)
def get_all_by_c_id(): '''category_idに紐づけられたthreadリストの取得 Args: QueryString: category_id: カテゴリID sort_id: ソートID paging: ページング番号 Returns: 200: list(dict): threads情報(dict)のリスト 400: パラメータ不正 500: サーバエラー ページング番号 1の時は1~10,2の時11~20のthreadを取得 ''' try: params = parse_params(request.args) category_id = int(params.get('category_id')) sort_id = int(params.get('sort_id')) paging = int(params.get('paging')) if not category_id or not sort_id or not paging: return make_response('', 400) result = Thread.get_all_by_c_id( category_id, sort_id, paging ) return jsonify(result) except Exception as e: return make_response('', 500)
def test_get_by_c_id_no_thread(self): '''category_idに紐づくthreadが存在しない場合 ''' self.load_fixtures() thread = Thread() actual = thread.get_all_by_c_id(category_id=100, sort_id=ID_ASC, paging=1) self.assertListEqual([], actual)
def test_get_sort_speed_desc_2(self): '''人気高い順2 ''' self.load_fixtures() thread = Thread() test_data = self.filter_test_data(table='thread', field='thread_id', target=[4, 3]) actual = thread.get_all_by_c_id(category_id=2, sort_id=SPEED_DESC, paging=1) expect = test_data self.assertListEqual(expect, actual)
def test_get_paging_outside(self): '''paging番号による取得できるthread数が0の場合,最後のpagingを表示する ''' self.load_fixtures() thread = Thread() test_data = self.filter_test_data(table='thread', field='thread_id', target=[23]) actual = thread.get_all_by_c_id(category_id=1, sort_id=ID_ASC, paging=100) expect = test_data self.assertListEqual(expect, actual)
def test_get_paging_3(self): '''ページング21-30 ''' self.load_fixtures() thread = Thread() test_data = self.filter_test_data(table='thread', field='thread_id', target=[23]) actual = thread.get_all_by_c_id(category_id=1, sort_id=ID_ASC, paging=3) expect = test_data self.assertListEqual(expect, actual)
def test_get_paging_2(self): '''ページング11-20 ''' self.load_fixtures() thread = Thread() test_data = self.filter_test_data( table='thread', field='thread_id', target=[13, 14, 15, 16, 17, 18, 19, 20, 21, 22]) actual = thread.get_all_by_c_id(category_id=1, sort_id=ID_ASC, paging=2) expect = test_data self.assertListEqual(expect, actual)
def test_get_paging_1(self): '''ページング1-10 ''' self.load_fixtures() thread = Thread() test_data = self.filter_test_data( table='thread', field='thread_id', target=[1, 2, 5, 6, 7, 8, 9, 10, 11, 12]) actual = thread.get_all_by_c_id(category_id=1, sort_id=ID_ASC, paging=1) expect = test_data self.assertListEqual(expect, actual)
def test_get_sort_num_comment_asc(self): '''コメント数少ない順 ''' self.load_fixtures() thread = Thread() test_data = self.filter_test_data( table='thread', field='thread_id', target=[1, 2, 23, 14, 7, 8, 9, 10, 11, 12]) actual = thread.get_all_by_c_id(category_id=1, sort_id=SPEED_ASC, paging=1) expect = test_data self.assertListEqual(expect, actual)
def test_get_sort_id_desc(self): '''ID降順 ''' self.load_fixtures() thread = Thread() test_data = self.filter_test_data(table='thread', field='category_id', target=1, paging=1, reverse=True) actual = thread.get_all_by_c_id(category_id=1, sort_id=ID_DESC, paging=1) expect = test_data self.assertListEqual(expect, actual)