<s> import unittest <EOL> from nagare import database <EOL> from elixir import metadata as __metadata__ <EOL> from kansha import helpers <EOL> from kansha . board import boardsmanager <EOL> from kansha . board . models import DataBoard <EOL> from kansha . board import comp as board_module <EOL> database . set_metadata ( __metadata__ , '<STR_LIT>' , False , { } ) <EOL> class BoardTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> helpers . setup_db ( __metadata__ ) <EOL> self . boards_manager = helpers . get_boards_manager ( ) <EOL> def tearDown ( self ) : <EOL> helpers . teardown_db ( __metadata__ ) <EOL> def test_add_board ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> self . assertEqual ( DataBoard . query . count ( ) , <NUM_LIT:0> ) <EOL> helpers . create_board ( ) <EOL> self . assertEqual ( DataBoard . query . filter_by ( is_template = False ) . count ( ) , <NUM_LIT:1> ) <EOL> def test_add_column_ok ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> self . assertIsNotNone ( board . archive_column ) <EOL> self . assertEqual ( board . count_columns ( ) , <NUM_LIT:4> ) <EOL> board . create_column ( <NUM_LIT:0> , helpers . word ( ) ) <EOL> self . assertEqual ( board . count_columns ( ) , <NUM_LIT:5> ) <EOL> def test_add_column_ko ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> self . assertEqual ( board . count_columns ( ) , <NUM_LIT:4> ) <EOL> self . assertFalse ( board . create_column ( <NUM_LIT:0> , '<STR_LIT>' ) ) <EOL> def test_delete_column ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> user = helpers . create_user ( ) <EOL> helpers . set_context ( user ) <EOL> board = helpers . create_board ( ) <EOL> self . assertIsNotNone ( board . archive_column ) <EOL> self . assertEqual ( board . count_columns ( ) , <NUM_LIT:4> ) <EOL> column = board . columns [ <NUM_LIT:0> ] <EOL> board . delete_column ( column ) <EOL> self . assertEqual ( board . count_columns ( ) , <NUM_LIT:3> ) <EOL> def test_set_visibility_1 ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> board . data . visibility = <NUM_LIT:0> <EOL> board . data . comments_allowed = <NUM_LIT:0> <EOL> board . data . votes_allowed = <NUM_LIT:1> <EOL> board . set_visibility ( board_module . BOARD_PUBLIC ) <EOL> self . assertEqual ( board . data . visibility , <NUM_LIT:1> ) <EOL> self . assertEqual ( board . data . comments_allowed , <NUM_LIT:0> ) <EOL> self . assertEqual ( board . data . votes_allowed , <NUM_LIT:1> ) <EOL> def test_set_visibility_2 ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> board . data . visibility = <NUM_LIT:1> <EOL> board . data . comments_allowed = <NUM_LIT:2> <EOL> board . data . votes_allowed = <NUM_LIT:2> <EOL> board . set_visibility ( board_module . BOARD_PRIVATE ) <EOL> self . assertEqual ( board . data . visibility , <NUM_LIT:0> ) <EOL> self . assertEqual ( board . data . comments_allowed , <NUM_LIT:1> ) <EOL> self . assertEqual ( board . data . votes_allowed , <NUM_LIT:1> ) <EOL> def test_set_visibility_3 ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> board . data . visibility = <NUM_LIT:1> <EOL> board . data . comments_allowed = <NUM_LIT:1> <EOL> board . data . votes_allowed = <NUM_LIT:0> <EOL> board . set_visibility ( board_module . BOARD_PRIVATE ) <EOL> self . assertEqual ( board . data . visibility , <NUM_LIT:0> ) <EOL> self . assertEqual ( board . data . comments_allowed , <NUM_LIT:1> ) <EOL> self . assertEqual ( board . data . votes_allowed , <NUM_LIT:0> ) <EOL> def test_save_as_template ( self ) : <EOL> title = helpers . word ( ) <EOL> description = helpers . word ( ) <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> user = helpers . create_user ( ) <EOL> helpers . set_context ( user ) <EOL> boards_manager = helpers . get_boards_manager ( ) <EOL> template = boards_manager . create_template_from_board ( board , title , description , False ) <EOL> self . assertEqual ( template . data . title , title ) <EOL> self . assertEqual ( template . data . description , description ) <EOL> self . assertTrue ( template . data . is_template ) <EOL> self . assertEqual ( template . data . visibility , board_module . BOARD_PRIVATE ) <EOL> template = boards_manager . create_template_from_board ( board , title , description , True ) <EOL> self . assertEqual ( template . data . visibility , board_module . BOARD_PUBLIC ) <EOL> def test_switch_view ( self ) : <EOL> board = helpers . create_board ( ) <EOL> self . assertEqual ( board . model , '<STR_LIT>' ) <EOL> board . switch_view ( ) <EOL> self . assertEqual ( board . model , '<STR_LIT>' ) <EOL> board . switch_view ( ) <EOL> self . assertEqual ( board . model , '<STR_LIT>' ) <EOL> def test_has_member_1 ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> user = helpers . create_user ( ) <EOL> helpers . set_context ( user ) <EOL> data = board . data <EOL> members = data . members <EOL> members . append ( user . data ) <EOL> self . assertTrue ( board . has_member ( user ) ) <EOL> def test_has_member_2 ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> user = helpers . create_user ( '<STR_LIT>' ) <EOL> helpers . set_context ( user ) <EOL> user_2 = helpers . create_user ( suffixe = '<STR_LIT:2>' ) <EOL> data = board . data <EOL> data . managers . append ( user_2 . data ) <EOL> self . assertFalse ( board . has_member ( user ) ) <EOL> def test_has_manager_1 ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> user = helpers . create_user ( '<STR_LIT>' ) <EOL> helpers . set_context ( user ) <EOL> self . assertFalse ( board . has_manager ( user ) ) <EOL> user . data . managed_boards . append ( board . data ) <EOL> user . data . boards . append ( board . data ) <EOL> self . assertTrue ( board . has_manager ( user ) ) <EOL> def test_has_manager_2 ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> user = helpers . create_user ( '<STR_LIT>' ) <EOL> helpers . set_context ( user ) <EOL> user_2 = helpers . create_user ( suffixe = '<STR_LIT:2>' ) <EOL> self . assertFalse ( board . has_manager ( user ) ) <EOL> data = board . data <EOL> data . managers . append ( user_2 . data ) <EOL> data . members . append ( user_2 . data ) <EOL> database . session . flush ( ) <EOL> self . assertFalse ( board . has_manager ( user ) ) <EOL> def test_add_member_1 ( self ) : <EOL> """<STR_LIT>""" <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> user = helpers . create_user ( '<STR_LIT>' ) <EOL> helpers . set_context ( user ) <EOL> self . assertFalse ( board . has_member ( user ) ) <EOL> board . add_member ( user ) <EOL> self . assertTrue ( board . has_member ( user ) ) <EOL> def test_change_role ( self ) : <EOL> '''<STR_LIT>''' <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> user = helpers . create_user ( '<STR_LIT:test>' ) <EOL> board . add_member ( user ) <EOL> board . update_members ( ) <EOL> def find_board_member ( ) : <EOL> for member in board . all_members : <EOL> if member ( ) . get_user_data ( ) . username == user . username : <EOL> return member ( ) <EOL> member = find_board_member ( ) <EOL> self . assertEqual ( len ( board . members ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( board . managers ) , <NUM_LIT:1> ) <EOL> member . dispatch ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> member = find_board_member ( ) <EOL> board . update_members ( ) <EOL> self . assertEqual ( len ( board . members ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( board . managers ) , <NUM_LIT:2> ) <EOL> member . dispatch ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> board . update_members ( ) <EOL> self . assertEqual ( len ( board . members ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( board . managers ) , <NUM_LIT:1> ) <EOL> def test_get_boards ( self ) : <EOL> '''<STR_LIT>''' <EOL> helpers . set_dummy_context ( ) <EOL> board = helpers . create_board ( ) <EOL> user = helpers . create_user ( ) <EOL> user2 = helpers . create_user ( '<STR_LIT>' ) <EOL> board . add_member ( user2 , '<STR_LIT>' ) <EOL> boards_manager = helpers . get_boards_manager ( ) <EOL> self . assertTrue ( board . has_manager ( user ) ) <EOL> self . assertFalse ( board . has_manager ( user2 ) ) <EOL> helpers . set_context ( user ) <EOL> boards_manager . load_user_boards ( ) <EOL> self . assertNotIn ( board . id , boards_manager . last_modified_boards ) <EOL> self . assertNotIn ( board . id , boards_manager . guest_boards ) <EOL> self . assertIn ( board . id , boards_manager . my_boards ) <EOL> self . assertNotIn ( board . id , boards_manager . archived_boards ) <EOL> helpers . set_context ( user2 ) <EOL> boards_manager . load_user_boards ( ) <EOL> self . assertNotIn ( board . id , boards_manager . last_modified_boards ) <EOL> self . assertIn ( board . id , boards_manager . guest_boards ) <EOL> self . assertNotIn ( board . id , boards_manager . my_boards ) <EOL> self . assertNotIn ( board . id , boards_manager . archived_boards ) <EOL> column = board . create_column ( <NUM_LIT:1> , u'<STR_LIT:test>' ) <EOL> column . create_card ( u'<STR_LIT:test>' ) <EOL> boards_manager . load_user_boards ( ) <EOL> self . assertIn ( board . id , boards_manager . last_modified_boards ) <EOL> board . archive ( ) <EOL> boards_manager . load_user_boards ( ) <EOL> self . assertIn ( board . id , boards_manager . archived_boards ) <EOL> def test_get_by ( self ) : <EOL> '''<STR_LIT>''' <EOL> helpers . set_dummy_context ( ) <EOL> orig_board = helpers . create_board ( ) <EOL> board = self . boards_manager . get_by_id ( orig_board . id ) <EOL> self . assertEqual ( orig_board . data . id , board . data . id ) <EOL> self . assertEqual ( orig_board . data . title , board . data . title ) <EOL> board = self . boards_manager . get_by_uri ( orig_board . data . uri ) <EOL> self . assertEqual ( orig_board . data . id , board . data . id ) <EOL> self . assertEqual ( orig_board . data . title , board . data . title ) </s>
