def test_custom_tag_1(self): # make a new tagset TagSet.objects_by_account(self.account).get_or_create(account=self.account,name="new test tagset") populate_rule_components_for_an_account(self.account) left_side = LeftSide.objects_by_account(self.account).get(display_name="have a new test tagset tag that") self.assertEqual(left_side.query_string_partial, "taggeditem__tag__in=Tag.objects_by_account(self.account).filter(tagset__name='new test tagset',name") self.assertEqualQuerySets(left_side.operators, self._tag_operators ) self.assertEqualQuerySets(left_side.right_side_types, self._text_right_side_types) self.assertEqual(left_side.add_closing_paren, True) return left_side
def test_populate_cleans_up_unused_rules(self): # create a custom tag from generic_tags.models import TagSet ts1 = TagSet.objects_by_account(self.account).get_or_create(account=self.account,name="new test tagset")[0] # repopulate populate_rule_components_for_an_account(self.account) # make sure it's there left_side = LeftSide.objects_by_account(self.account).get(display_name="have a new test tagset tag that") self.assertEqual(left_side.query_string_partial, "taggeditem__tag__in=Tag.objects_by_account(self.account).filter(tagset__name='new test tagset',name") self.assertEqualQuerySets(left_side.operators, self._tag_operators ) self.assertEqualQuerySets(left_side.right_side_types, self._text_right_side_types) # delete it ts1.delete() # repopulate populate_rule_components_for_an_account(self.account) # make sure it's gone self.assertEqual(LeftSide.objects_by_account(self.account).filter(display_name="have a new test tagset tag that").count(), 0)
def test_create_new_group_rule_for_custom_tag_is_exactly(self, right_hand_term="test", operator_name="is exactly"): # create a new group group = Factory.group(self.account) # make the custom tag TagSet.raw_objects.get_or_create(account=self.account, name="new test tagset") populate_rule_components_for_an_account(self.account) # create a new group rule left_side = LeftSide.objects_by_account(self.account).get(display_name="have a new test tagset tag that") icontains = Operator.objects_by_account(self.account).get(display_name=operator_name) rst = self._text_right_side_types[0] rsv = right_hand_term group_rule = GroupRule.raw_objects.create(account=self.account, group=group, left_side=left_side, operator=icontains, right_side_value=rsv, right_side_type=rst) new_group_rule = GroupRule.objects_by_account(self.account).get(pk=group_rule.pk) # assert the correct models exist self.assertEqual(new_group_rule.group, group) self.assertEqual(new_group_rule.left_side, left_side) self.assertEqual(new_group_rule.operator, icontains) self.assertEqual(new_group_rule.right_side_value, rsv) self.assertEqual(new_group_rule.group, group) return group, new_group_rule
def create_demo_site(cls, organization_name, subdomain=None, delete_existing=False, quick=False, verbose=None, mostly_empty=False, single_user=False, create_subscription=False, with_demo_flag=True): if quick: max_num_people = 5 max_num_orgs = 2 num_tags = 1 if not verbose: verbose = False else: max_num_people = 2000 max_num_orgs = 200 num_tags = 10 if not verbose: verbose = True site = Site.objects.get(pk=settings.SITE_ID) # Create account print_if_verbose(verbose, "Starting creation of %s's site." % organization_name) account = cls.account(name=organization_name, subdomain=subdomain, delete_existing=delete_existing, is_demo=with_demo_flag) request = DummyObj() request.account = account print_if_verbose(verbose, "Creating site at %s.%s." % (account.subdomain, site)) print_if_verbose(verbose, "Account created.") admin_accesslevel = AccessLevel.objects.get(name__iexact="Admin") staff_accesslevel = AccessLevel.objects.get(name__iexact="Staff") volunteer_accesslevel = AccessLevel.objects.get(name__iexact="Volunteer") # create admin user (admin / admin) cls.useraccount(account=account, username="******", password="******", access_level=admin_accesslevel) if not single_user: # create staff user (staff / staff) cls.useraccount(account=account, username="******", password="******", access_level=staff_accesslevel) # create volunteer user ( volunteer / volunteer ) cls.useraccount(account=account, username="******", password="******", access_level=volunteer_accesslevel) print_if_verbose(verbose, "Users created.") # create a bunch of reasonable tags, including the favorite color category gen_ts = cls.tagset(account, name="General") vol_ts = cls.tagset(account, name="Volunteer") don_ts = cls.tagset(account, name="Donor") color_ts = cls.tagset(account, name="Favorite Color") from rules.tasks import populate_rule_components_for_an_account populate_rule_components_for_an_account(account) print_if_verbose(verbose, "Tagsets created.") if not mostly_empty: # gen tags cls.tag(account, tagset=gen_ts, name="Board of Directors") cls.tag(account, tagset=gen_ts, name="Advocate") cls.tag(account, tagset=gen_ts, name="Media Contact") cls.tag(account, tagset=gen_ts, name="Community Partner") # vol tags cls.tag(account, tagset=vol_ts, name="Monday") cls.tag(account, tagset=vol_ts, name="Tuesday") cls.tag(account, tagset=vol_ts, name="Wednesday") cls.tag(account, tagset=vol_ts, name="Thursday") cls.tag(account, tagset=vol_ts, name="Friday") cls.tag(account, tagset=vol_ts, name="Weekly") cls.tag(account, tagset=vol_ts, name="Monthly") cls.tag(account, tagset=vol_ts, name="Phone Skills") # don tags cls.tag(account, tagset=don_ts, name="Major Donor") cls.tag(account, tagset=don_ts, name="Potential Major Donor") cls.tag(account, tagset=don_ts, name="Fundraiser") cls.tag(account, tagset=don_ts, name="Monthly Donor") cls.tag(account, tagset=don_ts, name="Quarterly Donor") cls.tag(account, tagset=don_ts, name="Yearly Donor") # color tags cls.tag(account, tagset=color_ts, name="Red") cls.tag(account, tagset=color_ts, name="Orange") cls.tag(account, tagset=color_ts, name="Yellow") cls.tag(account, tagset=color_ts, name="Green") cls.tag(account, tagset=color_ts, name="Aquamarine") cls.tag(account, tagset=color_ts, name="Blue") cls.tag(account, tagset=color_ts, name="Violet") cls.tag(account, tagset=color_ts, name="Purple") cls.tag(account, tagset=color_ts, name="Black") cls.tag(account, tagset=color_ts, name="White") cls.tag(account, tagset=color_ts, name="Gray") print_if_verbose(verbose, "Tags created.") # create a bunch of people people_created = [] num = cls.rand_int(3,max_num_people) print_if_verbose(verbose, "Creating %s people" % num,) for i in range(0, num): p = cls.person(account) people_created.append(p) print_nobreak_if_verbose(verbose) print_if_verbose(verbose, "done.") num = cls.rand_int(2,max_num_orgs) print_if_verbose(verbose, "Creating %s organizations" % num,) # create a few organizations, with people for i in range(0, num): cls.organization(account) print_nobreak_if_verbose(verbose) print_if_verbose(verbose, "done.") # give some of the people volunteer histories and statii print_if_verbose(verbose, "Adding volunteer histories",) for p in people_created: if cls.rand_bool(): cls.volunteer_history(account, p) if cls.rand_bool(): v = p.volunteer v.status = VOLUNTEER_STATII[1][0] v.save() print_nobreak_if_verbose(verbose) print_if_verbose(verbose, "done.") # give some of the people donation histories print_if_verbose(verbose, "Adding donation histories",) for p in people_created: if cls.rand_bool(): cls.donor_history(account, p) print_nobreak_if_verbose(verbose) print_if_verbose(verbose, "done.") print_if_verbose(verbose, "Adding conversations",) for p in people_created: if cls.rand_bool(): cls.conversation_history(account, p) print_nobreak_if_verbose(verbose) print_if_verbose(verbose, "done.") print_if_verbose(verbose, "Adding tags",) # give some of the people tags all_tags = [t for t in Tag.objects_by_account(account).all()] for p in people_created: for i in range(0,cls.rand_int(0,num_tags)): t = all_tags[cls.rand_int(0,len(all_tags)-1)] if t.tagset!=gen_ts or (cls.rand_bool() and cls.rand_bool()): t.add_tag_to_person(p) print_nobreak_if_verbose(verbose) print_if_verbose(verbose, "done." ) # create a few groups # Board of Directors group = cls.group(account, name="Board of Directors") cls.grouprule(account, "have a general tag that","contains","Board of Directors", group=group) print_if_verbose(verbose, "Created Board of Directors group") # Active Volunteers group = cls.group(account, name="Active Volunteers") cls.grouprule(account, "volunteer status","is",VOLUNTEER_STATII[0][0], group=group) print_if_verbose(verbose, "Created Active Volunteers group") # Warm color people group = cls.group(account, name="Warm Color People", rules_boolean=False) cls.grouprule(account, "have a Favorite Color tag that","contains","red", group=group) cls.grouprule(account, "have a Favorite Color tag that","contains","orange", group=group) cls.grouprule(account, "have a Favorite Color tag that","contains","yellow", group=group) print_if_verbose(verbose, "Created Warm color people group") # Recurring donors group = cls.group(account, name="Recurring Donors", rules_boolean=False) cls.grouprule(account, "have a Donor tag that","is exactly","monthly donor", group=group) cls.grouprule(account, "have a Donor tag that","is exactly","quarterly donor", group=group) cls.grouprule(account, "have a Donor tag that","is exactly","yearly donor", group=group) print_if_verbose(verbose, "Created Recurring donors group") # Volunteers this year today = datetime.date.today() group = cls.group(account, name="Volunteers this year") cls.grouprule(account, "last volunteer shift","is after",datetime.date(day=1,month=1,year=today.year), group=group) else: print_if_verbose(verbose, "Mostly empty called - skipping people, etc.") if create_subscription: sub = account.create_stripe_subscription() print_if_verbose(verbose, "Created subscription.") print_if_verbose(verbose, "Setup complete.") return account
def setUp(self, *args, **kwargs): self.account = self.setup_for_logged_in() populate_rule_components_for_an_account(self.account) self.people = [Factory.volunteer_history(self.account) for i in range(1,Factory.rand_int(30,100))] self.verificationErrors = []
def setUp(self, *args, **kwargs): cache.clear() self.account = self.setup_for_logged_in_with_no_data() populate_rule_components_for_an_account(self.account) self.verificationErrors = []
def setUp(self): self.account = Factory.account() populate_rule_components_for_an_account(self.account) self.request = Dummy() self.request.account = self.account
def setUp(self): self.account = Factory.account() populate_rule_components_for_an_account(self.account) self.request = Dummy() self.request.account = self.account self.left_side = LeftSide.objects_by_account(self.account).get(display_name="have a General tag that")