def add_a_donation(self, amount=None, date=None, type=None, notes=None, in_honor=False, in_memory=False, honorarium_name=None): sel = self.selenium self.switch_to_donor_tab() if not amount: amount = "%.2f" % (Factory.rand_currency()) if not date: d = Factory.rand_date() date = "%02d/%02d/%02d" % (d.month, d.day, d.year) sel.click("css=tabbed_box[name=add_a_donation] tab_title") sel.type("css=#id_amount", amount) sel.type("css=#id_date", date) if type: sel.select("css=#id_type",type) if notes: sel.type("css=#id_notes", notes) if in_honor: sel.click("css=#id_in_honor_of") if in_memory: sel.click("css=#id_in_memory_of") if honorarium_name: sel.type("css=#id_honorarium_name", honorarium_name) sel.click("css=tabbed_box[name=add_a_donation] .add_donation_btn") time.sleep(2) return amount,date
def test_challenge_has_set_up_tags(self): # needed since the setup creates some and I don't want to add it to all the other tests. Tag.objects_by_account(self.a1).delete() self.a1.check_challenge_progress() assert self.a1.challenge_has_set_up_tags == False Factory.tag_person(self.a1) self.a1.check_challenge_progress() assert self.a1.challenge_has_set_up_tags == True
def test__detect_type(self): fh = Factory.people_mailing_list_spreadsheet_file(self.a1, file_type=CSV_TYPE) s = SpreadsheetAbstraction(self.a1, fh, "people", filename="test.foo") self.assertEqual(s.type, CSV_TYPE) self.assertEqual(s.is_valid,True) fh = Factory.people_mailing_list_spreadsheet_file(self.a1, file_type=EXCEL_TYPE) s = SpreadsheetAbstraction(self.a1, fh, "people", filename="test.bar") self.assertEqual(s.type, EXCEL_TYPE) self.assertEqual(s.is_valid,True)
def test_that_after_signup_users_can_change_their_billing_info(self): # And see it updated. sel = self.selenium self.get_logged_in() self.go_to_the_account_page() self.enter_billing_info_signup() assert sel.is_text_present("XXXX-XXXX-XXXX-%s" % (Factory.test_cc_number(True)[-4:])) self.enter_billing_info_signup(cc_number="4222222222222") assert not sel.is_text_present("XXXX-XXXX-XXXX-%s" % (Factory.test_cc_number(True)[-4:])) assert sel.is_text_present("XXXX-XXXX-XXXX-2222")
def test_creating_and_deleting_an_account_does_so_successfully(self): from django.contrib.auth.models import User a1 = Factory.create_demo_site("test1", quick=True, create_subscription=True) a2 = Factory.create_demo_site("test2", quick=True) a1.delete() time.sleep(5) a3 = Factory.create_demo_site("test3", quick=True) a3.delete() self.assertEqual(Account.objects.all().count(), 1) self.assertEqual(User.objects.all().count(), 3) a2.delete() self.assertEqual(Account.objects.all().count(), 0) self.assertEqual(User.objects.all().count(), 0)
def test_that_a_new_person_in_account_1_does_not_show_in_account_2_org_people_search(self): sel = self.selenium cache.clear() self.go_to_the_login_page() self.log_in() self.assert_login_succeeded() self.create_john_smith_and_verify() self.create_new_organization() sel.click("css=tabbed_box tab_title") time.sleep(0.5) sel.click("id_search_new_person") sel.type("id_search_new_person", "john") time.sleep(2) assert sel.is_text_present('John Smith') a2 = self.create_demo_site("test2") ua = Factory.useraccount(account=a2) self.set_site("test2") self.go_to_the_login_page("test2") self.log_in(ua=ua) self.assert_login_succeeded() self.create_new_organization() sel.click("css=tabbed_box tab_title") time.sleep(0.5) sel.click("id_search_new_person") sel.type("id_search_new_person", "john") time.sleep(2) assert sel.is_text_present('No people found for search "john".')
def add_a_conversation(self, body=None, date=None, type="in-person"): sel = self.selenium self.switch_to_conversation_tab() if not body: body = Factory.rand_str(500) if not date: d = Factory.rand_date() date = "%02d/%02d/%02d" % (d.month, d.day, d.year) sel.click("css=tabbed_box[name=add_a_conversation] tab_title") sel.type("css=#id_body", body) sel.click("css=input[name=conversation_type][value=%s]" % (type,)) sel.type("css=#id_date", date) sel.click("css=tabbed_box[name=add_a_conversation] .add_conversation_btn") time.sleep(2) return body,date
def test_num_volunteer_hours(self): a = Factory.create_demo_site("test", quick=True) hours = 0 for c in CompletedShift.objects.all(): hours += c.duration self.assertEqual(a.num_volunteer_hours, hours)
def test_completed_shifts_by_year_returns_sanely(): account = Factory.account() person = Factory.person(account) today = datetime.date.today() s1 = CompletedShift.raw_objects.create(account=account, volunteer=person.volunteer, duration=5, date=today) s2 = CompletedShift.raw_objects.create(account=account, volunteer=person.volunteer, duration=1, date=today) target = [{'shifts': [s2, s1], 'total_hours': s1.duration+s2.duration, 'total_shifts': 2, 'year': today.year }] assert person.volunteer.completed_shifts_by_year == target
def created_and_imported_excel_spreadsheet(self, **kwargs): fh = Factory.people_mailing_list_spreadsheet_file(self.a1, file_type=EXCEL_TYPE, **kwargs) # import it fh.seek(0) s = SpreadsheetAbstraction(self.a1, fh, "people", filename="test.xls") self.assertEqual(s.is_valid,True) return s
def test_challenge_has_added_board(self): Factory.tag(self.a1, name="Board of Directors") bg = Factory.group(self.a1,"board of directors") Factory.grouprule(self.a1, "have any tag that","contains","Board of Directors", group=bg) Factory.tag_person(self.a1, tag_name="Board of Directors") self.a1.check_challenge_progress() assert self.a1.challenge_has_added_board == True
def test_queryset_for_new_group_rule_for_last_volunteer_shift_is_on(self): # create a new group rule (and TagSet) group, group_rule = self.test_create_new_group_rule_for_last_volunteer_shift_is_on() # hand-create a few people, some of whom match, and others who don't ppl = self._generate_people() target_date = datetime.date(month=3,day=24,year=2010) Factory.completed_volunteer_shift(ppl[2], date=target_date) Factory.completed_volunteer_shift(ppl[4], date=target_date) # assert the queryset string is right self.assertEqual(group_rule.queryset_filter_string, "filter(volunteer__completedshift__date=datetime.date(month=3,day=24,year=2010))") # get the queryset, make sure it matches a hand-created one. qs = group.members hand_qs = Person.objects_by_account(self.account).filter(Q(pk=ppl[2].pk) | Q(pk=ppl[4].pk) ) self.assertEqualQuerySets(qs,hand_qs)
def test_that_new_signups_can_sign_up_for_an_account(self): sel = self.selenium self.get_logged_in() self.go_to_the_account_page() self.enter_billing_info_signup() assert sel.is_text_present("Status: Free Trial") assert sel.is_text_present("XXXX-XXXX-XXXX-%s" % (Factory.test_cc_number(True)[-4:])) assert sel.is_text_present("Signup Date: %s" % (date(datetime.date.today()),) ) assert sel.is_element_present("link=Update Billing Information")
def test_deleting_an_account_cancels_its_subscription(self): a1 = Factory.create_demo_site("test1", quick=True, create_subscription=True) stripe_id = a1.stripe_customer_id c = self.stripe.Customer.retrieve(stripe_id) assert hasattr(c, "subscription") a1.delete() c = self.stripe.Customer.retrieve(stripe_id) assert not hasattr(c, "subscription")
def test_saving_a_blank_group_gives_it_a_filler_name(self): account = Factory.account() ts = TagSet.raw_objects.create(account=account) self.assertEqual(ts.name,BLANK_TAGSET_NAME) ts.name = "foo" ts.save() self.assertEqual(ts.name,"foo") ts.name = "" ts.save() self.assertEqual(ts.name,BLANK_TAGSET_NAME)
def test_objects_by_account_limits_to_account(self, model=Person, factory_method=Factory.person, **kwargs): a1 = Factory.account("test1",delete_existing=True) g1 = factory_method(account=a1, **kwargs) a2 = Factory.account("test2",delete_existing=True) g2 = factory_method(account=a2, **kwargs) request = Dummy() request.account = a1 self.assertNotEqual(a1,a2) self.assertNotEqual(g1,g2) self.assertEqual([g for g in model.objects_by_account(a1).all()], [g1]) self.assertEqual([g for g in model.objects_by_account(request).all()], [g1]) self.assertEqual([g for g in model.objects_by_account(a2).all()], [g2]) try: self.assertEqual([g for g in model.raw_objects.all()],[g1, g2]) except: self.assertEqual([g for g in model.raw_objects.all()],[g2, g1])
def test_that_new_donations_can_include_a_type_and_notes(self): sel = self.selenium self.create_person_and_go_to_donor_tab() notes_str = Factory.rand_str() a1, d1 = self.add_a_donation(amount=85.8, date="3/8/2011", type="Check", notes=notes_str) # make sure recent donations display cleanly self.assertEqual("$%.2f"%a1, sel.get_text("css=.donor_donation_table .donation_row:nth(0) .amount")) self.assertEqual("March 8, 2011", sel.get_text("css=.donor_donation_table .donation_row:nth(0) .date")) self.assertEqual("Check", sel.get_text("css=.donor_donation_table .donation_row:nth(0) .type")) self.assertEqual("Notes: %s" % notes_str, sel.get_text("css=.donor_donation_table .donation_row:nth(0) .notes_body"))
def add_a_new_shift(self, hours=None, date=None): sel = self.selenium if not hours: hours = Factory.rand_int(1,10) sel.click("css=tabbed_box[name=add_a_volunteer_shift] tab_title") sel.type("css=#id_duration", hours) if date: sel.type("css=#id_date", date) sel.click("css=tabbed_box[name=add_a_volunteer_shift] .add_shift_btn") time.sleep(2)
def test_that_logged_in_site2s_user_cannot_manually_browse_to_site_ones_page(self): sel = self.selenium a2 = self.create_demo_site("test2") ua = Factory.useraccount(account=a2) self.go_to_the_login_page("test2") self.log_in(ua=ua) self.assert_login_succeeded() self.go_to_the_login_page() self.open("/people") assert sel.is_element_present("css=.login_btn")
def test_that_requesting_an_invalid_group_404s(self): sel = self.selenium self.go_to_the_login_page() self.log_in() self.assert_login_succeeded() # make sure to make a new person for i in range(0,10): Factory.group(account=self.a1) self.create_new_group() # get pk url = sel.get_location() url = url[url.find(":%s/" % settings.LIVE_SERVER_PORT)+5:] a2 = self.create_demo_site("test2") ua = Factory.useraccount(account=a2) self.go_to_the_login_page(site="test2") self.log_in(ua=ua) self.open(url, site="test2") time.sleep(10) assert sel.is_text_present("not found")
def test_that_site2s_user_cannot_log_into_site_one(self): a2 = self.create_demo_site("test2") self.go_to_the_login_page() ua = Factory.useraccount(account=a2) self.log_in(ua=ua, with_assert=False) self.assert_login_failed() self.go_to_the_login_page("test2") self.log_in(ua=ua) self.assert_login_succeeded()
def _generate_people(self, number=5): from volunteers import VOLUNTEER_STATII people = [] for i in range(0,number): p = Factory.person(self.account) v = p.volunteer v.status = VOLUNTEER_STATII[1][0] v.save() people.append(p.pk) people = Person.objects_by_account(self.account).filter(pk__in=people) return people
def test_that_requesting_an_invalid_person_404s(self): sel = self.selenium cache.clear() self.go_to_the_login_page() self.log_in() self.assert_login_succeeded() # make sure to make a new person for i in range(0,20): Factory.person(account=self.a1) self.create_john_smith_and_verify() # get pk url = sel.get_location() person_url = url[url.find(":%s/" % settings.LIVE_SERVER_PORT)+5:] a2 = self.create_demo_site("test2") ua = Factory.useraccount(account=a2) self.go_to_the_login_page(site="test2") self.log_in(ua=ua) self.open(person_url, site="test2") assert sel.is_text_present("not found")
def test_invalid_rule_missing_operator_side(self): right_hand_term="test" # operator_name="contains" group = Factory.group(self.account) left_side = LeftSide.objects_by_account(self.account).get(display_name="have a General tag that") # icontains = Operator.objects_by_account(self.account).get(display_name=operator_name) icontains = None rst = self._text_right_side_types[0] rsv = right_hand_term GroupRule.raw_objects.create(account=self.account, group=group, left_side=left_side, operator=icontains, right_side_value=rsv, right_side_type=rst) self.assertEqual(group.has_a_valid_rule, False)
def test_challenge_has_imported_contacts(self): user_account = Factory.useraccount(self.a1) DataImport.objects.create( account=self.a1, importer=user_account, start_time=datetime.datetime.now(), import_type="people", source_filename="test.csv", fields=["first_name","last_name","email","phone_number"], has_header=False, ) self.a1.check_challenge_progress() assert self.a1.challenge_has_imported_contacts == True
def _test_spreadsheet_download_200s_for_template_type(self, template_type, file_type=None): from spreadsheets.views import download spreadsheet = Factory.spreadsheet(self.a1, template_type, file_type=file_type) request = self.factory.get( "%s?type=%s&spreadsheet_id=%s" % (reverse("spreadsheets:download"), spreadsheet.default_filetype, spreadsheet.pk) ) request.account = self.a1 response = download(request) self.assertEqual(response.status_code, 200)
def test_donations_by_year_returns_sanely(): account = Factory.account() person = Factory.person(account) today = datetime.date.today() d1 = Donation.raw_objects.create(account=account, donor=person.donor, amount=5, date=today) d2 = Donation.raw_objects.create(account=account, donor=person.donor, amount=41, date=datetime.datetime.now()-datetime.timedelta(days=1)) d3 = Donation.raw_objects.create(account=account, donor=person.donor, amount=41, date=datetime.datetime.now()-datetime.timedelta(days=360)) target = [{'donations': [d1, d2], 'total_donations': d1.amount+d2.amount, 'total_number_of_donations':2, 'year': today.year },{'donations': [d3], 'total_donations': d3.amount, 'total_number_of_donations':1, 'year': d3.date.year }] assert person.donor.donations_by_year == target
def test_age_and_next_age(self): today = datetime.date.today() today_20_years_ago = datetime.date(year=today.year-20, day=today.day, month=today.month) yesterday_20_years_ago = today_20_years_ago - datetime.timedelta(days=1) tomorrow_20_years_ago = today_20_years_ago + datetime.timedelta(days=1) p1 = Factory.person(account=self.account, birthday=yesterday_20_years_ago) p2 = Factory.person(account=self.account, birthday=today_20_years_ago) p3 = Factory.person(account=self.account, birthday=tomorrow_20_years_ago) p4 = Factory.person(account=self.account) p4.birth_year = None p4.birth_day = 4 p4.birth_month = 9 p4.save() self.assertEqual(p1.age, 20) self.assertEqual(p2.age, 20) self.assertEqual(p3.age, 19) self.assertEqual(p4.age, None) self.assertEqual(p1.next_or_todays_birthday_age, 21) self.assertEqual(p2.next_or_todays_birthday_age, 20) self.assertEqual(p3.next_or_todays_birthday_age, 20) self.assertEqual(p4.next_or_todays_birthday_age, None)
def enter_billing_info_signup(self, valid_cc=True, cc_number=None): """Assumes you're starting on the manage acct page""" if not cc_number: cc_number = Factory.test_cc_number(valid_cc) sel = self.selenium sel.click("link=Update Billing Information") sel.type("css=#id_card_number",cc_number) sel.type("css=#id_card_cvv","123") sel.select("css=#id_card_expiry_month","May") sel.select("css=#id_card_expiry_year","2020") sel.click("css=#subscription_submit") if valid_cc: sel.wait_for_page_to_load("30000") else: time.sleep(6)
def test_create_new_group_rule_for_general_tag_contains(self, right_hand_term="test", operator_name="contains"): # create a new group rule group = Factory.group(self.account) left_side = LeftSide.objects_by_account(self.account).get(display_name="have a General 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