def test_best_for_with_only_two_datainfra_per_plan_and_environment_returns_rounding_robin_them( self): plan = factory.PlanFactory() environment = plan.environments.all()[0] datainfra1 = factory.DatabaseInfraFactory(plan=plan, environment=environment, capacity=10) factory.InstanceFactory(address="127.0.0.1", port=27017, databaseinfra=datainfra1) datainfra2 = factory.DatabaseInfraFactory(plan=plan, environment=environment, capacity=10) factory.InstanceFactory(address="127.0.0.2", port=27017, databaseinfra=datainfra2) for i in range(10): should_choose = (datainfra1, datainfra2)[i % 2] choosed = DatabaseInfra.best_for(plan=plan, environment=environment, name="test") self.assertEqual(should_choose, choosed) database = factory_logical.DatabaseFactory(databaseinfra=choosed) self.assertEqual(choosed, database.databaseinfra)
def setUp(self): self.instance = physical_factory.InstanceFactory() self.databaseinfra = self.instance.databaseinfra self.engine = FakeDriver(databaseinfra=self.databaseinfra) self.environment = physical_factory.EnvironmentFactory() self.plan_upgrade = physical_factory.PlanFactory()