fix: format all code with black
and from now on should not deviate from that...
This commit is contained in:
		
							parent
							
								
									45dabce956
								
							
						
					
					
						commit
						33ac0e008e
					
				
					 17 changed files with 730 additions and 576 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
#-*- coding: utf-8; -*-
 | 
			
		||||
# -*- coding: utf-8; -*-
 | 
			
		||||
 | 
			
		||||
import inspect
 | 
			
		||||
from unittest import TestCase
 | 
			
		||||
| 
						 | 
				
			
			@ -19,7 +19,7 @@ class TestImportCommandHandler(DataTestCase):
 | 
			
		|||
        handler = self.make_handler()
 | 
			
		||||
        self.assertIsNone(handler.import_handler)
 | 
			
		||||
 | 
			
		||||
        FromCsvToWutta = self.app.load_object('wuttasync.importing.csv:FromCsvToWutta')
 | 
			
		||||
        FromCsvToWutta = self.app.load_object("wuttasync.importing.csv:FromCsvToWutta")
 | 
			
		||||
 | 
			
		||||
        # as spec
 | 
			
		||||
        handler = self.make_handler(import_handler=FromCsvToWutta.get_spec())
 | 
			
		||||
| 
						 | 
				
			
			@ -35,26 +35,30 @@ class TestImportCommandHandler(DataTestCase):
 | 
			
		|||
        self.assertIs(handler.import_handler, myhandler)
 | 
			
		||||
 | 
			
		||||
    def test_run(self):
 | 
			
		||||
        handler = self.make_handler(import_handler='wuttasync.importing.csv:FromCsvToWutta')
 | 
			
		||||
        handler = self.make_handler(
 | 
			
		||||
            import_handler="wuttasync.importing.csv:FromCsvToWutta"
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        with patch.object(handler, 'list_models') as list_models:
 | 
			
		||||
            handler.run({'list_models': True})
 | 
			
		||||
            list_models.assert_called_once_with({'list_models': True})
 | 
			
		||||
        with patch.object(handler, "list_models") as list_models:
 | 
			
		||||
            handler.run({"list_models": True})
 | 
			
		||||
            list_models.assert_called_once_with({"list_models": True})
 | 
			
		||||
 | 
			
		||||
        with patch.object(handler, 'import_handler') as import_handler:
 | 
			
		||||
            handler.run({'models': []})
 | 
			
		||||
        with patch.object(handler, "import_handler") as import_handler:
 | 
			
		||||
            handler.run({"models": []})
 | 
			
		||||
            import_handler.process_data.assert_called_once_with()
 | 
			
		||||
 | 
			
		||||
    def test_list_models(self):
 | 
			
		||||
        handler = self.make_handler(import_handler='wuttasync.importing.csv:FromCsvToWutta')
 | 
			
		||||
        handler = self.make_handler(
 | 
			
		||||
            import_handler="wuttasync.importing.csv:FromCsvToWutta"
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        with patch.object(mod, 'sys') as sys:
 | 
			
		||||
        with patch.object(mod, "sys") as sys:
 | 
			
		||||
            handler.list_models({})
 | 
			
		||||
            # just test a few random things we expect to see
 | 
			
		||||
            self.assertTrue(sys.stdout.write.has_call('ALL MODELS:\n'))
 | 
			
		||||
            self.assertTrue(sys.stdout.write.has_call('Person'))
 | 
			
		||||
            self.assertTrue(sys.stdout.write.has_call('User'))
 | 
			
		||||
            self.assertTrue(sys.stdout.write.has_call('Upgrade'))
 | 
			
		||||
            self.assertTrue(sys.stdout.write.has_call("ALL MODELS:\n"))
 | 
			
		||||
            self.assertTrue(sys.stdout.write.has_call("Person"))
 | 
			
		||||
            self.assertTrue(sys.stdout.write.has_call("User"))
 | 
			
		||||
            self.assertTrue(sys.stdout.write.has_call("Upgrade"))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestImporterCommand(TestCase):
 | 
			
		||||
| 
						 | 
				
			
			@ -64,12 +68,12 @@ class TestImporterCommand(TestCase):
 | 
			
		|||
            pass
 | 
			
		||||
 | 
			
		||||
        sig1 = inspect.signature(myfunc)
 | 
			
		||||
        self.assertIn('kwargs', sig1.parameters)
 | 
			
		||||
        self.assertNotIn('dry_run', sig1.parameters)
 | 
			
		||||
        self.assertIn("kwargs", sig1.parameters)
 | 
			
		||||
        self.assertNotIn("dry_run", sig1.parameters)
 | 
			
		||||
        wrapt = mod.import_command(myfunc)
 | 
			
		||||
        sig2 = inspect.signature(wrapt)
 | 
			
		||||
        self.assertNotIn('kwargs', sig2.parameters)
 | 
			
		||||
        self.assertIn('dry_run', sig2.parameters)
 | 
			
		||||
        self.assertNotIn("kwargs", sig2.parameters)
 | 
			
		||||
        self.assertIn("dry_run", sig2.parameters)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestFileImporterCommand(TestCase):
 | 
			
		||||
| 
						 | 
				
			
			@ -79,11 +83,11 @@ class TestFileImporterCommand(TestCase):
 | 
			
		|||
            pass
 | 
			
		||||
 | 
			
		||||
        sig1 = inspect.signature(myfunc)
 | 
			
		||||
        self.assertIn('kwargs', sig1.parameters)
 | 
			
		||||
        self.assertNotIn('dry_run', sig1.parameters)
 | 
			
		||||
        self.assertNotIn('input_file_path', sig1.parameters)
 | 
			
		||||
        self.assertIn("kwargs", sig1.parameters)
 | 
			
		||||
        self.assertNotIn("dry_run", sig1.parameters)
 | 
			
		||||
        self.assertNotIn("input_file_path", sig1.parameters)
 | 
			
		||||
        wrapt = mod.file_import_command(myfunc)
 | 
			
		||||
        sig2 = inspect.signature(wrapt)
 | 
			
		||||
        self.assertNotIn('kwargs', sig2.parameters)
 | 
			
		||||
        self.assertIn('dry_run', sig2.parameters)
 | 
			
		||||
        self.assertIn('input_file_path', sig2.parameters)
 | 
			
		||||
        self.assertNotIn("kwargs", sig2.parameters)
 | 
			
		||||
        self.assertIn("dry_run", sig2.parameters)
 | 
			
		||||
        self.assertIn("input_file_path", sig2.parameters)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
#-*- coding: utf-8; -*-
 | 
			
		||||
# -*- coding: utf-8; -*-
 | 
			
		||||
 | 
			
		||||
from unittest import TestCase
 | 
			
		||||
from unittest.mock import MagicMock, patch
 | 
			
		||||
| 
						 | 
				
			
			@ -6,14 +6,17 @@ from unittest.mock import MagicMock, patch
 | 
			
		|||
from wuttasync.cli import import_csv as mod, ImportCommandHandler
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestImportCsv(TestCase):
 | 
			
		||||
 | 
			
		||||
    def test_basic(self):
 | 
			
		||||
        params = {'models': [],
 | 
			
		||||
                  'create': True, 'update': True, 'delete': False,
 | 
			
		||||
                  'dry_run': True}
 | 
			
		||||
        params = {
 | 
			
		||||
            "models": [],
 | 
			
		||||
            "create": True,
 | 
			
		||||
            "update": True,
 | 
			
		||||
            "delete": False,
 | 
			
		||||
            "dry_run": True,
 | 
			
		||||
        }
 | 
			
		||||
        ctx = MagicMock(params=params)
 | 
			
		||||
        with patch.object(ImportCommandHandler, 'run') as run:
 | 
			
		||||
        with patch.object(ImportCommandHandler, "run") as run:
 | 
			
		||||
            mod.import_csv(ctx)
 | 
			
		||||
            run.assert_called_once_with(params)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue