Esempio n. 1
0
 def test_get_products(self):
     plans = set([
         billing_defs.GoldPlan,
         billing_defs.SilverPlan,
         billing_defs.BronzePlan,
         billing_defs.FreePlan,
     ])
     self.assertSetEqual(set(loading.get_products()), plans)
Esempio n. 2
0
 def test_get_products(self):
     plans = set([
         billing_defs.GoldPlan,
         billing_defs.SilverPlan,
         billing_defs.BronzePlan,
         billing_defs.FreePlan,
     ])
     self.assertSetEqual(set(loading.get_products()), plans)
Esempio n. 3
0
 def test_populate_product_cache_billing_defs(self):
     BILLING_PRODUCTS = "example_saas_project.core.billing"
     loading.product_cache = loading.populate_product_cache(products=BILLING_PRODUCTS)
     plans = [
         billing_defs.SecretFreePlan,
         billing_defs.FreePlan,
         billing_defs.SecretPlan,
         billing_defs.BronzePlan,
         billing_defs.SilverPlan,
         billing_defs.GoldPlan,
     ]
     self.assertListEqual(plans, loading.get_products(hidden=True))
Esempio n. 4
0
 def test_populate_product_cache_billing_defs(self):
     BILLING_PRODUCTS = 'example_saas_project.core.billing'
     loading.product_cache = loading.populate_product_cache(
         products=BILLING_PRODUCTS, )
     plans = [
         billing_defs.SecretFreePlan,
         billing_defs.FreePlan,
         billing_defs.SecretPlan,
         billing_defs.BronzePlan,
         billing_defs.SilverPlan,
         billing_defs.GoldPlan,
     ]
     self.assertListEqual(plans, loading.get_products(hidden=True))
Esempio n. 5
0
 def test_populate_product_cache_module_list(self):
     BILLING_PRODUCTS = (
         "example_saas_project.core.products",
         ["FreePlan", "BronzePlan", "SilverPlan", "GoldPlan", "CustomPlan", "SecretPlan", "EnterprisePlan"],
     )
     BILLING_DEFINITIONS = ()
     loading.product_cache = loading.populate_product_cache(products=BILLING_PRODUCTS)
     plans = [
         billing_defs.FreePlan,
         billing_defs.BronzePlan,
         billing_defs.SilverPlan,
         billing_defs.GoldPlan,
         product_defs.CustomPlan,
         product_defs.SecretPlan,
         product_defs.EnterprisePlan,
     ]
     self.assertListEqual(plans, loading.get_products(hidden=True))
 def handle(self, *args, **options):
     if len(args) == 0:
         # show list of plans
         def get_plan_str(p):
             hidden = p.manual_intervention is ManualPreApproval
             return '%s%s' % (p.name, ' (hidden)' if hidden else '')
         plan_strs = [get_plan_str(p) for p in get_products(hidden=True)]
         self.stdout.write(
             '\nAvailable plans:\n\n%s' %
             '\n'.join(plan_strs)
         )
         self.stdout.write('\n\n\nFor full help, use --help\n\n')
         return
     elif len(args) != 2:
         raise CommandError(
             'Exactly two arguments are needed: a user and a product')
     userarg, product_name = args
     try:
         user_by_name = User.objects.get(username=userarg)
     except User.DoesNotExist:
         user_by_name = None
     try:
         userid = int(userarg)
     except ValueError:
         userid = None
     try:
         user_by_id = User.objects.get(id=userid)
     except User.DoesNotExist:
         user_by_id = None
     if user_by_name is None and user_by_id is None:
         raise CommandError('No such user found')
     elif user_by_name is not None and user_by_id is not None:
         if user_by_name == user_by_id:
             user = user_by_id
         else:
             raise CommandError('Two users match: one by id and one by username')
     else:
         user = user_by_name or user_by_id
     user.billing_account.subscribe_to_product(product_name)
     self.stdout.write(
         '\nSuccessfully subscribed User(id=%s, username=%s, email=%s) to %s\n\n' %
         (user.id, user.username, user.email, product_name)
     )
    def handle(self, *args, **options):
        if len(args) == 0:
            # show list of plans
            def get_plan_str(p):
                hidden = p.manual_intervention is ManualPreApproval
                return '%s%s' % (p.name, ' (hidden)' if hidden else '')

            plan_strs = [get_plan_str(p) for p in get_products(hidden=True)]
            self.stdout.write('\nAvailable plans:\n\n%s' %
                              '\n'.join(plan_strs))
            self.stdout.write('\n\n\nFor full help, use --help\n\n')
            return
        elif len(args) != 2:
            raise CommandError(
                'Exactly two arguments are needed: a user and a product')
        userarg, product_name = args
        try:
            user_by_name = User.objects.get(username=userarg)
        except User.DoesNotExist:
            user_by_name = None
        try:
            userid = int(userarg)
        except ValueError:
            userid = None
        try:
            user_by_id = User.objects.get(id=userid)
        except User.DoesNotExist:
            user_by_id = None
        if user_by_name is None and user_by_id is None:
            raise CommandError('No such user found')
        elif user_by_name is not None and user_by_id is not None:
            if user_by_name == user_by_id:
                user = user_by_id
            else:
                raise CommandError(
                    'Two users match: one by id and one by username')
        else:
            user = user_by_name or user_by_id
        user.billing_account.subscribe_to_product(product_name)
        self.stdout.write(
            '\nSuccessfully subscribed User(id=%s, username=%s, email=%s) to %s\n\n'
            % (user.id, user.username, user.email, product_name))
Esempio n. 8
0
def update_all_producttypes(verbosity=2, **kwargs):

    product_types = list(ProductType.objects.all())
    for product in get_products(hidden=True):
        try:
            pt = ProductType.objects.get(name=product.__name__)
            product_types.remove(pt)
        except ProductType.DoesNotExist:
            pt = ProductType(name=product.__name__)
            pt.save()
            if verbosity >= 2:
                print "Adding product type '%s'" % (pt.name)
    # The presence of any remaining product types means the supplied app has an
    # undefined product. Confirm that the product type is stale before deletion.
    if product_types:
        if kwargs.get('interactive', False):
            prodcut_type_display = '\n'.join(
                ['    %s' % pt.name for pt in product_types])
            ok_to_delete = raw_input(
                """The following product types are stale and need to be deleted:

%s

Any objects related to these product types by a foreign key will also
be deleted. Are you sure you want to delete these product types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: """ % product_type_display)
        else:
            ok_to_delete = False

        if ok_to_delete == 'yes':
            for pt in product_types:
                if verbosity >= 2:
                    print "Deleting stale product type '%s'" % pt.name
                pt.delete()
        else:
            if verbosity >= 2:
                print "Stale product types remain."
Esempio n. 9
0
 def test_populate_product_cache_module_list(self):
     BILLING_PRODUCTS = ('example_saas_project.core.products', [
         'FreePlan',
         'BronzePlan',
         'SilverPlan',
         'GoldPlan',
         'CustomPlan',
         'SecretPlan',
         'EnterprisePlan',
     ])
     BILLING_DEFINITIONS = ()
     loading.product_cache = loading.populate_product_cache(
         products=BILLING_PRODUCTS, )
     plans = [
         billing_defs.FreePlan,
         billing_defs.BronzePlan,
         billing_defs.SilverPlan,
         billing_defs.GoldPlan,
         product_defs.CustomPlan,
         product_defs.SecretPlan,
         product_defs.EnterprisePlan,
     ]
     self.assertListEqual(plans, loading.get_products(hidden=True))
Esempio n. 10
0
def update_all_producttypes(verbosity=2, **kwargs):
    
    product_types = list(ProductType.objects.all())
    for product in get_products(hidden=True):
        try:
            pt = ProductType.objects.get(name=product.__name__)
            product_types.remove(pt)
        except ProductType.DoesNotExist:
            pt = ProductType(name=product.__name__)
            pt.save()
            if verbosity >= 2:
                print "Adding product type '%s'" % (pt.name)
    # The presence of any remaining product types means the supplied app has an
    # undefined product. Confirm that the product type is stale before deletion.
    if product_types:
        if kwargs.get('interactive', False):
            prodcut_type_display = '\n'.join(['    %s' % pt.name for pt in product_types])
            ok_to_delete = raw_input("""The following product types are stale and need to be deleted:

%s

Any objects related to these product types by a foreign key will also
be deleted. Are you sure you want to delete these product types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: """ % product_type_display)
        else:
            ok_to_delete = False

        if ok_to_delete == 'yes':
            for pt in product_types:
                if verbosity >= 2:
                    print "Deleting stale product type '%s'" % pt.name
                pt.delete()
        else:
            if verbosity >= 2:
                print "Stale product types remain."
Esempio n. 11
0
 def test_get_products(self):
     self.assertNotIn(product_defs.SecretPlan, loading.get_products())
     self.assertIn(product_defs.SecretPlan, loading.get_products(hidden=True))
Esempio n. 12
0
 def test_get_products(self):
     self.assertNotIn(product_defs.SecretPlan, loading.get_products())
     self.assertIn(product_defs.SecretPlan,
                   loading.get_products(hidden=True))