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)
     # Create and populate the materialized view table we need
     factory.populate_materialised_views()
     # Pull out an individual practice and CCG to use in our tests
     cls.practice = cls.practices[0]
     cls.ccg = cls.ccgs[0]
     # Create user to own a bookmark
     cls.user = factory.create_user()
    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()