def test_option_for_user_to_renew_subscription_on_dashboard(self): self.grantor_org = self.user.organisation order = OrderFactory.create(organisation=self.grantor_org, status=Order.STATUS_APPROVED) SubscriptionFactory.create(order=order, end_date=date.today()) invitation_count = 1 AssessmentPurchaseFactory.create( package=self.package, order=order, order__organisation=self.grantor_org, order__status=Order.STATUS_APPROVED, number_included=invitation_count, ) with self.wait_for_page_load(): self.browser.find_element_by_link_text("Dashboard").click() expired_subscription_message = "Your subscription expires in 0 days" expired_subscription_element = self.browser.find_element_by_css_selector( "div > .col-md-6.mt-3 > .text-bold") self.assertIn(expired_subscription_message, expired_subscription_element.text) renew_button = self.browser.find_element_by_link_text("Renew") self.assertTrue(renew_button.is_enabled())
def test_user_should_be_able_to_view_remaining_invitation_credits(self): self.grantor_org = self.user.organisation order = OrderFactory.create(organisation=self.grantor_org, status=Order.STATUS_APPROVED) SubscriptionFactory.create(order=order) invitation_count = 10 AssessmentPurchaseFactory.create( package=self.package, order=order, order__organisation=self.grantor_org, order__status=Order.STATUS_APPROVED, number_included=invitation_count, ) with self.wait_for_page_load(): self.browser.find_element_by_link_text("Invitations").click() # credits_field = self.browser_wait.until( # lambda browser: browser.find_element_by_class_name( # "badge-pill.bg-crystal-blue.number") # ) # locator changed and WebDriverWait works wait = WebDriverWait(self.browser, 10) credits_field = wait.until( EC.presence_of_element_located(( By.XPATH, "//span[@class='badge badge-pill bg-crystal-blue _700 number mx-1']" ))) actual_text = credits_field.text self.assertEquals(actual_text, "10") self.assertEqual(order.organisation.remaining_invites, 10)
def test_view_order_history_for_subscription(self): self.grantor_org = self.user.organisation order = OrderFactory.create(organisation=self.grantor_org, status=Order.STATUS_APPROVED) SubscriptionFactory.create(order=order) invitation_count = 1 AssessmentPurchaseFactory.create( package=self.package, order=order, order__organisation=self.grantor_org, order__status=Order.STATUS_APPROVED, number_included=invitation_count, ) with self.wait_for_page_load(): self.browser.find_element_by_link_text( "Subscription & billing").click() with self.wait_for_page_load(): self.browser.find_element_by_link_text("Order history").click() table_order = self.browser.find_element_by_id("packages-list") table_rows = table_order.find_elements_by_xpath("tbody/tr/td") current_formatted_date = date.today().strftime("%d %b %Y") self.assertEqual(current_formatted_date.lstrip("0"), table_rows[1].text) self.assertEquals("Paid", table_rows[2].text)
def setUp(self): # create subscribers SubscriptionFactory.create_batch(size=3) # create a vumi backend self.vumi_backend = BackendFactory(name='vumi') # to add noise to the db self.create_batch(VumiLogFactory, 5, direction=INCOMING, start=100) self.create_batch(SMSFactory, 2, direction=INCOMING, start=100, carrier=self.vumi_backend)
def test_user_cannot_send_invitation_where_there_are_no_credits_left(self): self.grantor_org = self.user.organisation order = OrderFactory.create(organisation=self.grantor_org, status=Order.STATUS_APPROVED) SubscriptionFactory.create(order=order) invitation_count = 1 AssessmentPurchaseFactory.create( package=self.package, order=order, order__organisation=self.grantor_org, order__status=Order.STATUS_APPROVED, number_included=invitation_count, ) self.grantee_user = UserFactory.create(password=self.password) assign_role(self.grantee_user, 'manager') with self.wait_for_page_load(): self.browser.find_element_by_link_text("Invitations").click() # credits_field = self.browser_wait.until( # lambda browser: browser.find_element_by_class_name( # "badge-pill.bg-crystal-blue.number") # ) wait = WebDriverWait(self.browser, 10) credits_field = wait.until( EC.presence_of_element_located(( By.XPATH, "//span[@class='badge badge-pill bg-crystal-blue _700 number mx-1']" ))) actual_text = credits_field.text self.assertEquals(actual_text, "1") self.assertEqual(order.organisation.remaining_invites, 1) with self.wait_for_page_load(): self.browser.find_element_by_link_text("Make invitation").click() # select from list self.select_drop_down_for_invitation("grantee") # select survey self.select_drop_down_for_invitation("survey") # select tier # 0-Bronze,1-Silver,2-Gold,3-Platinum tiers = self.browser.find_elements_by_css_selector( "label[class='ui-check w-sm']") tiers[1].click() self.browser.find_element_by_css_selector( "button[type='submit']").click() db_order = Order.objects.get(id=order.id) self.assertEqual(db_order.organisation.remaining_invites, 0) self.assertTrue( EC.invisibility_of_element_located( (By.LINK_TEXT, "Make invitation")))
def test_view_submitted_assessment_report_by_grantee(self): self.grantee = UserFactory.create(password=self.password) assign_role(self.grantee, "admin") assign_role(self.user, "admin") self.survey = SurveyFactory.create() self.survey_response = SurveyResponseFactory.create( organisation=self.grantee.organisation, survey=self.survey, level=1, submitted=timezone.now()) self.section = SurveySectionFactory.create(number=1, ) self.question = SurveyQuestionFactory.create(survey=self.survey, level=1, section=self.section) self.answer = SurveyAnswerFactory.create(response=self.survey_response, question=self.question) self.invitation = InvitationFactory.create( survey=self.survey, grantee=self.survey_response.organisation, status=3, accepted=True, grantor=self.user.organisation) grantor_org = self.user.organisation order = OrderFactory.create(organisation=grantor_org, status=Order.STATUS_APPROVED) SubscriptionFactory.create(order=order) package = AssessmentPackageFactory.create(number_included=1, price=900.00) AssessmentPurchaseFactory.create( package=package, order=order, order__organisation=grantor_org, order__status=Order.STATUS_APPROVED, number_included=1, ) self.login(self.user.email, self.password) self.click_and_wait_for_page_load( self.browser.find_element_by_link_text("Invitations"), ) self.assertTrue(EC.presence_of_element_located((By.LINK_TEXT, "View"))) view_submitted_survey = self.browser.find_element_by_link_text("View") self.click_and_wait_for_page_load(view_submitted_survey) self.assertTrue( self.browser_wait.until( lambda browser: browser.find_element_by_link_text( "Print report").is_enabled())) completion_percentage = self.browser_wait.until( lambda browser: self.browser.find_element_by_css_selector( ".number._700")) report_header = self.browser.find_element_by_tag_name("h2").text self.assertEquals(completion_percentage.text, "100%") self.assertIn("Full report", report_header)
def setUp(self): # create subscribers SubscriptionFactory.create_batch(size=3) # create a vumi backend self.vumi_backend = BackendFactory(name='vumi') # 3 incoming discrepancies incoming = INCOMING self.create_batch(VumiLogFactory, 5, direction=incoming) self.create_batch(SMSFactory, 2, direction=incoming, carrier=self.vumi_backend) # 2 outgoing discrepancies outgoing = OUTGOING creation_date = now() - timedelta(hours=25) self.create_batch(VumiLogFactory, 3, direction=outgoing, start=10) # sms are older than 24 hours self.create_batch(SMSFactory, 5, direction=outgoing, creation_date=creation_date, start=10, carrier=self.vumi_backend)
def setUp(self): self.user = UserFactory.create(password=self.password) assign_role(self.user, 'manager') self.survey = SurveyFactory.create() self.section4_1 = SurveySectionFactory.create(number=1, ) self.section4_2 = SurveySectionFactory.create(number=2, ) self.section4_3 = SurveySectionFactory.create(number=3, ) self.q1 = SurveyQuestionFactory.create(survey=self.survey, level=1, section=self.section4_1) self.q2 = SurveyQuestionFactory.create(survey=self.survey, level=2, section=self.section4_1) self.q3 = SurveyQuestionFactory.create(survey=self.survey, level=2, section=self.section4_1) self.q4 = SurveyQuestionFactory.create(survey=self.survey, level=3, section=self.section4_2) self.q5 = SurveyQuestionFactory.create(survey=self.survey, level=4, section=self.section4_3) self.grantor_org = self.user.organisation order = OrderFactory.create(organisation=self.grantor_org, status=Order.STATUS_APPROVED) SubscriptionFactory.create(order=order) package = AssessmentPackageFactory.create(number_included=1, price=900.00) AssessmentPurchaseFactory.create( package=package, order=order, order__organisation=self.grantor_org, order__status=Order.STATUS_APPROVED, number_included=10, ) self.login(self.user.email, self.password) self.assertIn(self.title, self.browser.title)
def test_inform_user_for_subscription_to_expire(self): self.grantor_org = self.user.organisation order = OrderFactory.create(organisation=self.grantor_org, status=Order.STATUS_APPROVED) current_date = date.today() next_month_date = current_date + relativedelta(days=30) SubscriptionFactory.create(order=order, end_date=next_month_date) with self.wait_for_page_load(): self.browser.find_element_by_link_text("Assessments").click() expiration_info = "Your subscription expires in 30 days" subscription_expiry_notif = self.browser.find_element_by_class_name( "notification-header.pjax-update") self.assertIn(expiration_info, subscription_expiry_notif.text) renew_button = self.browser.find_element_by_link_text("Renew") self.assertTrue(renew_button.is_enabled())
def test_user_cannot_view_assessments_with_expired_subscription(self): self.grantor_org = self.user.organisation order = OrderFactory.create(organisation=self.grantor_org, status=Order.STATUS_APPROVED) current_date = date.today() SubscriptionFactory.create(order=order, end_date=current_date) self.grantee = UserFactory.create(password=self.password) assign_role(self.user, "admin") self.survey = SurveyFactory.create() self.survey_response = SurveyResponseFactory.create( organisation=self.grantee.organisation, survey=self.survey, level=1, submitted=timezone.now()) self.section = SurveySectionFactory.create(number=1, ) self.question = SurveyQuestionFactory.create(survey=self.survey, level=1, section=self.section) self.answer = SurveyAnswerFactory.create(response=self.survey_response, question=self.question) self.invitation = InvitationFactory.create( survey=self.survey, grantee=self.survey_response.organisation, status=3, accepted=True, grantor=self.user.organisation) with self.wait_for_page_load(): self.browser.find_element_by_link_text("Assessments").click() renew_subscription_field = self.browser.find_element_by_link_text( "Renew subscription") self.assertTrue(renew_subscription_field.is_enabled()) assessment_notification = self.browser.find_element_by_class_name( "notification-header.pjax-update").text view_assessments_info_text = "Your subscription expires in 0 days" self.assertIn(view_assessments_info_text, assessment_notification)
def test_user_can_view_assessments_with_active_subscription(self): self.grantor_org = self.user.organisation order = OrderFactory.create(organisation=self.grantor_org, status=Order.STATUS_APPROVED) print("Order is", order) SubscriptionFactory.create(order=order) self.grantee = UserFactory.create(password=self.password) assign_role(self.user, "admin") self.survey = SurveyFactory.create() self.survey_response = SurveyResponseFactory.create( organisation=self.grantee.organisation, survey=self.survey, level=1, submitted=timezone.now()) print("Survey response is", self.survey_response) self.section = SurveySectionFactory.create(number=1, ) print("Section is", self.section) self.question = SurveyQuestionFactory.create(survey=self.survey, level=1, section=self.section) print("Queston is", self.question) self.answer = SurveyAnswerFactory.create(response=self.survey_response, question=self.question) print("Answer is", self.answer) self.invitation = InvitationFactory.create( survey=self.survey, grantee=self.survey_response.organisation, status=3, accepted=True, grantor=self.user.organisation) print("Invitation is", self.invitation) with self.wait_for_page_load(): self.browser.find_element_by_link_text("Assessments").click() import time time.sleep(10) self.assertTrue(EC.presence_of_element_located((By.LINK_TEXT, "View"))) view_submitted_survey = self.browser.find_element_by_link_text("View") self.assertTrue(view_submitted_survey.is_enabled())
def test_user_cannot_send_invitation_without_buying_invitation_package( self): self.grantor_org = self.user.organisation order = OrderFactory.create(organisation=self.grantor_org, status=Order.STATUS_APPROVED) SubscriptionFactory.create(order=order) with self.wait_for_page_load(): self.browser.find_element_by_link_text("Invitations").click() require_subscription_text = "Invite a grantees to submit an assessment" # self.assertIn(require_subscription_text, # self.browser.find_element_by_class_name( # "box-body.px-4.d-flex").text) # locator changed self.assertIn( require_subscription_text, self.browser.find_element_by_xpath( "//div[contains(text(),'Invite a grantees to submit an assessment')]" ).text)
def test_inform_user_when_subscription_is_expired(self): self.grantor_org = self.user.organisation order = OrderFactory.create(organisation=self.grantor_org, status=Order.STATUS_APPROVED) current_date = date.today() SubscriptionFactory.create(order=order, end_date=current_date) with self.wait_for_page_load(): self.browser.find_element_by_link_text("Assessments").click() # expiration_info = "Your subscription expires in 0 days" expiration_info = "Your subscription expires in" # subscription_expiry_notif = self.browser.find_element_by_class_name( # "notification-header.pjax-update") # locator changed subscription_expiry_notif = self.browser.find_element_by_xpath( "//span[@class='vr-middle text-s-md']") self.assertIn(expiration_info, subscription_expiry_notif.text) renew_button = self.browser.find_element_by_link_text("Renew") self.assertTrue(renew_button.is_enabled())
def setUp(self): self.user = UserFactory.create(password=self.password) assign_role(self.user, 'admin') self.browser.get(self.live_server_url) self.grantor = self.user.organisation new_order = OrderFactory.create(organisation=self.grantor, status=Order.STATUS_APPROVED) SubscriptionFactory.create(order=new_order, price=1500.00) new_package = AssessmentPackageFactory.create(name=str(self.user), number_included=2, price=900.00) self.assess = AssessmentPurchaseFactory.create(order=new_order, package=new_package, number_included=2, price=900.00) self.user1 = UserFactory.create(password=self.password) self.grantee = self.user1.organisation self.survey_list = SurveyFactory.create(name="Survey 0")
def test_user_can_buy_a_package_for_invitation_credits(self): self.grantor_org = self.user.organisation order = OrderFactory.create(organisation=self.grantor_org, status=Order.STATUS_APPROVED) SubscriptionFactory.create(order=order) with self.wait_for_page_load(): self.browser.find_element_by_link_text("Assessments").click() with self.wait_for_page_load(): self.browser.find_element_by_link_text( "Subscription & billing").click() package_section = self.browser.find_element_by_class_name( "invitation-package") buy_package_button = package_section.find_element_by_link_text("Buy") buy_package_button.click() self.browser_wait.until( EC.text_to_be_present_in_element((By.ID, "total-amount"), "900")) total_amount = self.browser.find_element_by_id("total-amount").text self.assertIn("900", total_amount) self.browser.find_element_by_css_selector( "button[type='submit']").click() order_submit_message = "You have successfully submitted the order" alert_text = self.browser.find_element_by_id("alert").text self.assertEqual(alert_text, order_submit_message) # package_order_info = self.browser.find_element_by_class_name( # "d-flex.bg-md-champagne") # locator changed package_order_info = self.browser.find_element_by_xpath( "//span[contains(text(),'10 assessment invitations')]") self.assertIn("10 assessment invitations", package_order_info.text)
def test_order_completion_subscription(self): assign_role(self.user, 'admin') self.subscription = SubscriptionFactory.create( order__organisation=self.user.organisation, order__status=Order.STATUS_APPROVED) self.subscription.order.send_order_completion()
def test_subscription_renewal_one_month(self): assign_role(self.user, 'admin') self.subscription = SubscriptionFactory.create(end_date=date.today() + timedelta(days=30), order=self.order) check_subscription_expiry()
def test_order_confirmation_subscription(self): assign_role(self.user, 'admin') self.subscription = SubscriptionFactory.create(order=self.order) self.order.send_order_confirmation()
def setUp(self): SubscriptionFactory.create_batch(size=10)
def test_order_canceled_subscription(self): assign_role(self.user, 'admin') self.subscription = SubscriptionFactory.create( order__organisation=self.user.organisation, order__status=Order.STATUS_CANCELED) self.subscription.order.send_order_cancelation()