def test_alert_signup_form(self): factory = DataFactory() user = factory.create_user() url = '/practice/{}/concessions/'.format(self.practice.code) # Check form is displayed when user not loged in. response = self.client.get(url) self.assertContains(response, 'Get email updates') # Now log user in. self.client.force_login(user) # Check form is displayed when user has no bookmarks. response = self.client.get(url) self.assertContains(response, 'Get email updates') # Create bookmarks for CCG and All England, and check that form is # still displayed. factory.create_ncso_concessions_bookmark(self.ccg, user) factory.create_ncso_concessions_bookmark(None, user) response = self.client.get(url) self.assertContains(response, 'Get email updates') # Create bookmark for practice, and check that form is not displayed. factory.create_ncso_concessions_bookmark(self.practice, user) response = self.client.get(url) self.assertNotContains(response, 'Get email updates') self.assertContains(response, 'already signed up')
def test_all_england_alert_signup_form(self): factory = DataFactory() user = factory.create_user() url = "/all-england/concessions/".format(self.practice.code) # Check form is displayed when user not loged in. response = self.client.get(url) self.assertContains(response, "Get email updates") # Now log user in. self.client.force_login(user) # Check form is displayed when user has no bookmarks. response = self.client.get(url) self.assertContains(response, "Get email updates") # Create bookmarks for practice and CCG, and check that form is still # displayed. factory.create_ncso_concessions_bookmark(self.practice, user) factory.create_ncso_concessions_bookmark(self.ccg, user) response = self.client.get(url) self.assertContains(response, "Get email updates") # Create bookmark for All England, and check that form is not displayed. factory.create_ncso_concessions_bookmark(None, user) response = self.client.get(url) self.assertNotContains(response, "Get email updates") self.assertContains(response, "already signed up")
def setUpTestData(cls): factory = DataFactory() cls.months = factory.create_months_array(start_date="2018-02-01", num_months=6) # Our NCSO and tariff data extends further than our prescribing data by # a couple of months cls.prescribing_months = cls.months[:-2] # Create some CCGs (we need more than one so we can test aggregation # across CCGs at the All England level) cls.ccgs = [factory.create_ccg() for _ in range(2)] # Populate those CCGs with practices cls.practices = [] for ccg in cls.ccgs: for _ in range(2): cls.practices.append(factory.create_practice(ccg=ccg)) # Create some presentations cls.presentations = factory.create_presentations(6) # Create drug tariff and price concessions costs for these presentations factory.create_tariff_and_ncso_costings_for_presentations( cls.presentations, months=cls.months) # Create prescribing for each of the practices we've created for practice in cls.practices: factory.create_prescribing_for_practice( practice, presentations=cls.presentations, months=cls.prescribing_months) # Pull out an individual practice and CCG to use in our tests cls.practice = cls.practices[0] cls.ccg = cls.ccgs[0]
def setUp(self): self.api_prefix = '/api/1.0' factory = DataFactory() self.months = factory.create_months_array(start_date='2018-02-01') self.ccgs = [factory.create_ccg() for _ in range(2)] self.practices = [] for ccg in self.ccgs: for _ in range(2): self.practices.append(factory.create_practice(ccg=ccg)) self.presentations = factory.create_presentations( 2, vmpp_per_presentation=2) factory.create_tariff_and_ncso_costings_for_presentations( presentations=self.presentations, months=self.months) # Create prescribing for each of the practices we've created for practice in self.practices: factory.create_prescribing_for_practice( practice, presentations=self.presentations, months=self.months ) # Create and populate the materialized view table we need factory.populate_materialised_views() # Refresh vw__medians_for_tariff materialized view with connection.cursor() as cursor: cursor.execute("REFRESH MATERIALIZED VIEW vw__medians_for_tariff") super(TestAPISpendingViewsGhostGenerics, self).setUp()
def test_counts(self): factory = DataFactory() factory.create_measure(tags=['tag1']) factory.create_measure(tags=['tag1', 'tag2']) tags = _lazy_load_measure_tags(self.path) self.assertEqual(tags['tag1']['count'], 2) self.assertEqual(tags['tag2']['count'], 1)
def test_counts(self): factory = DataFactory() factory.create_measure(tags=["tag1"]) factory.create_measure(tags=["tag1", "tag2"]) tags = _lazy_load_measure_tags(self.path) self.assertEqual(tags["tag1"]["count"], 2) self.assertEqual(tags["tag2"]["count"], 1)
def test_all_england_alerts_sent(self): factory = DataFactory() # Create an All England bookmark, send alerts, and make sure one email # is sent to correct user bookmark = factory.create_org_bookmark(None) call_command(CMD_NAME) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, [bookmark.user.email])
def test_pcn_alerts_sent(self): """Create a PCN bookmark, send alerts, and make sure an email is sent to correct user, and that its contents mention PCNs """ factory = DataFactory() pcn = PCN.objects.get(pk="E00000011") bookmark = factory.create_org_bookmark(pcn) call_command(CMD_NAME) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, [bookmark.user.email]) self.assertIn("PCN", mail.outbox[0].body)
def test_alert_signup(self): factory = DataFactory() factory.create_user(email="*****@*****.**") factory.create_ncso_concessions_bookmark(None) self.assertEqual(NCSOConcessionBookmark.objects.count(), 1) url = "/practice/{}/concessions/".format(self.practice.code) data = {"email": "*****@*****.**", "practice": self.practice.code} response = self.client.post(url, data, follow=True) self.assertContains(response, "alerts about NCSO concessions for Practice 5") self.assertEqual(NCSOConcessionBookmark.objects.count(), 2) bookmark = NCSOConcessionBookmark.objects.last() self.assertEqual(bookmark.practice, self.practice) self.assertEqual(bookmark.user.email, "*****@*****.**")
def test_all_england_alert_signup(self): factory = DataFactory() factory.create_user(email="*****@*****.**") factory.create_ncso_concessions_bookmark(self.practice) self.assertEqual(NCSOConcessionBookmark.objects.count(), 1) url = "/all-england/concessions/" data = {"email": "*****@*****.**"} response = self.client.post(url, data, follow=True) self.assertContains( response, "alerts about NCSO concessions for the NHS in England") self.assertEqual(NCSOConcessionBookmark.objects.count(), 2) bookmark = NCSOConcessionBookmark.objects.order_by("id").last() self.assertEqual(bookmark.practice, None) self.assertEqual(bookmark.pct, None) self.assertEqual(bookmark.user.email, "*****@*****.**")
def test_send_alerts(self, attach_image): factory = DataFactory() # Create a bookmark, send alerts, and make sure one email is sent. factory.create_ncso_concessions_bookmark(self.ccg) call_command("send_ncso_concessions_alerts", "2019-02-14") self.assertEqual(len(mail.outbox), 1) # Create another bookmark, send alerts for same date as above, and make # sure only one email is sent. mail.outbox = [] factory.create_ncso_concessions_bookmark(self.practice) call_command("send_ncso_concessions_alerts", "2019-02-14") self.assertEqual(len(mail.outbox), 1) # Send alerts for new date, and make sure two emails are sent. mail.outbox = [] call_command("send_ncso_concessions_alerts", "2019-02-15") self.assertEqual(len(mail.outbox), 2)
def test_all_england_alert_signup(self): factory = DataFactory() factory.create_user(email="*****@*****.**") factory.create_ncso_concessions_bookmark(self.practice) self.assertEqual(NCSOConcessionBookmark.objects.count(), 1) url = "/all-england/concessions/" data = {"email": "*****@*****.**", "newsletters": ["alerts"]} response = self.client.post(url, data, follow=True) self.assertContains( response, "Check your email and click the confirmation link") self.assertEqual(NCSOConcessionBookmark.objects.count(), 2) bookmark = NCSOConcessionBookmark.objects.order_by("id").last() self.assertEqual(bookmark.practice, None) self.assertEqual(bookmark.pct, None) self.assertEqual(bookmark.user.email, "*****@*****.**") self.assertEqual(bookmark.approved, True)
def setUpTestData(self): self.api_prefix = "/api/1.0" factory = DataFactory() self.months = factory.create_months_array(start_date="2018-02-01") self.ccgs = [factory.create_ccg() for _ in range(2)] self.practices = [] for ccg in self.ccgs: for _ in range(2): self.practices.append(factory.create_practice(ccg=ccg, setting=4)) self.presentations = factory.create_presentations(2, vmpp_per_presentation=2) factory.create_tariff_and_ncso_costings_for_presentations( presentations=self.presentations, months=self.months ) # Create prescribing for each of the practices we've created for practice in self.practices: factory.create_prescribing_for_practice( practice, presentations=self.presentations, months=self.months )
def test_vmp(self): rsp = self.client.get("/dmd/vmp/318412000/") self.assertContains(rsp, "<td>Name</td><td>Acebutolol 100mg capsules</td>", html=True) self.assertNotContains(rsp, "Analyse prescribing") self.assertNotContains(rsp, "See prices paid") factory = DataFactory() practice = factory.create_practice() presentation = Presentation.objects.create(bnf_code="0204000C0AAAAAA", name="Acebut HCl_Cap 100mg") factory.create_prescribing_for_practice(practice, [presentation]) stop_patching = patch_global_matrixstore(matrixstore_from_postgres()) try: rsp = self.client.get("/dmd/vmp/318412000/") self.assertContains(rsp, "Analyse prescribing") self.assertContains(rsp, "See prices paid") finally: stop_patching()
def setUpClass(cls): super(TestSpendingViews, cls).setUpClass() factory = DataFactory() cls.months = factory.create_months_array(start_date="2018-02-01", num_months=6) # Our NCSO and tariff data extends further than our prescribing data by # a couple of months cls.prescribing_months = cls.months[:-2] # Create some high level orgs cls.regional_team = factory.create_regional_team() cls.stp = factory.create_stp() # Create some CCGs (we need more than one so we can test aggregation # across CCGs at the All England level) cls.ccgs = [ factory.create_ccg(stp=cls.stp, regional_team=cls.regional_team) for _ in range(2) ] # Create a PCN (one will do) cls.pcn = factory.create_pcn() # Populate those CCGs with practices cls.practices = [] for ccg in cls.ccgs: for _ in range(2): cls.practices.append( factory.create_practice(ccg=ccg, pcn=cls.pcn)) # Create some presentations cls.presentations = factory.create_presentations( 6, vmpp_per_presentation=2) # Create drug tariff and price concessions costs for these presentations factory.create_tariff_and_ncso_costings_for_presentations( cls.presentations, months=cls.months) # Create prescribing for each of the practices we've created for practice in cls.practices: factory.create_prescribing_for_practice( practice, presentations=cls.presentations, months=cls.prescribing_months) # Pull out an individual practice and CCG to use in our tests cls.practice = cls.practices[0] cls.ccg = cls.ccgs[0]
def test_all_england_alert_signup(self): factory = DataFactory() user = factory.create_user(email='*****@*****.**') factory.create_ncso_concessions_bookmark(self.practice) self.assertEqual(NCSOConcessionBookmark.objects.count(), 1) url = '/all-england/concessions/' data = { 'email': '*****@*****.**', 'newsletters': ['alerts'], } response = self.client.post(url, data, follow=True) self.assertContains( response, "Check your email and click the confirmation link") self.assertEqual(NCSOConcessionBookmark.objects.count(), 2) bookmark = NCSOConcessionBookmark.objects.order_by('id').last() self.assertEqual(bookmark.practice, None) self.assertEqual(bookmark.pct, None) self.assertEqual(bookmark.user.email, '*****@*****.**') self.assertEqual(bookmark.approved, True)
def test_send_alerts(self): factory = DataFactory() # Create a bookmark, send alerts, and make sure one email is sent to # correct user bookmark = factory.create_org_bookmark(None) call_command('send_all_england_alerts') self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, [bookmark.user.email]) # Create another bookmark, send alerts again and make sure email is # only sent to new user mail.outbox = [] bookmark2 = factory.create_org_bookmark(None) call_command('send_all_england_alerts') self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, [bookmark2.user.email]) # Try sending alerts again and make sure no emails are sent mail.outbox = [] call_command('send_all_england_alerts') self.assertEqual(len(mail.outbox), 0)