def test_admin_only_for_admin(self): def texts(sel): return [el.text for el in self.b.find_elements_by_css_selector(sel)] def nav_texts(): return texts('.nav li a') def admin_page_not_found(): b.get("%s/admin" % self.app_url()) self.assertIn('Not Found', texts('h1')) b = self.b admin_page_not_found() b.get(self.app_url()) self.assertNotIn('Admin', nav_texts()) User.objects.create_superuser(username='******', password='******', email='') self.log_in('admin') b.get(self.app_url()) self.assertIn('Admin', nav_texts()) user = UserFactory.create() self.log_in(user.username) b.get(self.app_url()) self.assertNotIn('Admin', nav_texts()) admin_page_not_found()
def __init__(self, section=None, status=SS_STATUS_ACCEPTED): self.user = UserFactory.create() self.parent = ParentFactory() self.parent.users.add(self.user) self.stu = StudentFactory.create(parent=self.parent) if section: StudentSectionAssignment.objects.create(student=self.stu, section=section, status=status)
def test_email_goes_to_right_parents(self): user1 = UserFactory.create() self.client.login(username=user1.username, password='******') parent1 = ParentFactory() parent1.users.add(user1) stu1a = StudentFactory.create(parent=parent1) stu1b = StudentFactory.create(parent=parent1) user2 = UserFactory.create() self.client.login(username=user2.username, password='******') parent2 = ParentFactory() parent2.users.add(user2) stu2a = StudentFactory.create(parent=parent2) stu2b = StudentFactory.create(parent=parent2) course1 = Course(name='Python') course1.save() stu1a.wants_courses.add(course1) py_sec = SectionFactory(course=course1) parents = email_parents(()) # No filters, so all parents should be included self.assertIn(parent1, parents) self.assertIn(parent2, parents) parents = email_parents((), send_only_upcoming=True) # No parents have students in upcoming sections self.assertNotIn(parent1, parents) self.assertNotIn(parent2, parents) StudentSectionAssignment(student=stu1a, section=py_sec, status=SS_STATUS_APPLIED).save() parents = email_parents((), send_only_upcoming=True) # parent1 now has a student in an upcoming section self.assertIn(parent1, parents) self.assertNotIn(parent2, parents) parents = email_parents((), send_only_wanted_upcoming=True) self.assertNotIn(parent1, parents) self.assertNotIn(parent2, parents) parents = email_parents((course1.id,), send_only_wanted_upcoming=True) self.assertIn(parent1, parents) self.assertNotIn(parent2, parents)
def test_can_view_students(self): user = UserFactory.create() self.client.login(username=user.username, password='******') parent = ParentFactory() parent.users.add(user) stu1 = StudentFactory.create(parent=parent) stu2 = StudentFactory.create(parent=parent) course1 = Course(name='Python') course1.save() stu1.wants_courses.add(course1) response = self.client.get(reverse('students') + '?wants=%i' % course1.id) self.assertEqual(200, response.status_code) soup = BeautifulSoup(response.content, 'html.parser') text = soup.get_text() self.assertIn(stu1.name, text) self.assertNotIn(stu2.name, text)