<s> """<STR_LIT>""" <EOL> import json <EOL> import random <EOL> import unittest <EOL> from flstats import statistics , webstatistics <EOL> from flask import Flask <EOL> from time import sleep <EOL> class FlstatsTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . app = Flask ( __name__ ) <EOL> self . app . register_blueprint ( webstatistics ) <EOL> self . client = self . app . test_client ( ) <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> @ statistics <EOL> def url1 ( ) : <EOL> return random . randint ( <NUM_LIT:0> , <NUM_LIT:1000> ) <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> @ statistics <EOL> def url2 ( ) : <EOL> return random . randint ( <NUM_LIT:0> , <NUM_LIT:1000> ) <EOL> def test_url1 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . get ( '<STR_LIT>' ) <EOL> sleep ( <NUM_LIT:0.1> ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status , '<STR_LIT>' ) <EOL> data = json . loads ( response . data ) <EOL> stats = data [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( stats ) , <NUM_LIT:1> ) <EOL> stat = stats . pop ( ) <EOL> self . assertEqual ( stat [ '<STR_LIT:url>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( stat [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertTrue ( stat [ '<STR_LIT>' ] == stat [ '<STR_LIT>' ] == stat [ '<STR_LIT>' ] ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:9> ) : <EOL> self . client . get ( '<STR_LIT>' ) <EOL> sleep ( <NUM_LIT:0.1> ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status , '<STR_LIT>' ) <EOL> data = json . loads ( response . data ) <EOL> stats = data [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( stats ) , <NUM_LIT:1> ) <EOL> stat = stats . pop ( ) <EOL> self . assertEqual ( stat [ '<STR_LIT:url>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( stat [ '<STR_LIT>' ] , <NUM_LIT:9> ) <EOL> self . assertTrue ( stat [ '<STR_LIT>' ] <= stat [ '<STR_LIT>' ] <= stat [ '<STR_LIT>' ] ) <EOL> def test_url2 ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:20> ) : <EOL> self . client . get ( '<STR_LIT>' ) <EOL> sleep ( <NUM_LIT:0.1> ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status , '<STR_LIT>' ) <EOL> data = json . loads ( response . data ) <EOL> stats = data [ '<STR_LIT>' ] <EOL> self . assertEqual ( len ( stats ) , <NUM_LIT:2> ) <EOL> for stat in stats : <EOL> if stat [ '<STR_LIT:url>' ] == '<STR_LIT>' : <EOL> self . assertEqual ( stat [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> self . assertTrue ( stat [ '<STR_LIT>' ] <= stat [ '<STR_LIT>' ] <= stat [ '<STR_LIT>' ] ) <EOL> elif stat [ '<STR_LIT:url>' ] == '<STR_LIT>' : <EOL> self . assertEqual ( stat [ '<STR_LIT>' ] , <NUM_LIT:20> ) <EOL> self . assertTrue ( stat [ '<STR_LIT>' ] <= stat [ '<STR_LIT>' ] <= stat [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
