示例#1
0
 def test_enabled(self, which):
     self.assertTrue(
         can_i_use(
             ClientUser.user_from_object('test'),
             functionality=Functionality()
         )
     )
示例#2
0
 def test_none(self, which):
     self.assertFalse(
         can_i_use(
             ClientUser.user_from_object('test'),
             functionality=Functionality()
         )
     )
示例#3
0
    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 :)'))
示例#4
0
 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()
示例#5
0
 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()
示例#6
0
    def get(self, request, client_user_string, functionality_group_id):
        """
        Is the specified user allowed to use the functionality?

        Returns `{ "enabled": true }` if the specified ClientUser is allowed to use the
        functionality group, ``{ "enabled": false }`` if the user is disallowed, or a 404 error if
        functionality group does not exist.

        Include a string that uniquely identifies the user as the client user string.

        See also the `which` endpoint to see if a user has a specific functionality group within a
        functionality
        """
        functionality_group = get_object_or_404(Functionality,
                                                id=functionality_group_id)
        client_user = ClientUser.user_from_object(client_user_string)
        return Response(
            {'enabled': can_i_use(client_user, functionality_group)})
示例#7
0
    def get(self, request, client_user_string, functionality_group_id):
        """
        Which Flavor of the given Functionality is enabled for the user, if any?

        Returns `{ "which": "<app.group.functionality>" }` that corresponds to the ClientUser's
        enabled functionality, or `{ "which": none }` if the user does not have any Flavor in
        the given FuncationlityGroup.

        If the Functionality does not exist, this endpoint returns a 404 error.

        """
        functionality_group = get_object_or_404(Functionality,
                                                id=functionality_group_id)
        client_user = ClientUser.user_from_object(client_user_string)
        availability = which(client_user, functionality_group)
        return Response({
            'functionality':
            availability.flavor.__str__() if availability else None,
        })