<s> import unittest <EOL> import random <EOL> import string <EOL> import datetime <EOL> from reap . api . timesheet import * <EOL> def random_string ( length = <NUM_LIT:5> ) : <EOL> return '<STR_LIT>' . join ( random . choice ( string . ascii_lowercase ) for x in xrange ( length ) ) <EOL> class TimesheetTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> with open ( '<STR_LIT>' ) as info : <EOL> self . base_uri = info . readline ( ) . strip ( ) <EOL> self . username = info . readline ( ) . strip ( ) <EOL> self . password = info . readline ( ) . strip ( ) <EOL> self . ts = Timesheet ( self . base_uri , self . username , self . password ) <EOL> class TestTimesheetLogin ( TimesheetTest ) : <EOL> def runTest ( self ) : <EOL> ts = Timesheet ( self . base_uri , self . username , self . password ) <EOL> self . assertIsNotNone ( ts ) <EOL> self . assertIsNotNone ( ts . id ) <EOL> self . assertRaises ( ValueError , Timesheet , random_string ( ) , random_string ( ) , random_string ( ) ) <EOL> class TestProjectTask ( TimesheetTest ) : <EOL> def test_get_projects ( self ) : <EOL> projs = self . ts . projects ( ) <EOL> self . assertIsNotNone ( projs ) <EOL> self . assertTrue ( len ( projs ) > <NUM_LIT:0> ) <EOL> for proj in projs : <EOL> self . assertIsNotNone ( proj . name ) <EOL> self . assertIsNotNone ( proj . client ) <EOL> self . assertIsNotNone ( proj . id ) <EOL> def test_get_tasks ( self ) : <EOL> projs = self . ts . projects ( ) <EOL> for proj in projs : <EOL> tasks = proj . tasks ( ) <EOL> self . assertIsNotNone ( tasks ) <EOL> self . assertTrue ( len ( tasks ) > <NUM_LIT:0> ) <EOL> for task in tasks : <EOL> self . assertEqual ( task . project . id , proj . id ) <EOL> self . assertIsNotNone ( task . name ) <EOL> self . assertIsNotNone ( task . id ) <EOL> self . assertIsNotNone ( task . billable ) <EOL> class TestEntry ( TimesheetTest ) : <EOL> def test_get ( self ) : <EOL> entries = self . ts . entries ( ) <EOL> self . assertIsNotNone ( entries ) <EOL> for entry in entries : <EOL> self . assertIsNotNone ( entry . id ) <EOL> self . assertIsNotNone ( entry . spent_at ) <EOL> self . assertIsNotNone ( entry . user_id ) <EOL> self . assertIsNotNone ( entry . client_name ) <EOL> self . assertIsNotNone ( entry . project_id ) <EOL> self . assertIsNotNone ( entry . project_name ) <EOL> self . assertIsNotNone ( entry . task_id ) <EOL> self . assertIsNotNone ( entry . task_name ) <EOL> self . assertIsNotNone ( entry . hours ) <EOL> self . assertIsNotNone ( entry . notes ) <EOL> if entry . started : <EOL> self . assertIsNotNone ( entry . timer_started ) <EOL> self . assertIsNotNone ( entry . timer_created ) <EOL> self . assertIsNotNone ( entry . timer_updated ) <EOL> def test_get_specific_day ( self ) : <EOL> project = self . ts . projects ( ) [ <NUM_LIT:0> ] <EOL> task = project . tasks ( ) [ <NUM_LIT:0> ] <EOL> tomorrow = datetime . datetime . utcnow ( ) . date ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( self . ts . entries ( day_of_year = tomorrow . timetuple ( ) . tm_yday ) ) , <NUM_LIT:0> ) <EOL> self . ts . create_entry ( project . id , task . id , hours = str ( <NUM_LIT:2> ) , notes = "<STR_LIT>" , spent_at = str ( tomorrow ) ) <EOL> new_entry = self . ts . entries ( day_of_year = tomorrow . timetuple ( ) . tm_yday , year = tomorrow . year ) [ <NUM_LIT:0> ] <EOL> self . assertIsNotNone ( new_entry ) <EOL> self . assertEqual ( new_entry . spent_at , str ( tomorrow ) ) <EOL> self . assertEqual ( new_entry . notes , "<STR_LIT>" ) <EOL> new_entry . delete ( ) <EOL> def test_create ( self ) : <EOL> project = self . ts . projects ( ) [ <NUM_LIT:0> ] <EOL> task = project . tasks ( ) [ <NUM_LIT:0> ] <EOL> entry = self . ts . create_entry ( project . id , task . id ) <EOL> self . assertIsNotNone ( entry ) <EOL> self . assertTrue ( entry . started ) <EOL> self . assertEqual ( entry . project_id , project . id ) <EOL> self . assertTrue ( ( entry . timer_created - datetime . datetime . utcnow ( ) ) < datetime . timedelta ( minutes = <NUM_LIT:1> ) ) <EOL> entry . delete ( ) <EOL> def test_create_specific_day ( self ) : <EOL> project = self . ts . projects ( ) [ <NUM_LIT:0> ] <EOL> task = project . tasks ( ) [ <NUM_LIT:0> ] <EOL> tomorrow = datetime . datetime . utcnow ( ) . date ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> entry = self . ts . create_entry ( project . id , task . id , hours = str ( <NUM_LIT:8> ) , spent_at = str ( tomorrow ) ) <EOL> self . assertIsNotNone ( entry ) <EOL> self . assertEqual ( entry . project_id , project . id ) <EOL> self . assertEqual ( entry . spent_at , str ( tomorrow ) ) <EOL> entry . delete ( ) <EOL> def test_delete ( self ) : <EOL> entries_count = len ( self . ts . entries ( ) ) <EOL> project = self . ts . projects ( ) [ <NUM_LIT:0> ] <EOL> task = project . tasks ( ) [ <NUM_LIT:0> ] <EOL> entry = self . ts . create_entry ( project . id , task . id ) <EOL> self . assertEqual ( entries_count + <NUM_LIT:1> , len ( self . ts . entries ( ) ) ) <EOL> entry . delete ( ) <EOL> self . assertEqual ( entries_count , len ( self . ts . entries ( ) ) ) <EOL> def test_update_notes ( self ) : <EOL> project = self . ts . projects ( ) [ <NUM_LIT:0> ] <EOL> task = project . tasks ( ) [ <NUM_LIT:0> ] <EOL> entry = self . ts . create_entry ( project . id , task . id ) <EOL> orig_notes = entry . notes <EOL> new_note = random_string ( ) <EOL> entry . update ( notes = new_note ) <EOL> self . assertEqual ( new_note , entry . notes ) <EOL> new_entry = None <EOL> for test_entry in self . ts . entries ( ) : <EOL> if entry . id == test_entry . id : <EOL> new_entry = test_entry <EOL> self . assertIsNotNone ( new_entry ) <EOL> self . assertEqual ( new_entry . notes , new_note ) <EOL> entry . delete ( ) <EOL> def test_update_hours ( self ) : <EOL> project = self . ts . projects ( ) [ <NUM_LIT:0> ] <EOL> task = project . tasks ( ) [ <NUM_LIT:0> ] <EOL> entry = self . ts . create_entry ( project . id , task . id ) <EOL> orig_hours = entry . hours <EOL> new_hours = random . randint ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> entry . update ( hours = new_hours ) <EOL> self . assertEqual ( new_hours , entry . hours ) <EOL> new_entry = None <EOL> for test_entry in self . ts . entries ( ) : <EOL> if entry . id == test_entry . id : <EOL> new_entry = test_entry <EOL> self . assertIsNotNone ( new_entry ) <EOL> self . assertEqual ( new_entry . hours , new_hours ) <EOL> entry . delete ( ) <EOL> def test_update_project ( self ) : <EOL> projects = self . ts . projects ( ) <EOL> project = projects [ <NUM_LIT:0> ] <EOL> task = project . tasks ( ) [ <NUM_LIT:0> ] <EOL> new_proj = projects [ <NUM_LIT:1> ] <EOL> new_task = new_proj . tasks ( ) [ <NUM_LIT:0> ] <EOL> entry = self . ts . create_entry ( project . id , task . id ) <EOL> entry . update ( project_id = new_proj . id , task_id = new_task . id ) <EOL> self . assertEqual ( new_proj . id , entry . project_id ) <EOL> self . assertEqual ( new_proj . name , entry . project_name ) <EOL> self . assertEqual ( new_task . id , entry . task_id ) <EOL> self . assertEqual ( new_task . name , entry . task_name ) <EOL> new_entry = None <EOL> for test_entry in self . ts . entries ( ) : <EOL> if entry . id == test_entry . id : <EOL> new_entry = test_entry <EOL> self . assertIsNotNone ( new_entry ) <EOL> self . assertEqual ( new_entry . project_id , new_proj . id ) <EOL> self . assertEqual ( new_entry . task_id , new_task . id ) <EOL> entry . delete ( ) <EOL> def test_timer ( self ) : <EOL> project = self . ts . projects ( ) [ <NUM_LIT:0> ] <EOL> task = project . tasks ( ) [ <NUM_LIT:0> ] <EOL> entry = self . ts . create_entry ( project . id , task . id ) <EOL> self . assertTrue ( entry . started ) <EOL> entry . stop ( ) <EOL> self . assertFalse ( entry . started ) <EOL> new_entry = None <EOL> for test_entry in self . ts . entries ( ) : <EOL> if entry . id == test_entry . id : <EOL> new_entry = test_entry <EOL> self . assertIsNotNone ( new_entry ) <EOL> self . assertFalse ( new_entry . started ) <EOL> entry . start ( ) <EOL> self . assertTrue ( entry . started ) <EOL> new_entry = None <EOL> for test_entry in self . ts . entries ( ) : <EOL> if entry . id == test_entry . id : <EOL> new_entry = test_entry <EOL> self . assertIsNotNone ( new_entry ) <EOL> self . assertTrue ( new_entry . started ) <EOL> entry . delete ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
