<s> from __future__ import absolute_import , print_function , unicode_literals <EOL> import unittest <EOL> from datetime import datetime <EOL> from unittest import TestCase <EOL> from mock import patch , Mock <EOL> from click . testing import CliRunner <EOL> from statuspage import cli , update , create , iter_systems , get_severity , SYSTEM_LABEL_COLOR <EOL> from github import UnknownObjectException <EOL> class CLITestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . patcher = patch ( '<STR_LIT>' ) <EOL> self . gh = self . patcher . start ( ) <EOL> self . label = Mock ( ) <EOL> self . label . color = "<STR_LIT>" <EOL> self . label . name = "<STR_LIT>" <EOL> self . label1 = Mock ( ) <EOL> self . label1 . color = "<STR_LIT>" <EOL> self . label1 . name = "<STR_LIT>" <EOL> self . gh ( ) . get_user ( ) . get_repo ( ) . get_labels . return_value = [ self . label , self . label1 ] <EOL> self . issue = Mock ( ) <EOL> self . issue . created_at = datetime . now ( ) <EOL> self . issue . state = "<STR_LIT>" <EOL> self . issue_label = Mock ( ) <EOL> self . issue_label . color = "<STR_LIT>" <EOL> self . issue_label . name = "<STR_LIT>" <EOL> self . issue . get_labels . return_value = [ self . issue_label , self . label ] <EOL> self . issue . user . login = "<STR_LIT>" <EOL> self . comment = Mock ( ) <EOL> self . comment . user . login = "<STR_LIT>" <EOL> self . issue . get_comments . return_value = [ self . comment , ] <EOL> self . issue1 = Mock ( ) <EOL> self . issue1 . created_at = datetime . now ( ) <EOL> self . issue1 . state = "<STR_LIT>" <EOL> self . issue1 . user . login = "<STR_LIT>" <EOL> self . issue1 . get_labels . return_value = [ self . issue_label , self . label1 ] <EOL> self . issue1 . get_comments . return_value = [ self . comment , ] <EOL> self . gh ( ) . get_user ( ) . get_repo ( ) . get_issues . return_value = [ self . issue , self . issue1 ] <EOL> self . template = Mock ( ) <EOL> self . template . decoded_content = b"<STR_LIT>" <EOL> self . gh ( ) . get_user ( ) . get_repo ( ) . get_file_contents . return_value = self . template <EOL> self . gh ( ) . get_organization ( ) . get_repo ( ) . get_file_contents . return_value = self . template <EOL> self . collaborator = Mock ( ) <EOL> self . collaborator . login = "<STR_LIT>" <EOL> self . gh ( ) . get_user ( ) . get_repo ( ) . get_collaborators . return_value = [ self . collaborator , ] <EOL> self . gh ( ) . get_organization ( ) . get_repo ( ) . get_collaborators . return_value = [ self . collaborator , ] <EOL> def tearDown ( self ) : <EOL> self . patcher . stop ( ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_create ( self , run_update ) : <EOL> label = Mock ( ) <EOL> self . gh ( ) . get_user ( ) . create_repo ( ) . get_labels . return_value = [ label , ] <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> create , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . gh . assert_called_with ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_create_org ( self , run_update ) : <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( <EOL> create , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . gh . assert_called_with ( "<STR_LIT>" ) <EOL> self . gh ( ) . get_organization . assert_called_with ( "<STR_LIT>" ) <EOL> def test_update ( self ) : <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( update , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . gh . assert_called_with ( "<STR_LIT>" ) <EOL> self . gh ( ) . get_user ( ) . get_repo . assert_called_with ( name = "<STR_LIT>" ) <EOL> self . gh ( ) . get_user ( ) . get_repo ( ) . get_labels . assert_called_once_with ( ) <EOL> def test_update_org ( self ) : <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( update , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . gh . assert_called_with ( "<STR_LIT>" ) <EOL> self . gh ( ) . get_organization ( ) . get_repo . assert_called_with ( name = "<STR_LIT>" ) <EOL> self . gh ( ) . get_organization ( ) . get_repo ( ) . get_labels . assert_called_once_with ( ) <EOL> def test_update_index_does_not_exist ( self ) : <EOL> self . gh ( ) . get_user ( ) . get_repo ( ) . update_file . side_effect = UnknownObjectException ( status = <NUM_LIT> , data = "<STR_LIT:foo>" ) <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( update , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . gh . assert_called_with ( "<STR_LIT>" ) <EOL> self . gh ( ) . get_user ( ) . get_repo . assert_called_with ( name = "<STR_LIT>" ) <EOL> self . gh ( ) . get_user ( ) . get_repo ( ) . get_labels . assert_called_once_with ( ) <EOL> self . gh ( ) . get_user ( ) . get_repo ( ) . create_file . assert_called_once_with ( <EOL> branch = '<STR_LIT>' , <EOL> content = '<STR_LIT>' , <EOL> message = '<STR_LIT>' , <EOL> path = '<STR_LIT>' <EOL> ) <EOL> def test_update_non_labeled_issue_not_displayed ( self ) : <EOL> self . issue . get_labels . return_value = [ ] <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( update , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . issue . get_comments . assert_not_called ( ) <EOL> self . issue1 . get_comments . assert_called_once_with ( ) <EOL> def test_update_non_colaborator_issue_not_displayed ( self ) : <EOL> self . issue . user . login = "<STR_LIT>" <EOL> runner = CliRunner ( ) <EOL> result = runner . invoke ( update , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( result . exit_code , <NUM_LIT:0> ) <EOL> self . issue . get_comments . assert_not_called ( ) <EOL> self . issue1 . get_comments . assert_called_once_with ( ) <EOL> class UtilTestCase ( TestCase ) : <EOL> def test_iter_systems ( self ) : <EOL> label1 = Mock ( ) <EOL> label2 = Mock ( ) <EOL> label1 . name = "<STR_LIT>" <EOL> label1 . color = SYSTEM_LABEL_COLOR <EOL> self . assertEqual ( <EOL> list ( iter_systems ( [ label1 , label2 ] ) ) , <EOL> [ "<STR_LIT>" , ] <EOL> ) <EOL> self . assertEqual ( <EOL> list ( iter_systems ( [ label2 ] ) ) , <EOL> [ ] <EOL> ) <EOL> def test_severity ( self ) : <EOL> label1 = Mock ( ) <EOL> label2 = Mock ( ) <EOL> label1 . color = "<STR_LIT>" <EOL> self . assertEqual ( <EOL> get_severity ( [ label1 , label2 ] ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> label1 . color = "<STR_LIT>" <EOL> self . assertEqual ( <EOL> get_severity ( [ label1 , label2 ] ) , <EOL> None <EOL> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
