class CheckExistenceOfRelease(TestCase): def setUp(self): self.company = Company(name='Testcompany') self.company.save() self.app = App(name='test-app', slug='test-app', company=self.company) self.app.save() self.functionality = Functionality( app=self.app, name='test-func', slug='test-func', ) self.functionality.save() def test_with_release_present(self): self.release = Release(functionality=self.functionality) self.release.save() context = WhichContext() context.functionality = self.functionality assert_existence_of_release(context) def test_with_release_not_present(self): context = WhichContext() context.functionality = Functionality() with self.assertRaises(NoAvailability): assert_existence_of_release(context)
def setUp(self): self.company = Company(name='Testcompany') self.company.save() self.app = App(name='test-app', slug='test-app', company=self.company) self.app.save() self.functionality = Functionality( app=self.app, name='test-func', slug='test-func', ) self.functionality.save()
def handle(self, *args, **options): company = Company(name='Masa', slug='masa') company.save() self.stdout.write( self.style.SUCCESS('### Created Company {} ###'.format( company.name))) try: first_user = User.objects.all()[0] ablator_user = AblatorUser(user=first_user, company=company) ablator_user.save() self.stdout.write( self.style.SUCCESS( '### Created User {} ###'.format(ablator_user))) except IndexError: self.stdout.write('No users yet, skipping user creation') for app_name in app_names: app = App(name=app_name, slug=slugify(app_name), company=company) app.save() self.stdout.write( self.style.SUCCESS('### Created App {} ###'.format(app.name))) for f_name in functionality_descriptions.keys(): functionality = Functionality(app=app, name=f_name, slug=slugify(f_name)) functionality.save() self.stdout.write( self.style.SUCCESS('Created Functionality {}'.format( functionality.name))) release = Release(functionality=functionality, max_enabled_users=6) release.save() self.stdout.write( self.style.SUCCESS(' + Release {}'.format(release.id))) for flavor_name in functionality_descriptions[f_name]: flavor = Flavor(name=flavor_name, slug=slugify(flavor_name)) flavor.functionality = functionality flavor.save() self.stdout.write( self.style.SUCCESS(' + Flavor {}'.format(flavor.name))) num_availabilities = random.randrange(13, 15) for _ in range(num_availabilities): which(client_user=ClientUser.user_from_object( random_user_name()), functionality=functionality) self.stdout.write( self.style.SUCCESS( ' + {} availabilities'.format(num_availabilities))) self.stdout.write(self.style.SUCCESS('Done :)'))
def setUp(self): self.company = Company(name='Testcompany') self.company.save() self.user = ClientUser.user_from_object('testuser') self.user.save() app = App(name='Test App', slug='test-app', company=self.company) app.save() self.functionality = Functionality(app=app, name='Test Func', slug='test-func') self.functionality.save() flavor = Flavor(name='Flav', slug='flav', functionality=self.functionality) flavor.save() self.availability = Availability(flavor=flavor, user=self.user) self.availability.save()
def test_with_flavors_present(self): company = Company(name='Testcompany') company.save() app = App(name='Test App', slug='test-app', company=company) app.save() self.functionality = Functionality(app=app, name='Test Func', slug='test-func', rollout_strategy=Functionality.DEFINED_BY_RELEASES) self.functionality.save() flavor = Flavor(name='Flav', slug='flav', functionality=self.functionality) flavor.save() context = WhichContext() context.functionality = self.functionality self.assertIsNone(assert_existence_of_flavors(context))
def setUp(self): self.company = Company(name='Testcompany') self.company.save() self.user = ClientUser.user_from_object('testuser') self.user.save() app = App(name='Test App', slug='test-app', company=self.company) app.save() self.functionality = Functionality(app=app, name='Test Func', slug='test-func', rollout_strategy=Functionality.DEFINED_BY_RELEASES) self.functionality.save() flavor = Flavor(name='Flav', slug='flav', functionality=self.functionality) flavor.save() self.availability = Availability(flavor=flavor, user=self.user) self.availability.save() self.release = Release(functionality=self.functionality, max_enabled_users=10) self.release.save()
class EnableExistingAvailability(TestCase): def setUp(self): self.company = Company(name='Testcompany') self.company.save() self.user = ClientUser.user_from_object('testuser') self.user.save() app = App(name='Test App', slug='test-app', company=self.company) app.save() self.functionality = Functionality(app=app, name='Test Func', slug='test-func', rollout_strategy=Functionality.DEFINED_BY_RELEASES) self.functionality.save() flavor = Flavor(name='Flav', slug='flav', functionality=self.functionality) flavor.save() self.availability = Availability(flavor=flavor, user=self.user) self.availability.save() self.release = Release(functionality=self.functionality, max_enabled_users=10) self.release.save() def test_already_enabled(self): context = WhichContext() context.availability = Availability(is_enabled=True) context.functionality = Functionality() context.functionality.availability = context.availability availability = enable_availability_by_user_count(context) self.assertEqual(availability, context.availability) def test_wrong_roll_out_strategy(self): context = WhichContext() context.availability = Availability(is_enabled=False) context.functionality = Functionality(rollout_strategy=Functionality.RECALL_FUNCTIONALITY) availability = enable_availability_by_user_count(context) self.assertIsNone(availability) def test_enable_with_users_to_spare(self): context = WhichContext() context.availability = self.availability context.functionality = self.functionality context.enabled_count = 5 availability = enable_availability_by_user_count(context) self.assertEqual(availability, self.availability)
class GetAvailability(TestCase): def setUp(self): self.company = Company(name='Testcompany') self.company.save() self.user = ClientUser.user_from_object('testuser') self.user.save() app = App(name='Test App', slug='test-app', company=self.company) app.save() self.functionality = Functionality(app=app, name='Test Func', slug='test-func') self.functionality.save() flavor = Flavor(name='Flav', slug='flav', functionality=self.functionality) flavor.save() self.availability = Availability(flavor=flavor, user=self.user) self.availability.save() def test_get_availability(self): context = WhichContext() context.client_user = self.user context.functionality = self.functionality get_availability(context) self.assertIsNotNone(context.availability) self.assertEqual(context.availability, self.availability)