Beispiel #1
0
class UserProfileTest(TestCase):

    def setUp(self):
        self.user = User.objects.create_user("test_student",
                                             "*****@*****.**",
                                             "testpassword")
        UserProfile.objects.get_or_create(user=self.user,
                                          gender="M",
                                          is_faculty="ST",
                                          institute="I1",
                                          specialty="S2",
                                          hispanic_latino="Y",
                                          year_of_graduation=2015,
                                          consent_participant=True,
                                          consent_not_participant=False)

        self.hierarchy = Hierarchy(name="main", base_url="/")
        self.hierarchy.save()

        self.root = Section.add_root(label="Root", slug="",
                                     hierarchy=self.hierarchy)

        self.root.append_child("Section 1", "section-1")
        self.root.append_child("Section 2", "section-2")

        self.section1 = Section.objects.get(slug="section-1")
        self.section2 = Section.objects.get(slug="section-2")

    def tearDown(self):
        self.user.delete()
        self.hierarchy.delete()

    def test_set_has_visited(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)

        self.assertFalse(profile.get_has_visited(self.section1))
        self.assertFalse(profile.get_has_visited(self.section2))

        profile.set_has_visited([self.section1, self.section2])

        self.assertTrue(profile.get_has_visited(self.section1))
        self.assertTrue(profile.get_has_visited(self.section2))

    def test_last_location(self):
        user = User.objects.get(username="******")

        # By default, the 1st leaf is returned if there are no visits
        self.assertEquals(user.profile.last_location(), self.section1)

        user.profile.set_has_visited([self.section1])
        self.assertEquals(user.profile.last_location(), self.section1)

        user.profile.set_has_visited([self.section2])
        self.assertEquals(user.profile.last_location(), self.section2)

        user.profile.set_has_visited([self.section1])
        self.assertEquals(user.profile.last_location(), self.section1)

    def test_user_unicode(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)
        uni_name = smart_text(profile)
        self.assertEqual(uni_name, "test_student")

    def test_user_display_name(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)
        display_name = UserProfile.display_name(profile)
        self.assertEqual(display_name, "test_student")

    def test_percent_complete(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)

        self.assertEquals(0, profile.percent_complete())

        profile.set_has_visited([self.root, self.section1])
        self.assertEquals(66, profile.percent_complete())
        profile.set_has_visited([self.section2])
        self.assertEquals(100, profile.percent_complete())

    def test_percent_complete_null_hierarchy(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)
        profile.speciality = "pediatrics"

        self.assertEquals(0, profile.percent_complete())

    def test_is_role_student(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)

        profile.is_faculty = "FA"
        profile.save()
        self.assertFalse(profile.is_role_student())
        self.assertTrue(profile.is_role_faculty())

        profile.is_faculty = "OT"
        profile.save()
        self.assertFalse(profile.is_role_student())
        self.assertFalse(profile.is_role_faculty())

        profile.is_faculty = "ST"
        profile.save()
        self.assertTrue(profile.is_role_student())
        self.assertFalse(profile.is_role_faculty())

    def test_default_role(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)

        self.assertEquals("main", profile.role())

    def test_role(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)

        # pre-doctoral
        self.assertEquals(profile.role(), "main")

        # verify being a faculty doesn't change this selection
        profile.is_faculty = "FA"
        profile.save()
        self.assertEquals(profile.role(), "main")

        profile.specialty = "S1"
        profile.save()
        self.assertEquals(profile.role(), "general")

        profile.specialty = "S2"  # Pre-Doctoral Student"
        profile.save()
        self.assertEquals(profile.role(), "main")

        profile.specialty = "S3"  # Endodontics
        profile.save()
        self.assertEquals(profile.role(), "endodontics")

        profile.specialty = "S4"  # Oral and Maxillofacial Surgery"
        profile.save()
        self.assertEquals(profile.role(), "surgery")

        profile.specialty = "S5"  # Pediatric Dentistry
        profile.save()
        self.assertEquals(profile.role(), "pediatrics")

        profile.specialty = "S6"  # Periodontics
        profile.save()
        self.assertEquals(profile.role(), "perio")

        profile.specialty = "S7"  # Prosthodontics
        profile.save()
        self.assertEquals(profile.role(), "general")

        profile.specialty = "S8"  # Orthodontics
        profile.save()
        self.assertEquals(profile.role(), "orthodontics")

        profile.specialty = "S9"  # Other
        profile.save()
        self.assertEquals(profile.role(), "main")

        profile.specialty = "S10"  # Dental Public Health
        profile.save()
        self.assertEquals(profile.role(), "main")
class UserProfileTest(TestCase):
    def setUp(self):
        self.user = User.objects.create_user("test_student", "*****@*****.**",
                                             "testpassword")
        UserProfile.objects.get_or_create(user=self.user,
                                          gender="M",
                                          is_faculty="ST",
                                          institute="I1",
                                          specialty="S2",
                                          hispanic_latino="Y",
                                          year_of_graduation=2015,
                                          consent_participant=True,
                                          consent_not_participant=False)

        self.hierarchy = Hierarchy(name="main", base_url="/")
        self.hierarchy.save()

        self.root = Section.add_root(label="Root",
                                     slug="",
                                     hierarchy=self.hierarchy)

        self.root.append_child("Section 1", "section-1")
        self.root.append_child("Section 2", "section-2")

        self.section1 = Section.objects.get(slug="section-1")
        self.section2 = Section.objects.get(slug="section-2")

    def tearDown(self):
        self.user.delete()
        self.hierarchy.delete()

    def test_set_has_visited(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)

        self.assertFalse(profile.get_has_visited(self.section1))
        self.assertFalse(profile.get_has_visited(self.section2))

        profile.set_has_visited([self.section1, self.section2])

        self.assertTrue(profile.get_has_visited(self.section1))
        self.assertTrue(profile.get_has_visited(self.section2))

    def test_last_location(self):
        user = User.objects.get(username="******")

        # By default, the 1st leaf is returned if there are no visits
        self.assertEquals(user.profile.last_location(), self.section1)

        user.profile.set_has_visited([self.section1])
        self.assertEquals(user.profile.last_location(), self.section1)

        user.profile.set_has_visited([self.section2])
        self.assertEquals(user.profile.last_location(), self.section2)

        user.profile.set_has_visited([self.section1])
        self.assertEquals(user.profile.last_location(), self.section1)

    def test_user_unicode(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)
        uni_name = UserProfile.__unicode__(profile)
        self.assertEqual(uni_name, "test_student")

    def test_user_display_name(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)
        display_name = UserProfile.display_name(profile)
        self.assertEqual(display_name, "test_student")

    def test_percent_complete(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)

        self.assertEquals(0, profile.percent_complete())

        profile.set_has_visited([self.root, self.section1])
        self.assertEquals(66, profile.percent_complete())
        profile.set_has_visited([self.section2])
        self.assertEquals(100, profile.percent_complete())

    def test_percent_complete_null_hierarchy(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)
        profile.speciality = "pediatrics"

        self.assertEquals(0, profile.percent_complete())

    def test_is_role_student(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)

        profile.is_faculty = "FA"
        profile.save()
        self.assertFalse(profile.is_role_student())
        self.assertTrue(profile.is_role_faculty())

        profile.is_faculty = "OT"
        profile.save()
        self.assertFalse(profile.is_role_student())
        self.assertFalse(profile.is_role_faculty())

        profile.is_faculty = "ST"
        profile.save()
        self.assertTrue(profile.is_role_student())
        self.assertFalse(profile.is_role_faculty())

    def test_default_role(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)

        self.assertEquals("main", profile.role())

    def test_role(self):
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)

        # pre-doctoral
        self.assertEquals(profile.role(), "main")

        # verify being a faculty doesn't change this selection
        profile.is_faculty = "FA"
        profile.save()
        self.assertEquals(profile.role(), "main")

        profile.specialty = "S1"
        profile.save()
        self.assertEquals(profile.role(), "general")

        profile.specialty = "S2"  # Pre-Doctoral Student"
        profile.save()
        self.assertEquals(profile.role(), "main")

        profile.specialty = "S3"  # Endodontics
        profile.save()
        self.assertEquals(profile.role(), "endodontics")

        profile.specialty = "S4"  # Oral and Maxillofacial Surgery"
        profile.save()
        self.assertEquals(profile.role(), "surgery")

        profile.specialty = "S5"  # Pediatric Dentistry
        profile.save()
        self.assertEquals(profile.role(), "pediatrics")

        profile.specialty = "S6"  # Periodontics
        profile.save()
        self.assertEquals(profile.role(), "perio")

        profile.specialty = "S7"  # Prosthodontics
        profile.save()
        self.assertEquals(profile.role(), "general")

        profile.specialty = "S8"  # Orthodontics
        profile.save()
        self.assertEquals(profile.role(), "orthodontics")

        profile.specialty = "S9"  # Other
        profile.save()
        self.assertEquals(profile.role(), "main")

        profile.specialty = "S10"  # Dental Public Health
        profile.save()
        self.assertEquals(profile.role(), "main")
Beispiel #3
0
class TestViews(TestCase):
    def setUp(self):
        self.c = Client()
        self.factory = RequestFactory()
        self.user = User.objects.create_user('test_student',
                                             '*****@*****.**',
                                             'testpassword')
        self.user.save()

        self.hierarchy = Hierarchy(name="main", base_url="/")
        self.hierarchy.save()

        root = Section.add_root(label="Root", slug="",
                                hierarchy=self.hierarchy)

        root.append_child("Section 1", "section-1")
        root.append_child("Section 2", "section-2")

        self.section1 = Section.objects.get(slug="section-1")
        self.section2 = Section.objects.get(slug="section-2")

    def tearDown(self):
        self.user.delete()

    def test_index(self):
        # it should redirect us somewhere.
        response = self.c.get("/")
        self.assertEquals(response.status_code, 302)
        # for now, we don't care where. really, we
        # are just making sure it's not a 500 error
        # at this point

    def test_smoke(self):
        # run the smoketests. we don't care if they pass
        # or fail, we just want to make sure that the
        # smoketests themselves don't have an error
        response = self.c.get("/smoketest/")
        self.assertEquals(response.status_code, 200)

    def test_accessible(self):
        pass
        # Need better test...

    def test_is_accessible(self):
        pass

    def test_clear_state(self):
        pass

    def test_consent_no_profile(self):
        self.c = Client()
        self.c.login(username='******', password='******')
        self.response = self.c.get('/', follow=True)
        self.assertEqual(self.response.status_code, 200)
        self.assertEquals(self.response.redirect_chain[0][1], 302)
        self.assertEquals(self.response.templates[0].name,
                          "main/create_profile.html")

    def test_consent_incomplete_profile(self):
        # User has a profile, but does not have "consent" or other
        # special fields filled out. Redirect to create profile
        UserProfile.objects.create(user=self.user,
                                   gender='M',
                                   is_faculty='ST',
                                   institute='I1',
                                   specialty='S1',
                                   hispanic_latino='Y',
                                   year_of_graduation=2015,
                                   consent_participant=False,
                                   consent_not_participant=False)

        self.c = Client()
        self.c.login(username='******', password='******')
        self.response = self.c.get('/', follow=True)
        self.assertEqual(self.response.status_code, 200)
        self.assertEquals(self.response.templates[0].name,
                          "main/create_profile.html")
        self.assertEquals(self.response.redirect_chain[0][1], 302)

    def test_consent_complete_profile(self):
        # User has a complete profile
        profile = UserProfile.objects.create(user=self.user,
                                             gender='M',
                                             is_faculty='ST',
                                             institute='I1',
                                             specialty='S1',
                                             hispanic_latino='Y',
                                             year_of_graduation=2015,
                                             consent_participant=True,
                                             consent_not_participant=False)
        profile.gender = 'F'
        profile.is_faculty = 'ST'
        profile.specialty = 'S10'
        profile.year_of_graduation = 2014
        profile.consent_participant = True
        profile.consent_not_participant = False
        profile.save()

        self.c = Client()
        self.c.login(username='******', password='******')
        self.response = self.c.get('/', follow=True)
        self.assertEqual(self.response.status_code, 200)
        self.assertEquals(self.response.templates[0].name,
                          "main/index.html")
        self.assertEquals(len(self.response.redirect_chain), 0)