def test_main_loads_url_and_auth_from_env(self): '''Required to ensure that the main program loads the GIT2SC_AUTH and GIT2SC_API_URL variables from the environment, I know it's not the perfect test but didn't manage to do any other way''' main() self.assertEqual(self.env.call_count, 2)
def test_article_delete_subcommand(self): '''Required to ensure that the main program reacts as expected when called with the delete page arguments''' self.args.subcommand = 'article' self.args.article_command = 'delete' self.args.article_id = '1' main() self.assertEqual( self.git2sc.return_value.delete_page.assert_called_with( self.args.article_id, ), None)
def test_upload_directory_subcommand(self): '''Required to ensure that the main program reacts as expected when called with the upload directory arguments''' self.args.subcommand = 'upload' self.args.path = '/path/to/directory' self.args.exclude = ['.git'] self.args.parent_id = None main() self.assertEqual( self.git2sc.return_value.directory_full_upload.assert_called_with( self.args.path, self.args.exclude, None), None)
def test_main_loads_git2sc_object(self): '''Required to ensure that the main program load the git2sc object''' main() self.assertEqual( self.git2sc.assert_called_with( 'https://confluence.sucks.com/wiki/rest/api', 'user:password', 'TST', ), None, ) self.assertTrue(self.git2sc.called)
def test_main_loads_gives_error_if_no_url_in_env(self): '''Required to ensure that the main program will fail if the environmental variable GIT2SC_API_URL is not set''' type(self.os).environ = PropertyMock(return_value={ 'GIT2SC_AUTH': 'user:password', }, ) main() self.assertEqual( self.print.assert_called_with( 'GIT2SC_API_URL environmental variable not set'), None, )
def test_main_loads_gives_error_if_no_auth_in_env(self): '''Required to ensure that the main program will fail if the environmental variable GIT2SC_AUTH is not set''' type(self.os).environ = PropertyMock(return_value={ 'GIT2SC_API_URL': 'https://confluence.sucks.com/wiki/rest/api', }, ) main() self.assertEqual( self.print.assert_called_with( 'GIT2SC_AUTH environmental variable not set'), None, )
def test_article_create_children_article_with_html(self): self.args.subcommand = 'article' self.args.article_command = 'create' self.args.title = 'new article' self.args.parent_id = '1111' self.args.content = '<p>New article!</p>' self.args.html = True main() self.assertEqual( self.git2sc.return_value.create_page.assert_called_with( self.args.title, self.args.content, self.args.parent_id, ), None)
def test_article_update_subcommand_with_html(self): '''Required to ensure that the main program reacts as expected when called with the update page arguments''' self.args.subcommand = 'article' self.args.article_command = 'update' self.args.html = True self.args.article_id = '1' self.args.content = '<p> This is a test </p>' main() self.assertEqual( self.git2sc.return_value.update_page.assert_called_with( self.args.article_id, self.args.content, ), None)
def test_article_update_subcommand_with_file(self): '''Required to ensure that by default the update command expects a path to a file containing the article''' self.args.subcommand = 'article' self.args.article_command = 'update' self.args.html = False self.args.article_id = '1' self.args.content = '/path/to/file' main() self.assertEqual( self.git2sc.return_value.import_file.assert_called_with( self.args.content, ), None) self.assertEqual( self.git2sc.return_value.update_page.assert_called_with( self.args.article_id, self.git2sc.return_value.import_file.return_value, ), None)
def test_main_loads_parser(self): '''Required to ensure that the main program load the parser''' self.load_parser.parse_args = True main() self.assertTrue(self.load_parser.called)