def setUpClass(self): self.database = DatabaseFactory() self.task = TaskHistoryFactory( object_class=self.database._meta.db_table, object_id=self.database.id, task_status=TaskHistory.STATUS_WAITING )
def setUp(self): self.host_api = HostAPI() self.host_api.request = MagicMock() self.instance = InstanceFactory.create() self.instance.databaseinfra.databases.add( DatabaseFactory.create(databaseinfra=self.instance.databaseinfra))
def setUp(self): database = DatabaseFactory() self.keys = ( 'notification.tasks.create_database', 'notification.tasks.resize_database', 'notification.tasks.database_disk_resize', 'backup.tasks.restore_snapshot', 'notification.tasks.destroy_database', 'notification.tasks.clone_database', 'dbaas_services.analyzing.tasks.analyze.analyze_databases', 'notification.tasks.upgrade_mongodb_24_to_30', 'dbaas_aclapi.tasks.unbind_address_on_database', 'dbaas_aclapi.tasks.bind_address_on_database', 'arguments.test_not_existent.there_is_no_class_for_this_task', ) self.args = { 'name': database.name, 'database': database, 'environment': database.environment, 'project': database.project, 'plan': database.databaseinfra.plan, 'cloudstackpack': CloudStackPackFactory(), 'disk_offering': database.databaseinfra.disk_offering, 'user': UserFactory(), 'origin_database': database, 'clone_name': 'clone_{}'.format(database.name), 'database_bind': DatabaseBindFactory(), } # Pattern: Name of the argument: value of argument self.pattern = "[A-Z0-9][A-Za-z0-9_\- ]*[:][\s][A-Za-z0-9_\- ]+"
def setUp(self): self.team = TeamFactory() self.threshold_database_notification = Configuration( name='threshold_database_notification', value=70, description='Threshold infra notification') self.threshold_database_notification.save() self.new_user_notify_email = Configuration( name='new_user_notify_email', value='*****@*****.**', description='New user notify e-mail') self.new_user_notify_email.save() self.database_big = DatabaseFactory( databaseinfra__engine__engine_type__name=self.engine_name, ) self.database_big.team = self.team self.database_big.save() self.infra_big = self.database_big.databaseinfra self.infra_big.plan.replication_topology.class_path = self.replication_topology_class_path self.infra_big.plan.replication_topology.save() self.infra_big.save() self.database_small = DatabaseFactory( databaseinfra__engine__engine_type__name=self.engine_name) self.database_small.team = self.team self.database_small.save() self.infra_small = self.database_small.databaseinfra self.infra_small.plan.replication_topology.class_path = self.replication_topology_class_path self.infra_small.plan.replication_topology.save() self.infra_small.save() self.instance_helper.create_instances_by_quant( qt=self.instance_quantity, infra=self.infra_big, total_size_in_bytes=10000, used_size_in_bytes=9900, port=self.port, instance_type=self.instance_type) self.instance_helper.create_instances_by_quant( qt=self.instance_quantity, infra=self.infra_small, total_size_in_bytes=10000, used_size_in_bytes=1900, port=self.port, instance_type=self.instance_type)
def setUp(self): self.host_api = HostAPI() self.host_api.request = MagicMock() self.instance = InstanceFactory.create() self.instance.databaseinfra.databases.add( DatabaseFactory.create(databaseinfra=self.instance.databaseinfra) )
def setUp(self): self.team = TeamFactory() self.threshold_database_notification = Configuration( name='threshold_database_notification', value=70, description='Threshold infra notification' ) self.threshold_database_notification.save() self.new_user_notify_email = Configuration( name='new_user_notify_email', value='*****@*****.**', description='New user notify e-mail' ) self.new_user_notify_email.save() self.database_big = DatabaseFactory( databaseinfra__engine__engine_type__name=self.engine_name, ) self.database_big.team = self.team self.database_big.save() self.infra_big = self.database_big.databaseinfra self.infra_big.plan.replication_topology.class_path = self.replication_topology_class_path self.infra_big.plan.replication_topology.save() self.infra_big.save() self.database_small = DatabaseFactory( databaseinfra__engine__engine_type__name=self.engine_name ) self.database_small.team = self.team self.database_small.save() self.infra_small = self.database_small.databaseinfra self.infra_small.plan.replication_topology.class_path = self.replication_topology_class_path self.infra_small.plan.replication_topology.save() self.infra_small.save() self.instance_helper.create_instances_by_quant( qt=self.instance_quantity, infra=self.infra_big, total_size_in_bytes=10000, used_size_in_bytes=9900, port=self.port, instance_type=self.instance_type ) self.instance_helper.create_instances_by_quant( qt=self.instance_quantity, infra=self.infra_small, total_size_in_bytes=10000, used_size_in_bytes=1900, port=self.port, instance_type=self.instance_type )
def test_object_make_dict_from_model(self, objects_mock): fake_database = DatabaseFactory.build(name='test_fake_database', ) fake_database.environment.name = '__test__ fake env' fake_database.databaseinfra.engine.version = 'v1.2.3' fake_database.databaseinfra.engine.engine_type.name = '__test__ fake engine' objects_mock.select_related().get.return_value = fake_database database_info = self.serializer.get_database(self.fake_task) self.assertEqual(database_info.get('name'), 'test_fake_database') self.assertEqual(database_info.get('environment'), '__test__ fake env') self.assertEqual(database_info.get('engine'), '__test__ fake engine v1.2.3')
def test_can_send_email_disk_auto_resize(self): database = DatabaseFactory() usage_percentage = 76.89 disk_resize_notification(database=database, new_disk=self.disk, usage_percentage=usage_percentage) self.assertEqual(len(mail.outbox), 2) self.assertEqual(mail.outbox[0].subject, SUBJECT_DISK_AUTO_RESIZE.format(database, self.disk)) self.assertEqual(mail.outbox[1].subject, SUBJECT_DISK_AUTO_RESIZE.format(database, self.disk))
def test_object_make_dict_from_model(self, objects_mock): fake_database = DatabaseFactory.build( name='test_fake_database', ) fake_database.environment.name = '__test__ fake env' fake_database.databaseinfra.engine.version = 'v1.2.3' fake_database.databaseinfra.engine.engine_type.name = '__test__ fake engine' objects_mock.select_related().get.return_value = fake_database database_info = self.serializer.get_database(self.fake_task) self.assertEqual(database_info.get('name'), 'test_fake_database') self.assertEqual(database_info.get('environment'), '__test__ fake env') self.assertEqual(database_info.get('engine'), '__test__ fake engine v1.2.3')
class TaskHistoryObjectTestCase(TestCase): @classmethod def setUpClass(self): self.database = DatabaseFactory() self.task = TaskHistoryFactory( object_class=self.database._meta.db_table, object_id=self.database.id, task_status=TaskHistory.STATUS_WAITING) @classmethod def tearDownClass(self): Database.objects.all().delete() TaskHistory.objects.all().delete() def test_return_true_when_have_task_history_registered(self): self.assertTrue(self.database.is_being_used_elsewhere()) def test_return_false_when_have_task_history_registered_in_another_database( self): other_database = DatabaseFactory() self.assertFalse(other_database.is_being_used_elsewhere())
class TaskHistoryObjectTestCase(TestCase): @classmethod def setUpClass(self): self.database = DatabaseFactory() self.task = TaskHistoryFactory( object_class=self.database._meta.db_table, object_id=self.database.id, task_status=TaskHistory.STATUS_WAITING ) @classmethod def tearDownClass(self): Database.objects.all().delete() TaskHistory.objects.all().delete() def test_return_true_when_have_task_history_registered(self): self.assertTrue(self.database.is_being_used_elsewhere()) def test_return_false_when_have_task_history_registered_in_another_database(self): other_database = DatabaseFactory() self.assertFalse(other_database.is_being_used_elsewhere())
class BaseTestCase(object): engine_name = '' port = None replication_topology_class_path = None instance_helper = InstanceHelper instance_quantity = 1 instance_type = 1 def setUp(self): self.team = TeamFactory() self.threshold_database_notification = Configuration( name='threshold_database_notification', value=70, description='Threshold infra notification') self.threshold_database_notification.save() self.new_user_notify_email = Configuration( name='new_user_notify_email', value='*****@*****.**', description='New user notify e-mail') self.new_user_notify_email.save() self.database_big = DatabaseFactory( databaseinfra__engine__engine_type__name=self.engine_name, ) self.database_big.team = self.team self.database_big.save() self.infra_big = self.database_big.databaseinfra self.infra_big.plan.replication_topology.class_path = self.replication_topology_class_path self.infra_big.plan.replication_topology.save() self.infra_big.save() self.database_small = DatabaseFactory( databaseinfra__engine__engine_type__name=self.engine_name) self.database_small.team = self.team self.database_small.save() self.infra_small = self.database_small.databaseinfra self.infra_small.plan.replication_topology.class_path = self.replication_topology_class_path self.infra_small.plan.replication_topology.save() self.infra_small.save() self.instance_helper.create_instances_by_quant( qt=self.instance_quantity, infra=self.infra_big, total_size_in_bytes=10000, used_size_in_bytes=9900, port=self.port, instance_type=self.instance_type) self.instance_helper.create_instances_by_quant( qt=self.instance_quantity, infra=self.infra_small, total_size_in_bytes=10000, used_size_in_bytes=1900, port=self.port, instance_type=self.instance_type) def test_team_can_receive_notification(self, check_master_mock): database_notification_for_team(team=self.team) self.assertEqual(len(mail.outbox), 2) def test_team_do_not_want_receive_notification(self, check_master_mock): self.database_big.subscribe_to_email_events = False self.database_big.save() database_notification_for_team(team=self.team) self.assertEqual(len(mail.outbox), 0)
def setUp(self): self.database = DatabaseFactory.create( databaseinfra__engine__engine_type__name='redis' )
def test_return_false_when_have_task_history_registered_in_another_database( self): other_database = DatabaseFactory() self.assertFalse(other_database.is_being_used_elsewhere())
def setUpClass(self): self.database = DatabaseFactory() self.task = TaskHistoryFactory( object_class=self.database._meta.db_table, object_id=self.database.id, task_status=TaskHistory.STATUS_WAITING)
class BaseTestCase(object): engine_name = '' port = None replication_topology_class_path = None instance_helper = InstanceHelper instance_quantity = 1 instance_type = 1 def setUp(self): self.team = TeamFactory() self.threshold_database_notification = Configuration( name='threshold_database_notification', value=70, description='Threshold infra notification' ) self.threshold_database_notification.save() self.new_user_notify_email = Configuration( name='new_user_notify_email', value='*****@*****.**', description='New user notify e-mail' ) self.new_user_notify_email.save() self.database_big = DatabaseFactory( databaseinfra__engine__engine_type__name=self.engine_name, ) self.database_big.team = self.team self.database_big.save() self.infra_big = self.database_big.databaseinfra self.infra_big.plan.replication_topology.class_path = self.replication_topology_class_path self.infra_big.plan.replication_topology.save() self.infra_big.save() self.database_small = DatabaseFactory( databaseinfra__engine__engine_type__name=self.engine_name ) self.database_small.team = self.team self.database_small.save() self.infra_small = self.database_small.databaseinfra self.infra_small.plan.replication_topology.class_path = self.replication_topology_class_path self.infra_small.plan.replication_topology.save() self.infra_small.save() self.instance_helper.create_instances_by_quant( qt=self.instance_quantity, infra=self.infra_big, total_size_in_bytes=10000, used_size_in_bytes=9900, port=self.port, instance_type=self.instance_type ) self.instance_helper.create_instances_by_quant( qt=self.instance_quantity, infra=self.infra_small, total_size_in_bytes=10000, used_size_in_bytes=1900, port=self.port, instance_type=self.instance_type ) def test_team_can_receive_notification(self, check_master_mock): database_notification_for_team(team=self.team) self.assertEqual(len(mail.outbox), 2) def test_team_do_not_want_receive_notification(self, check_master_mock): self.database_big.subscribe_to_email_events = False self.database_big.save() database_notification_for_team(team=self.team) self.assertEqual(len(mail.outbox), 0)
def test_return_false_when_have_task_history_registered_in_another_database(self): other_database = DatabaseFactory() self.assertFalse(other_database.is_being_used_elsewhere())