def test_get_fixture_nodes(self): """ Case: Fixture nodes get requested Expected: Only nodes starting with the given fixture name get returned """ runner = LoadFixtureRunner() runner.get_app_nodes = mock.MagicMock(return_value=[ ('app_one', '0001_my_fixture'), ('app_one', '0002_my_other_fixture'), ('app_one', '0003_my_other_fixture'), ]) result = runner.get_fixture_node(app_label='app_one', fixture_prefix='0001') self.assertListEqual(result, [('app_one', '0001_my_fixture')]) runner.get_app_nodes.assert_called_once_with(app_label='app_one')
def test_get_fixture_nodes(self): """ Case: Fixture nodes get requested Expected: Only nodes starting with the given fixture name get returned """ runner = LoadFixtureRunner() runner.get_app_nodes = mock.MagicMock(return_value=[ ("app_one", "0001_my_fixture"), ("app_one", "0002_my_other_fixture"), ("app_one", "0003_my_other_fixture"), ]) result = runner.get_fixture_node(app_label="app_one", fixture_prefix="0001") self.assertListEqual(result, [("app_one", "0001_my_fixture")]) runner.get_app_nodes.assert_called_once_with(app_label="app_one")
def test_get_app_nodes(self): """ Case: Get filtered app nodes Expected: Only app nodes which from given app get returned """ runner = LoadFixtureRunner() graph = self.graph_mock() graph.nodes = [ ("app_one", "foo"), ("app_one", "bar"), ("app_two", "foo"), ] runner._graph = graph app_nodes = runner.get_app_nodes("app_one") self.assertListEqual(app_nodes, [("app_one", "foo"), ("app_one", "bar")])
def test_get_fixture_nodes_none_returned(self): """ Case: Fixture nodes get requested but none matches Expected: An error get raised """ runner = LoadFixtureRunner() runner.get_app_nodes = mock.MagicMock(return_value=[ ("app_one", "0001_my_fixture"), ("app_one", "0002_my_other_fixture"), ("app_one", "0003_my_other_fixture"), ]) with self.assertRaises(FixtureNotFound) as e: runner.get_fixture_node(app_label="app_one", fixture_prefix="0006") self.assertEqual( "Fixture with prefix '0006' not found in app " "'app_one'", str(e.exception))
def handle(self, *args, **options): runner = LoadFixtureRunner() if len(args) == 1: fixture_name = None (app_label, ) = args elif len(args) == 2: app_label, fixture_name = args else: app_label = options.get("app_label") fixture_name = options.get("fixture_name") if app_label is None: nodes = None elif fixture_name is None: nodes = runner.get_app_nodes(app_label=app_label) else: nodes = runner.get_fixture_node(app_label=app_label, fixture_prefix=fixture_name) if options.get("verbosity") > 1: logger.setLevel(logging.DEBUG) if not options.get("list", False): fixture_count = runner.load_fixtures( nodes=nodes, progress_callback=self.progress_callback, dry_run=options.get("dry_run", False), ) else: plan = runner.get_plan(nodes=nodes) self.stdout.write("Discovery all dynamic fixtures...") for node in plan: self.stdout.write("{}.{}".format(*node)) fixture_count = len(plan) self.stdout.write("Total of {} fixtures".format(fixture_count)) if not options.get("list") and options.get("dry_run"): self.stdout.write("Dry-run: all changes are rolled back.")
def test_get_fixture_nodes_none_returned(self): """ Case: Fixture nodes get requested but none matches Expected: An error get raised """ runner = LoadFixtureRunner() runner.get_app_nodes = mock.MagicMock(return_value=[ ('app_one', '0001_my_fixture'), ('app_one', '0002_my_other_fixture'), ('app_one', '0003_my_other_fixture'), ]) with self.assertRaises(FixtureNotFound) as e: runner.get_fixture_node(app_label='app_one', fixture_prefix='0006') self.assertEqual("Fixture with prefix '0006' not found in app " "'app_one'", str(e.exception))
def test_get_fixture_nodes_multiple_returned(self): """ Case: Fixture nodes get requested but multiple matches Expected: An error get raised """ runner = LoadFixtureRunner() runner.get_app_nodes = mock.MagicMock(return_value=[ ('app_one', '0001_my_fixture'), ('app_one', '0001_my_other_fixture'), ('app_one', '0003_my_other_fixture'), ]) with self.assertRaises(MultipleFixturesFound) as e: runner.get_fixture_node(app_label='app_one', fixture_prefix='0001') self.assertEqual( "The following fixtures with prefix '0001' are found" " in app 'app_one': 0001_my_fixture, " "0001_my_other_fixture", str(e.exception))
def test_get_fixture_nodes_multiple_returned(self): """ Case: Fixture nodes get requested but multiple matches Expected: An error get raised """ runner = LoadFixtureRunner() runner.get_app_nodes = mock.MagicMock(return_value=[ ('app_one', '0001_my_fixture'), ('app_one', '0001_my_other_fixture'), ('app_one', '0003_my_other_fixture'), ]) with self.assertRaises(MultipleFixturesFound) as e: runner.get_fixture_node(app_label='app_one', fixture_prefix='0001') self.assertEqual("The following fixtures with prefix '0001' are found" " in app 'app_one': 0001_my_fixture, " "0001_my_other_fixture", str(e.exception))
def handle(self, *args, **options): runner = LoadFixtureRunner() if len(args) == 1: fixture_name = None app_label, = args elif len(args) == 2: app_label, fixture_name = args else: app_label = options.get('app_label') fixture_name = options.get('fixture_name') if app_label is None: nodes = None elif fixture_name is None: nodes = runner.get_app_nodes(app_label=app_label) else: nodes = runner.get_fixture_node(app_label=app_label, fixture_prefix=fixture_name) if not options.get('list', False): fixture_count = runner.load_fixtures( nodes=nodes, progress_callback=self.progress_callback, dry_run=options.get('dry_run', False) ) else: plan = runner.get_plan(nodes=nodes) self.stdout.write('Discovery all dynamic fixtures...') for node in plan: self.stdout.write('{}.{}'.format(*node)) fixture_count = len(plan) self.stdout.write('Total of {} fixtures'.format(fixture_count)) if not options.get('list') and options.get('dry_run'): self.stdout.write('Dry-run: all changes are rolled back.')
def handle(self, *args, **options): runner = LoadFixtureRunner() if len(args) == 1: fixture_name = None app_label, = args elif len(args) == 2: app_label, fixture_name = args else: app_label = options.get('app_label') fixture_name = options.get('fixture_name') if app_label is None: nodes = None elif fixture_name is None: nodes = runner.get_app_nodes(app_label=app_label) else: nodes = runner.get_fixture_node(app_label=app_label, fixture_prefix=fixture_name) if not options.get('list', False): fixture_count = runner.load_fixtures( nodes=nodes, progress_callback=self.progress_callback, dry_run=options.get('dry_run', False)) else: plan = runner.get_plan(nodes=nodes) self.stdout.write('Discovery all dynamic fixtures...') for node in plan: self.stdout.write('{}.{}'.format(*node)) fixture_count = len(plan) self.stdout.write('Total of {} fixtures'.format(fixture_count)) if not options.get('list') and options.get('dry_run'): self.stdout.write('Dry-run: all changes are rolled back.')
def test_get_app_nodes(self): """ Case: Get filtered app nodes Expected: Only app nodes which from given app get returned """ runner = LoadFixtureRunner() graph = self.graph_mock() graph.nodes = [ ('app_one', 'foo'), ('app_one', 'bar'), ('app_two', 'foo'), ] runner._graph = graph app_nodes = runner.get_app_nodes('app_one') self.assertListEqual( app_nodes, [ ('app_one', 'foo'), ('app_one', 'bar'), ] )
def handle(self, *args, **options): runner = LoadFixtureRunner() if len(args) == 1: fixture_name = None app_label, = args elif len(args) == 2: app_label, fixture_name = args else: app_label = options.get('app_label') fixture_name = options.get('fixture_name') if app_label is None: nodes = None elif fixture_name is None: nodes = runner.get_app_nodes(app_label=app_label) else: nodes = runner.get_fixture_node(app_label=app_label, fixture_prefix=fixture_name) fixture_count = runner.load_fixtures( nodes=nodes, progress_callback=self.progress_callback) self.stdout.write('Loaded {} fixtures'.format(fixture_count))