<s> import datetime <EOL> import json <EOL> import logging <EOL> from django . test import TestCase <EOL> from huxley . logging . handlers import DatabaseHandler <EOL> from huxley . logging . models import LogEntry <EOL> class LogEntryTestCase ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def test_valid ( self ) : <EOL> log_entry = LogEntry . objects . create ( <EOL> level = '<STR_LIT>' , <EOL> message = '<STR_LIT>' , <EOL> timestamp = datetime . datetime ( <NUM_LIT> , <NUM_LIT:0> <NUM_LIT:5> , <NUM_LIT> ) , <EOL> uri = "<STR_LIT>" , <EOL> status_code = <NUM_LIT:200> , <EOL> username = '<STR_LIT:username>' ) <EOL> self . assertEqual ( log_entry . level , '<STR_LIT>' ) <EOL> self . assertEqual ( log_entry . message , '<STR_LIT>' ) <EOL> self . assertEqual ( log_entry . timestamp , datetime . datetime ( <NUM_LIT> , <NUM_LIT:0> <NUM_LIT:5> , <NUM_LIT> ) ) <EOL> self . assertEqual ( log_entry . uri , "<STR_LIT>" ) <EOL> self . assertEqual ( log_entry . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( log_entry . username , '<STR_LIT:username>' ) <EOL> class DatabaseHandlerTestCase ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def test_valid ( self ) : <EOL> formatter = logging . Formatter ( '<STR_LIT>' ) <EOL> message = "<STR_LIT>" <EOL> uri = "<STR_LIT>" <EOL> status_code = <NUM_LIT> <EOL> username = '<STR_LIT:username>' <EOL> log_record = logging . makeLogRecord ( { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : json . dumps ( { <EOL> '<STR_LIT:message>' : message , <EOL> '<STR_LIT>' : uri , <EOL> '<STR_LIT>' : status_code , <EOL> '<STR_LIT:username>' : username } ) , <EOL> '<STR_LIT:args>' : ( ) , <EOL> '<STR_LIT>' : None } ) <EOL> handler = DatabaseHandler ( ) <EOL> handler . formatter = formatter <EOL> handler . emit ( log_record ) <EOL> log_entry = LogEntry . objects . get ( id = <NUM_LIT:1> ) <EOL> self . assertEqual ( log_entry . level , log_record . levelname ) <EOL> self . assertEqual ( log_entry . message , message ) <EOL> self . assertEqual ( log_entry . timestamp , <EOL> datetime . datetime . strptime ( log_record . asctime , "<STR_LIT>" ) ) <EOL> self . assertEqual ( log_entry . uri , uri ) <EOL> self . assertEqual ( log_entry . status_code , status_code ) <EOL> self . assertEqual ( log_entry . username , username ) </s>
