@@ -310,6 +310,62 @@ def test_pull_command_with_configs_and_filenames_should_be_download_only_file_in
310310
311311 mock_write_config .assert_not_called ()
312312
313+ #####
314+ # push
315+ #####
316+ def test_push_command_without_config_file_should_be_required_api_key_store_and_theme_id (self ):
317+ with self .assertRaises (TypeError ) as error :
318+ self .parser .apikey = None
319+ self .parser .store = None
320+ self .parser .theme_id = None
321+ self .command .push (self .parser )
322+ self .assertEqual (
323+ str (error .exception ), '[development] argument -a/--apikey, -s/--store, -t/--theme_id are required.' )
324+
325+ @patch ("ntk.command.Command._get_accept_files" , autospec = True )
326+ def test_push_command_with_configs_and_without_filenames_should_upload_all_files (
327+ self , mock_get_accept_files
328+ ):
329+ mock_get_accept_files .return_value = [
330+ f'{ os .getcwd ()} /layout/base.html' ,
331+ ]
332+ self .mock_gateway .return_value .create_or_update_template .return_value .ok = True
333+ self .mock_gateway .return_value .create_or_update_template .return_value .headers = {
334+ 'content-type' : 'application/json; charset=utf-8' }
335+ self .command .config .parser_config (self .parser )
336+ self .parser .filenames = None
337+ with patch ("builtins.open" , self .mock_file ):
338+ self .command .push (self .parser )
339+ expected_call = call ().create_or_update_template (
340+ theme_id = 1234 ,
341+ template_name = 'layout/base.html' ,
342+ content = '{% load i18n %}\n \n <div class="mt-2">My home page</div>' ,
343+ files = {}
344+ )
345+ self .assertIn (expected_call , self .mock_gateway .mock_calls )
346+
347+ @patch ("ntk.command.Command._get_accept_files" , autospec = True )
348+ def test_push_command_with_filenames_should_upload_only_specified_files (
349+ self , mock_get_accept_files
350+ ):
351+ mock_get_accept_files .return_value = [
352+ f'{ os .getcwd ()} /layout/base.html' ,
353+ ]
354+ self .mock_gateway .return_value .create_or_update_template .return_value .ok = True
355+ self .mock_gateway .return_value .create_or_update_template .return_value .headers = {
356+ 'content-type' : 'application/json; charset=utf-8' }
357+ self .command .config .parser_config (self .parser )
358+ self .parser .filenames = ['layout/base.html' ]
359+ with patch ("builtins.open" , self .mock_file ):
360+ self .command .push (self .parser )
361+ expected_call = call ().create_or_update_template (
362+ theme_id = 1234 ,
363+ template_name = 'layout/base.html' ,
364+ content = '{% load i18n %}\n \n <div class="mt-2">My home page</div>' ,
365+ files = {}
366+ )
367+ self .assertIn (expected_call , self .mock_gateway .mock_calls )
368+
313369 #####
314370 # watch (_handle_files_change)
315371 #####
0 commit comments