'Helper function to count visible elements in the schedule'

def assert_elements_in_schedule(self, url, n_chapters=2, n_sequentials=4, n_verticals=8):

    response = self.client.get(url)
    self.assertEqual(response.status_code, 200)
    chapters = json.loads(response.mako_context['schedule'])
    sequentials = flatten([chapter.get('children', []) for chapter in chapters])
    verticals = flatten([sequential.get('children', []) for sequential in sequentials])
    self.assertEqual(n_chapters, len(chapters))
    self.assertEqual(n_sequentials, len(sequentials))
    self.assertEqual(n_verticals, len(verticals))
    all_elements = ((chapters + sequentials) + verticals)
    return [elem['location'] for elem in all_elements if ('location' in elem)]
