@ddt.data(
        {"context": {"tenant": {"networks":
                                [mock.MagicMock(), mock.MagicMock()]}}},
        {"network_create_args": {"fakearg": "fake"},
         "context": {"tenant": {"networks":
                                [mock.MagicMock(), mock.MagicMock()]}}})
    @ddt.unpack
    @mock.patch("random.choice", side_effect=lambda l: l[0])
    def test_get_or_create_network(self, mock_random_choice,
                                   network_create_args=None, context=None):
        self.scenario.context = context
        self.scenario._create_network = mock.Mock(
            return_value={"network": mock.Mock()})

        network = self.scenario._get_or_create_network(network_create_args)

        # ensure that the return value is the proper type either way
        self.assertIn("network", network)

        if "networks" in context["tenant"]:
            self.assertEqual(network,
                             {"network": context["tenant"]["networks"][0]})
            self.assertFalse(self.scenario._create_network.called)
        else:
            self.assertEqual(network,
                             self.scenario._create_network.return_value)
            self.scenario._create_network.assert_called_once_with(
                network_create_args or {})
dataset/ETHPy150Open openstack/rally/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py/NeutronScenarioTestCase.test_get_or_create_network/original