<s> from __future__ import with_statement , print_function <EOL> from datetime import datetime <EOL> import unittest <EOL> import os <EOL> from trello import TrelloClient , Board <EOL> class TrelloBoardTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . _trello = TrelloClient ( os . environ [ '<STR_LIT>' ] , <EOL> token = os . environ [ '<STR_LIT>' ] ) <EOL> for b in cls . _trello . list_boards ( ) : <EOL> if b . name == os . environ [ '<STR_LIT>' ] . encode ( '<STR_LIT:utf-8>' ) : <EOL> cls . _board = b <EOL> break <EOL> if not cls . _board : <EOL> cls . fail ( "<STR_LIT>" ) <EOL> cls . _list = cls . _board . add_list ( str ( datetime . now ( ) ) ) <EOL> def _add_card ( self , name , description = None ) : <EOL> try : <EOL> card = self . _list . add_card ( name , description ) <EOL> self . assertIsNotNone ( card , msg = "<STR_LIT>" ) <EOL> self . assertIsNotNone ( card . id , msg = "<STR_LIT>" ) <EOL> self . assertEqual ( card . name , name . encode ( '<STR_LIT:utf-8>' ) ) <EOL> return card <EOL> except Exception as e : <EOL> print ( str ( e ) ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> def _add_checklist ( self , card , name , items = [ ] , itemstates = None ) : <EOL> checklist = card . add_checklist ( name , items , itemstates ) <EOL> self . assertIsNotNone ( checklist , msg = "<STR_LIT>" ) <EOL> self . assertIsNotNone ( checklist . id , msg = "<STR_LIT>" ) <EOL> self . assertEquals ( checklist . name , name ) <EOL> return checklist <EOL> def test_get_cards ( self ) : <EOL> for card in self . _board . get_cards ( ) : <EOL> card . delete ( ) <EOL> nb_cards = <NUM_LIT:3> <EOL> names = [ "<STR_LIT>" + str ( i ) for i in range ( nb_cards ) ] <EOL> for i in range ( nb_cards ) : <EOL> self . _add_card ( names [ i ] ) <EOL> cards = self . _board . get_cards ( ) <EOL> self . assertEquals ( len ( cards ) , nb_cards ) <EOL> self . assertEquals ( len ( cards ) , len ( self . _board . open_cards ( ) ) ) <EOL> for card in cards : <EOL> self . assertTrue ( card . name . decode ( '<STR_LIT:utf-8>' ) in names , '<STR_LIT>' ) <EOL> self . assertIsInstance ( self . _board . all_cards ( ) , list ) <EOL> self . assertIsInstance ( self . _board . open_cards ( ) , list ) <EOL> self . assertIsInstance ( self . _board . closed_cards ( ) , list ) <EOL> def test_fetch_action_limit ( self ) : <EOL> card = self . _add_card ( '<STR_LIT>' ) <EOL> card . set_closed ( True ) <EOL> self . _board . fetch_actions ( action_filter = '<STR_LIT:all>' , action_limit = <NUM_LIT:2> ) <EOL> actions = sorted ( self . _board . actions , key = lambda act : act [ '<STR_LIT:date>' ] , reverse = True ) <EOL> self . assertEqual ( len ( actions ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( actions [ <NUM_LIT:0> ] [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> self . assertFalse ( actions [ <NUM_LIT:0> ] [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( actions [ <NUM_LIT:1> ] [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> def test_fetch_action_filter ( self ) : <EOL> card = self . _add_card ( '<STR_LIT>' ) <EOL> card . set_closed ( True ) <EOL> self . _board . fetch_actions ( action_filter = '<STR_LIT>' , action_limit = <NUM_LIT:1> ) <EOL> actions = self . _board . actions <EOL> self . assertEqual ( len ( actions ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( actions [ <NUM_LIT:0> ] [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> def test_delete_cards ( self ) : <EOL> self . _add_card ( "<STR_LIT>" ) <EOL> cards = self . _board . open_cards ( ) <EOL> nb_open_cards = len ( cards ) <EOL> for card in cards : <EOL> card . delete ( ) <EOL> self . _board . fetch_actions ( action_filter = '<STR_LIT:all>' , action_limit = nb_open_cards ) <EOL> self . assertEquals ( len ( self . _board . actions ) , nb_open_cards ) <EOL> for action in self . _board . actions : <EOL> self . assertEqual ( action [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> def test_close_cards ( self ) : <EOL> nb_closed_cards = len ( self . _board . closed_cards ( ) ) <EOL> self . _add_card ( "<STR_LIT>" ) <EOL> cards = self . _board . open_cards ( ) <EOL> nb_open_cards = len ( cards ) <EOL> for card in cards : <EOL> card . set_closed ( True ) <EOL> cards_after = self . _board . closed_cards ( ) <EOL> nb_cards_after = len ( cards_after ) <EOL> self . assertEquals ( nb_cards_after , nb_closed_cards + nb_open_cards ) <EOL> def test_all_cards_reachable ( self ) : <EOL> if not len ( self . _board . open_cards ( ) ) : <EOL> self . _add_card ( "<STR_LIT>" ) <EOL> if not len ( self . _board . closed_cards ( ) ) : <EOL> card = self . _add_card ( "<STR_LIT>" ) <EOL> card . set_closed ( True ) <EOL> self . assertEqual ( len ( self . _board . all_cards ( ) ) , <EOL> len ( self . _board . open_cards ( ) ) + len ( self . _board . closed_cards ( ) ) ) <EOL> def test70_all_members ( self ) : <EOL> self . assertTrue ( len ( self . _board . all_members ( ) ) > <NUM_LIT:0> ) <EOL> def test71_normal_members ( self ) : <EOL> self . assertTrue ( len ( self . _board . normal_members ( ) ) >= <NUM_LIT:0> ) <EOL> def test72_admin_members ( self ) : <EOL> self . assertTrue ( len ( self . _board . admin_members ( ) ) > <NUM_LIT:0> ) <EOL> def test73_owner_members ( self ) : <EOL> members = self . _board . owner_members ( ) <EOL> self . assertTrue ( len ( members ) > <NUM_LIT:0> ) <EOL> member = members [ <NUM_LIT:0> ] . fetch ( ) <EOL> self . assertNotEqual ( member . status , None ) <EOL> self . assertNotEqual ( member . id , None ) <EOL> self . assertNotEqual ( member . bio , None ) <EOL> self . assertNotEqual ( member . url , None ) <EOL> self . assertNotEqual ( member . username , None ) <EOL> self . assertNotEqual ( member . full_name , None ) <EOL> self . assertNotEqual ( member . initials , None ) <EOL> member2 = self . _trello . get_member ( member . id ) <EOL> self . assertEqual ( member . username , member2 . username ) <EOL> def test90_get_board ( self ) : <EOL> board = self . _trello . get_board ( self . _board . id ) <EOL> self . assertEqual ( self . _board . name , board . name ) <EOL> def test100_add_board ( self ) : <EOL> test_board = self . _trello . add_board ( "<STR_LIT>" ) <EOL> test_list = test_board . add_list ( "<STR_LIT>" ) <EOL> test_list . add_card ( "<STR_LIT>" ) <EOL> open_boards = self . _trello . list_boards ( board_filter = "<STR_LIT>" ) <EOL> self . assertEqual ( len ( [ x for x in open_boards if x . name == "<STR_LIT>" . encode ( '<STR_LIT:utf-8>' ) ] ) , <NUM_LIT:1> ) <EOL> def test110_copy_board ( self ) : <EOL> boards = self . _trello . list_boards ( board_filter = "<STR_LIT>" ) <EOL> source_board = next ( x for x in boards if x . name == "<STR_LIT>" . encode ( '<STR_LIT:utf-8>' ) ) <EOL> self . _trello . add_board ( "<STR_LIT>" , source_board = source_board ) <EOL> listed_boards = self . _trello . list_boards ( board_filter = "<STR_LIT>" ) <EOL> copied_board = next ( iter ( [ x for x in listed_boards if x . name == "<STR_LIT>" . encode ( '<STR_LIT:utf-8>' ) ] ) , None ) <EOL> self . assertIsNotNone ( copied_board ) <EOL> open_lists = copied_board . open_lists ( ) <EOL> self . assertEqual ( len ( open_lists ) , <NUM_LIT:4> ) <EOL> test_list = open_lists [ <NUM_LIT:0> ] <EOL> self . assertEqual ( len ( test_list . list_cards ( ) ) , <NUM_LIT:1> ) <EOL> test_card = next ( iter ( [ x for x in test_list . list_cards ( ) if x . name == "<STR_LIT>" . encode ( '<STR_LIT:utf-8>' ) ] ) , None ) <EOL> self . assertIsNotNone ( test_card ) <EOL> def test120_close_board ( self ) : <EOL> boards = self . _trello . list_boards ( board_filter = "<STR_LIT>" ) <EOL> open_count = len ( boards ) <EOL> test_create_board = next ( x for x in boards if x . name == "<STR_LIT>" . encode ( '<STR_LIT:utf-8>' ) ) <EOL> copied_board = next ( x for x in boards if x . name == "<STR_LIT>" . encode ( '<STR_LIT:utf-8>' ) ) <EOL> test_create_board . close ( ) <EOL> copied_board . close ( ) <EOL> still_open_boards = self . _trello . list_boards ( board_filter = "<STR_LIT>" ) <EOL> still_open_count = len ( still_open_boards ) <EOL> self . assertEqual ( still_open_count , open_count - <NUM_LIT:2> ) <EOL> def test130_get_checklists_board ( self ) : <EOL> chklists = self . _board . get_checklists ( cards = '<STR_LIT>' ) <EOL> for chklst in chklists : <EOL> chklst . delete ( ) <EOL> card = self . _add_card ( '<STR_LIT>' ) <EOL> chklist = self . _add_checklist ( card , "<STR_LIT>" , items = [ "<STR_LIT>" , "<STR_LIT>" ] , itemstates = [ True , False ] ) <EOL> new_chklists = self . _board . get_checklists ( ) <EOL> test_chk = new_chklists [ <NUM_LIT:0> ] <EOL> self . assertEqual ( test_chk . name , "<STR_LIT>" ) <EOL> self . assertEqual ( test_chk . trello_card , card . id ) <EOL> self . assertEqual ( len ( new_chklists ) , <NUM_LIT:1> ) <EOL> i1 = test_chk . items [ <NUM_LIT:0> ] <EOL> i2 = test_chk . items [ <NUM_LIT:1> ] <EOL> self . assertEqual ( len ( test_chk . items ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( i1 [ '<STR_LIT:name>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( i1 [ '<STR_LIT:state>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( i2 [ '<STR_LIT:name>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( i2 [ '<STR_LIT:state>' ] , "<STR_LIT>" ) <EOL> def suite ( ) : <EOL> return unittest . TestLoader ( ) . loadTestsFromTestCase ( TrelloBoardTestCase ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
