class OrganizationDeletionTestCase(OrganizationManagementTestCase):
    def test_delete_org(self):
        """Delete an empty org"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-pencil"), None, "Make sure 'edit' icon appears."
        )
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-trash"), None, "Make sure 'delete' icon appears."
        )
        self.browser.find_element_by_css_selector(".icon-trash").click()
        self.browser.switch_to_alert().accept()
        self.browser_wait_for_no_element(".icon-trash")
        self.browser_check_django_message(message_type="success", contains="successfully deleted")
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".icon-trash"), None, "Make sure 'delete' icon is gone."
            )

    def test_cancel_delete_org(self):
        """Click to delete an empty org, then choose CANCEL"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-pencil"), None, "Make sure 'edit' icon appears."
        )
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-trash"), None, "Make sure 'delete' icon appears."
        )
        self.browser.find_element_by_css_selector(".icon-trash").click()
        self.browser.switch_to_alert().dismiss()
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-trash"), None, "Make sure 'delete' icon appears."
        )
        self.browser_check_django_message(num_messages=0)

    def test_cannot_delete_full_org(self):
        """Confirm no option to delete an org with data"""
        # Save zone info, but without adding
        self.zone = Zone(name=self.ZONE_NAME)
        self.zone.save()
        self.org.add_zone(self.zone)
        self.org.save()

        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-pencil"), None, "Make sure 'edit' icon appears."
        )
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".icon-trash"),
                None,
                "Make sure 'delete' icon does not appear.",
            )

    def test_issue_697(self):
        self.facility = Facility(name=self.FACILITY_NAME)
        self.facility.save()
        self.test_delete_org()
Example #2
0
class OrganizationDeletionTestCase(OrganizationManagementTestCase):
    def test_delete_org(self):
        """Delete an empty org"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-pencil"), None,
            "Make sure 'edit' icon appears.")
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-trash"), None,
            "Make sure 'delete' icon appears.")
        self.browser.find_element_by_css_selector(".icon-trash").click()
        self.browser.switch_to_alert().accept()
        self.browser_wait_for_no_element(".icon-trash")
        self.browser_check_django_message(message_type="success",
                                          contains="successfully deleted")
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".icon-trash"), None,
                "Make sure 'delete' icon is gone.")

    def test_cancel_delete_org(self):
        """Click to delete an empty org, then choose CANCEL"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-pencil"), None,
            "Make sure 'edit' icon appears.")
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-trash"), None,
            "Make sure 'delete' icon appears.")
        self.browser.find_element_by_css_selector(".icon-trash").click()
        self.browser.switch_to_alert().dismiss()
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-trash"), None,
            "Make sure 'delete' icon appears.")
        self.browser_check_django_message(num_messages=0)

    def test_cannot_delete_full_org(self):
        """Confirm no option to delete an org with data"""
        # Save zone info, but without adding
        self.zone = Zone(name=self.ZONE_NAME)
        self.zone.save()
        self.org.add_zone(self.zone)
        self.org.save()

        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".icon-pencil"), None,
            "Make sure 'edit' icon appears.")
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".icon-trash"), None,
                "Make sure 'delete' icon does not appear.")

    def test_issue_697(self):
        self.facility = Facility(name=self.FACILITY_NAME)
        self.facility.save()
        self.test_delete_org()
Example #3
0
def initialize_facility(facility_name=None):
    facility_name = facility_name or settings.INSTALL_FACILITY_NAME

    # Finally, install a facility--would help users get off the ground
    if facility_name:
        facility = get_object_or_None(Facility, name=facility_name)
        if not facility:
            facility = Facility(name=facility_name)
            facility.save()
        Settings.set("default_facility", facility.id)
Example #4
0
def initialize_facility(facility_name=None):
    facility_name = facility_name or settings.INSTALL_FACILITY_NAME

    # Finally, install a facility--would help users get off the ground
    if facility_name:
        facility = get_object_or_None(Facility, name=facility_name)
        if not facility:
            facility = Facility(name=facility_name)
            facility.save()
        Settings.set("default_facility", facility.id)
Example #5
0
    def setUp(self):
        """Create a new facility and facility user"""
        super(ChangeLocalUserPassword, self).setUp()

        self.old_password = '******'
        self.username = "******"
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.username,
                                 facility=self.facility)
        self.user.set_password(self.old_password)
        self.user.save()
Example #6
0
    def test_unicode_string(self):
        # Dependencies
        dev = Device.get_own_device()
        self.assertNotIn(unicode(dev), "Bad Unicode data", "Device: Bad conversion to unicode.")

        fac = Facility(name=self.korean_string)
        fac.save()
        self.assertNotIn(unicode(fac), "Bad Unicode data", "Facility: Bad conversion to unicode.")

        fg = FacilityGroup(facility=fac, name=self.korean_string)
        fg.save()
        self.assertNotIn(unicode(fg), "Bad Unicode data", "FacilityGroup: Bad conversion to unicode.")

        user = FacilityUser(
            facility=fac,
            group=fg,
            first_name=self.korean_string,
            last_name=self.korean_string,
            username=self.korean_string,
            notes=self.korean_string,
        )
        user.set_password(self.korean_string * settings.PASSWORD_CONSTRAINTS["min_length"])
        user.save()
        self.assertNotIn(unicode(user), "Bad Unicode data", "FacilityUser: Bad conversion to unicode.")

        known_classes = [ExerciseLog, UserLog, UserLogSummary, VideoLog]

        #
        elog = ExerciseLog(user=user, exercise_id=self.korean_string)
        self.assertNotIn(unicode(elog), "Bad Unicode data", "ExerciseLog: Bad conversion to unicode (before saving).")
        elog.save()
        self.assertNotIn(unicode(elog), "Bad Unicode data", "ExerciseLog: Bad conversion to unicode (after saving).")

        vlog = VideoLog(user=user, video_id=self.korean_string, youtube_id=self.korean_string)
        self.assertNotIn(unicode(vlog), "Bad Unicode data", "VideoLog: Bad conversion to unicode (before saving).")
        vlog.save()
        self.assertNotIn(unicode(vlog), "Bad Unicode data", "VideoLog: Bad conversion to unicode (after saving).")

        ulog = UserLog(user=user)
        self.assertNotIn(unicode(ulog), "Bad Unicode data", "UserLog: Bad conversion to unicode.")

        ulogsum = UserLogSummary(
            user=user,
            device=dev,
            activity_type=1,
            start_datetime=datetime.now(),
            end_datetime=datetime.now(),
        )
        self.assertNotIn(unicode(ulogsum), "Bad Unicode data", "UserLogSummary: Bad conversion to unicode.")
Example #7
0
    def setUp(self):
        super(TestSaveVideoLog, self).setUp()
        # create a facility and user that can be referred to in models across tests
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.USERNAME,
                                 facility=self.facility)
        self.user.set_password(self.PASSWORD)
        self.user.save()

        # create an initial VideoLog instance so we have something to update later
        self.original_videolog = VideoLog(video_id=self.VIDEO_ID,
                                          youtube_id=self.YOUTUBE_ID,
                                          user=self.user)
        self.original_videolog.points = self.ORIGINAL_POINTS
        self.original_videolog.total_seconds_watched = self.ORIGINAL_SECONDS_WATCHED
        self.original_videolog.save()
def generate_fake_facilities(names=("Wilson Elementary",)):
    """Add the given fake facilities"""
    facilities = []

    for name in names:
        found_facilities = Facility.objects.filter(name=name)
        if found_facilities:
            facility = found_facilities[0]
            logging.info("Retrieved facility '%s'" % name)
        else:
            facility = Facility(name=name)
            facility.save()
            logging.info("Created facility '%s'" % name)

        facilities.append(facility)

    return facilities
Example #9
0
def generate_fake_facilities(names=("Wilson Elementary", )):
    """Add the given fake facilities"""
    facilities = []

    for name in names:
        found_facilities = Facility.objects.filter(name=name)
        if found_facilities:
            facility = found_facilities[0]
            logging.info("Retrieved facility '%s'" % name)
        else:
            facility = Facility(name=name)
            facility.save()
            logging.info("Created facility '%s'" % name)

        facilities.append(facility)

    return facilities
Example #10
0
    def setUp(self):
        super(TestSaveExerciseLog, self).setUp()

        # create a facility and user that can be referred to in models across tests
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.USERNAME,
                                 facility=self.facility)
        self.user.set_password(self.PASSWORD)
        self.user.save()

        # create an initial ExerciseLog instance so we have something to update later
        self.original_exerciselog = ExerciseLog(exercise_id=self.EXERCISE_ID,
                                                user=self.user)
        self.original_exerciselog.points = self.ORIGINAL_POINTS
        self.original_exerciselog.attempts = self.ORIGINAL_ATTEMPTS
        self.original_exerciselog.streak_progress = self.ORIGINAL_STREAK_PROGRESS
        self.original_exerciselog.save()
Example #11
0
class ChangeLocalUserPassword(MainTestCase):
    """Tests for the changelocalpassword command"""
    def setUp(self):
        """Create a new facility and facility user"""
        super(ChangeLocalUserPassword, self).setUp()

        self.old_password = '******'
        self.username = "******"
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.username,
                                 facility=self.facility)
        self.user.set_password(self.old_password)
        self.user.save()

    def test_change_password_on_existing_user(self):
        """Change the password on an existing user."""

        # Now, re-retrieve the user, to check.
        (out, err, val) = call_command_with_output("changelocalpassword",
                                                   self.user.username,
                                                   noinput=True)
        self.assertEqual(err, "", "no output on stderr")
        self.assertNotEqual(out, "", "some output on stdout")
        self.assertEqual(val, 0, "Exit code is not zero")

        new_password = re.search(
            r"Generated new password for user .*: '(?P<password>.*)'",
            out).group('password')
        self.assertNotEqual(self.old_password, new_password)

        c = KALiteClient()
        success = c.login(username=self.user.username,
                          password=new_password,
                          facility=self.facility.id)
        self.assertTrue(success, "Was not able to login as the test user")

    def test_change_password_on_nonexistent_user(self):
        nonexistent_username = "******"
        with self.assertRaises(CommandError):
            (out, err, val) = call_command_with_output("changelocalpassword",
                                                       nonexistent_username,
                                                       noinput=True)
    def setUp(self):
        """Create a new facility and facility user"""
        super(ChangeLocalUserPassword, self).setUp()

        self.old_password = '******'
        self.username = "******"
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.username, facility=self.facility)
        self.user.set_password(self.old_password)
        self.user.save()
Example #13
0
    def setUp(self):
        super(TestSaveVideoLog, self).setUp()
        # create a facility and user that can be referred to in models across tests
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.USERNAME, facility=self.facility)
        self.user.set_password(self.PASSWORD)
        self.user.save()

        # create an initial VideoLog instance so we have something to update later
        self.original_videolog = VideoLog(video_id=self.VIDEO_ID, youtube_id=self.YOUTUBE_ID, user=self.user)
        self.original_videolog.points = self.ORIGINAL_POINTS
        self.original_videolog.total_seconds_watched = self.ORIGINAL_SECONDS_WATCHED
        self.original_videolog.save()
class ChangeLocalUserPassword(MainTestCase):
    """Tests for the changelocalpassword command"""

    def setUp(self):
        """Create a new facility and facility user"""
        super(ChangeLocalUserPassword, self).setUp()

        self.old_password = '******'
        self.username = "******"
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.username, facility=self.facility)
        self.user.set_password(self.old_password)
        self.user.save()


    def test_change_password_on_existing_user(self):
        """Change the password on an existing user."""

        # Now, re-retrieve the user, to check.
        (out,err,val) = call_command_with_output("changelocalpassword", self.user.username, noinput=True)
        self.assertEqual(err, "", "no output on stderr")
        self.assertNotEqual(out, "", "some output on stdout")
        self.assertEqual(val, 0, "Exit code is not zero")

        new_password =  re.search(r"Generated new password for user .*: '(?P<password>.*)'", out).group('password')
        self.assertNotEqual(self.old_password, new_password)

        c = KALiteClient()
        success = c.login(username=self.user.username, password=new_password, facility=self.facility.id)
        self.assertTrue(success, "Was not able to login as the test user")


    def test_change_password_on_nonexistent_user(self):
        nonexistent_username = "******"
        with self.assertRaises(CommandError):
            (out, err, val) = call_command_with_output("changelocalpassword", nonexistent_username, noinput=True)
Example #15
0
    def setUp(self):
        super(TestSaveExerciseLog, self).setUp()

        # create a facility and user that can be referred to in models across tests
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.USERNAME, facility=self.facility)
        self.user.set_password(self.PASSWORD)
        self.user.save()

        # create an initial ExerciseLog instance so we have something to update later
        self.original_exerciselog = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user)
        self.original_exerciselog.points = self.ORIGINAL_POINTS
        self.original_exerciselog.attempts = self.ORIGINAL_ATTEMPTS
        self.original_exerciselog.streak_progress = self.ORIGINAL_STREAK_PROGRESS
        self.original_exerciselog.save()
 def test_issue_697(self):
     self.facility = Facility(name=self.FACILITY_NAME)
     self.facility.save()
     self.test_delete_org()
Example #17
0
 def create_facility(self, facility_name=default_facility_name):
     if Facility.objects.filter(name=facility_name):
         logging.debug("Creating duplicate facility: %s" % facility_name)
     facility = Facility(name=facility_name)
     facility.save()
     return facility
Example #18
0
 def test_issue_697(self):
     self.facility = Facility(name=self.FACILITY_NAME)
     self.facility.save()
     self.test_delete_org()
 def create_facility(self, facility_name=default_facility_name):
     if Facility.objects.filter(name=facility_name):
         logging.debug("Creating duplicate facility: %s" % facility_name)
     facility = Facility(name=facility_name)
     facility.save()
     return facility
Example #20
0
class ZoneDeletionTestCase(OrganizationManagementTestCase):
    def setUp(self):
        super(ZoneDeletionTestCase, self).setUp()
        self.zone = Zone(name=self.ZONE_NAME)
        self.zone.save()
        self.org.add_zone(self.zone)
        self.org.save()

    def test_delete_zone_from_org_admin(self):
        """Delete a zone from the org_management page"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        self.browser.find_element_by_css_selector(".zone-delete-link").click()
        self.browser.switch_to_alert().accept()
        self.browser_wait_for_no_element(".zone-delete-link")
        self.browser_check_django_message(message_type="success",
                                          contains="successfully deleted")
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".zone-delete-link"),
                None, "Make sure 'delete' link is gone.")

    def test_cancel_delete_zone_from_org_admin(self):
        """Delete a zone from the org_management page"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        self.browser.find_element_by_css_selector(".zone-delete-link").click()
        self.browser.switch_to_alert().dismiss()
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".zone-delete-link"),
            None, "Make sure 'delete' link still exists.")
        self.browser_check_django_message(num_messages=0)

    def test_delete_zone_from_zone_admin(self):
        """Delete a zone from the org_management page"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        zone_url = self.browser.find_element_by_css_selector(
            ".zone-manage-link").get_attribute("href")
        self.browse_to(zone_url),
        self.assertEqual(self.browser.current_url, zone_url,
                         "Expect link to go to zone management page")

        self.browser.find_element_by_css_selector(".zone-delete-link").click()
        self.browser.switch_to_alert().accept()
        self.browser_wait_for_no_element(".zone-delete-link")
        self.browser_check_django_message(message_type="success",
                                          contains="successfully deleted")
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".zone-delete-link"),
                None, "Make sure 'delete' link is gone.")

    def test_cancel_delete_zone_from_zone_admin(self):
        """Delete a zone from the org_management page"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        zone_url = self.browser.find_element_by_css_selector(
            ".zone-manage-link").get_attribute("href")
        self.browse_to(zone_url)
        self.assertEqual(self.browser.current_url, zone_url,
                         "Expect link to go to zone management page")

        self.browser.find_element_by_css_selector(".zone-delete-link").click()
        self.browser.switch_to_alert().dismiss()
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".zone-delete-link"),
            None, "Make sure 'delete' link still exists.")
        self.browser_check_django_message(num_messages=0)

    def test_cannot_delete_full_zone(self):
        # Save zone info, but without adding
        self.devicezone = DeviceZone(device=Device.get_own_device(),
                                     zone=self.zone)
        self.devicezone.save()

        # Check on the org management page
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".zone-delete-link"),
                None, "Make sure 'delete' link is gone.")

        # Follow the link, and confirm on the zone management page.
        zone_url = self.browser.find_element_by_css_selector(
            ".zone-manage-link").get_attribute("href")
        self.browse_to(zone_url)
        self.assertEqual(self.browser.current_url, zone_url,
                         "Expect link to go to zone management page")
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".zone-delete-link"),
                None, "Make sure 'delete' link is gone.")

    def test_issue_697(self):
        self.facility = Facility(name=self.FACILITY_NAME)
        self.facility.save()
        self.test_delete_zone_from_org_admin()
Example #21
0
 def test_issue_697(self):
     self.facility = Facility(name=self.FACILITY_NAME)
     self.facility.save()
     self.test_delete_zone_from_org_admin()
Example #22
0
    def test_unicode_string(self):
        # Dependencies
        dev = Device.get_own_device()
        self.assertNotIn(unicode(dev), "Bad Unicode data",
                         "Device: Bad conversion to unicode.")

        fac = Facility(name=self.korean_string)
        fac.save()
        self.assertNotIn(unicode(fac), "Bad Unicode data",
                         "Facility: Bad conversion to unicode.")

        fg = FacilityGroup(facility=fac, name=self.korean_string)
        fg.save()
        self.assertNotIn(unicode(fg), "Bad Unicode data",
                         "FacilityGroup: Bad conversion to unicode.")

        user = FacilityUser(
            facility=fac,
            group=fg,
            first_name=self.korean_string,
            last_name=self.korean_string,
            username=self.korean_string,
            notes=self.korean_string,
        )
        user.set_password(self.korean_string *
                          settings.PASSWORD_CONSTRAINTS["min_length"])
        user.save()
        self.assertNotIn(unicode(user), "Bad Unicode data",
                         "FacilityUser: Bad conversion to unicode.")

        known_classes = [ExerciseLog, UserLog, UserLogSummary, VideoLog]

        #
        elog = ExerciseLog(user=user, exercise_id=self.korean_string)
        self.assertNotIn(
            unicode(elog), "Bad Unicode data",
            "ExerciseLog: Bad conversion to unicode (before saving).")
        elog.save()
        self.assertNotIn(
            unicode(elog), "Bad Unicode data",
            "ExerciseLog: Bad conversion to unicode (after saving).")

        vlog = VideoLog(user=user,
                        video_id=self.korean_string,
                        youtube_id=self.korean_string)
        self.assertNotIn(
            unicode(vlog), "Bad Unicode data",
            "VideoLog: Bad conversion to unicode (before saving).")
        vlog.save()
        self.assertNotIn(
            unicode(vlog), "Bad Unicode data",
            "VideoLog: Bad conversion to unicode (after saving).")

        ulog = UserLog(user=user)
        self.assertNotIn(unicode(ulog), "Bad Unicode data",
                         "UserLog: Bad conversion to unicode.")

        ulogsum = UserLogSummary(
            user=user,
            device=dev,
            activity_type=1,
            start_datetime=datetime.now(),
            end_datetime=datetime.now(),
        )
        self.assertNotIn(unicode(ulogsum), "Bad Unicode data",
                         "UserLogSummary: Bad conversion to unicode.")
Example #23
0
class TestSaveVideoLog(KALiteTestCase):

    ORIGINAL_POINTS = 84
    ORIGINAL_SECONDS_WATCHED = 32
    NEW_POINTS = 32
    NEW_SECONDS_WATCHED = 15
    YOUTUBE_ID = "aNqG4ChKShI"
    VIDEO_ID = i18n.get_video_id(YOUTUBE_ID) or "dummy"
    YOUTUBE_ID2 = "b22tMEc6Kko"
    VIDEO_ID2 = i18n.get_video_id(YOUTUBE_ID2) or "dummy2"
    USERNAME = "******"
    PASSWORD = "******"

    def setUp(self):
        super(TestSaveVideoLog, self).setUp()
        # create a facility and user that can be referred to in models across tests
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.USERNAME,
                                 facility=self.facility)
        self.user.set_password(self.PASSWORD)
        self.user.save()

        # create an initial VideoLog instance so we have something to update later
        self.original_videolog = VideoLog(video_id=self.VIDEO_ID,
                                          youtube_id=self.YOUTUBE_ID,
                                          user=self.user)
        self.original_videolog.points = self.ORIGINAL_POINTS
        self.original_videolog.total_seconds_watched = self.ORIGINAL_SECONDS_WATCHED
        self.original_videolog.save()

    def test_new_videolog(self):

        # make sure the target video log does not already exist
        videologs = VideoLog.objects.filter(video_id=self.VIDEO_ID2,
                                            user__username=self.USERNAME)
        self.assertEqual(
            videologs.count(), 0,
            "The target video log to be newly created already exists")

        c = KALiteClient()

        # login
        success = c.login(username=self.USERNAME,
                          password=self.PASSWORD,
                          facility=self.facility.id)
        self.assertTrue(success, "Was not able to login as the test user")

        # save a new video log
        result = c.save_video_log(
            video_id=self.VIDEO_ID2,
            youtube_id=self.YOUTUBE_ID2,
            total_seconds_watched=self.ORIGINAL_SECONDS_WATCHED,
            points=self.NEW_POINTS,
        )
        self.assertEqual(
            result.status_code, 200,
            "An error (%d) was thrown while saving the video log." %
            result.status_code)

        # get a reference to the newly created VideoLog
        videolog = VideoLog.objects.get(video_id=self.VIDEO_ID2,
                                        user__username=self.USERNAME)

        # make sure the VideoLog was properly created
        self.assertEqual(videolog.points, self.NEW_POINTS,
                         "The VideoLog's points were not saved correctly.")
        self.assertEqual(
            videolog.total_seconds_watched, self.ORIGINAL_SECONDS_WATCHED,
            "The VideoLog's seconds watched was not saved correctly.")

    def test_update_videolog(self):

        # get a new reference to the existing VideoLog
        videolog = VideoLog.objects.get(id=self.original_videolog.id)

        # make sure the VideoLog hasn't already been changed
        self.assertEqual(videolog.points, self.ORIGINAL_POINTS,
                         "The VideoLog's points have already changed.")
        self.assertEqual(videolog.total_seconds_watched,
                         self.ORIGINAL_SECONDS_WATCHED,
                         "The VideoLog's seconds watched already changed.")

        c = KALiteClient()

        # login
        success = c.login(username=self.USERNAME,
                          password=self.PASSWORD,
                          facility=self.facility.id)
        self.assertTrue(success, "Was not able to login as the test user")

        # save a new record onto the video log, with a correct answer (increasing the points and streak)
        result = c.save_video_log(
            video_id=self.VIDEO_ID,
            youtube_id=self.YOUTUBE_ID,
            total_seconds_watched=self.ORIGINAL_SECONDS_WATCHED +
            self.NEW_SECONDS_WATCHED,
            points=self.ORIGINAL_POINTS + self.NEW_POINTS,
        )
        self.assertEqual(
            result.status_code, 200,
            "An error (%d) was thrown while saving the video log." %
            result.status_code)

        # get a reference to the updated VideoLog
        videolog = VideoLog.objects.get(video_id=self.VIDEO_ID,
                                        user__username=self.USERNAME)

        # make sure the VideoLog was properly updated
        self.assertEqual(videolog.points,
                         self.ORIGINAL_POINTS + self.NEW_POINTS,
                         "The VideoLog's points were not updated correctly.")
        self.assertEqual(
            videolog.total_seconds_watched,
            self.ORIGINAL_SECONDS_WATCHED + self.NEW_SECONDS_WATCHED,
            "The VideoLog's seconds watched was not updated correctly.")
Example #24
0
class TestSaveVideoLog(KALiteTestCase):

    ORIGINAL_POINTS = 84
    ORIGINAL_SECONDS_WATCHED = 32
    NEW_POINTS = 32
    NEW_SECONDS_WATCHED = 15
    YOUTUBE_ID = "aNqG4ChKShI"
    VIDEO_ID = i18n.get_video_id(YOUTUBE_ID) or "dummy"
    YOUTUBE_ID2 = "b22tMEc6Kko"
    VIDEO_ID2 = i18n.get_video_id(YOUTUBE_ID2) or "dummy2"
    USERNAME = "******"
    PASSWORD = "******"

    def setUp(self):
        super(TestSaveVideoLog, self).setUp()
        # create a facility and user that can be referred to in models across tests
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.USERNAME, facility=self.facility)
        self.user.set_password(self.PASSWORD)
        self.user.save()

        # create an initial VideoLog instance so we have something to update later
        self.original_videolog = VideoLog(video_id=self.VIDEO_ID, youtube_id=self.YOUTUBE_ID, user=self.user)
        self.original_videolog.points = self.ORIGINAL_POINTS
        self.original_videolog.total_seconds_watched = self.ORIGINAL_SECONDS_WATCHED
        self.original_videolog.save()

    def test_new_videolog(self):

        # make sure the target video log does not already exist
        videologs = VideoLog.objects.filter(video_id=self.VIDEO_ID2, user__username=self.USERNAME)
        self.assertEqual(videologs.count(), 0, "The target video log to be newly created already exists")

        c = KALiteClient()

        # login
        success = c.login(username=self.USERNAME, password=self.PASSWORD, facility=self.facility.id)
        self.assertTrue(success, "Was not able to login as the test user")

        # save a new video log
        result = c.save_video_log(
            video_id=self.VIDEO_ID2,
            youtube_id=self.YOUTUBE_ID2,
            total_seconds_watched=self.ORIGINAL_SECONDS_WATCHED,
            points=self.NEW_POINTS,
        )
        self.assertEqual(result.status_code, 200, "An error (%d) was thrown while saving the video log." % result.status_code)

        # get a reference to the newly created VideoLog
        videolog = VideoLog.objects.get(video_id=self.VIDEO_ID2, user__username=self.USERNAME)

        # make sure the VideoLog was properly created
        self.assertEqual(videolog.points, self.NEW_POINTS, "The VideoLog's points were not saved correctly.")
        self.assertEqual(videolog.total_seconds_watched, self.ORIGINAL_SECONDS_WATCHED, "The VideoLog's seconds watched was not saved correctly.")

    def test_update_videolog(self):

        # get a new reference to the existing VideoLog
        videolog = VideoLog.objects.get(id=self.original_videolog.id)

        # make sure the VideoLog hasn't already been changed
        self.assertEqual(videolog.points, self.ORIGINAL_POINTS, "The VideoLog's points have already changed.")
        self.assertEqual(videolog.total_seconds_watched, self.ORIGINAL_SECONDS_WATCHED, "The VideoLog's seconds watched already changed.")

        c = KALiteClient()

        # login
        success = c.login(username=self.USERNAME, password=self.PASSWORD, facility=self.facility.id)
        self.assertTrue(success, "Was not able to login as the test user")

        # save a new record onto the video log, with a correct answer (increasing the points and streak)
        result = c.save_video_log(
            video_id=self.VIDEO_ID,
            youtube_id=self.YOUTUBE_ID,
            total_seconds_watched=self.ORIGINAL_SECONDS_WATCHED + self.NEW_SECONDS_WATCHED,
            points=self.ORIGINAL_POINTS + self.NEW_POINTS,
        )
        self.assertEqual(result.status_code, 200, "An error (%d) was thrown while saving the video log." % result.status_code)

        # get a reference to the updated VideoLog
        videolog = VideoLog.objects.get(video_id=self.VIDEO_ID, user__username=self.USERNAME)

        # make sure the VideoLog was properly updated
        self.assertEqual(videolog.points, self.ORIGINAL_POINTS + self.NEW_POINTS, "The VideoLog's points were not updated correctly.")
        self.assertEqual(videolog.total_seconds_watched, self.ORIGINAL_SECONDS_WATCHED + self.NEW_SECONDS_WATCHED, "The VideoLog's seconds watched was not updated correctly.")
Example #25
0
class TestSaveExerciseLog(KALiteTestCase):

    ORIGINAL_POINTS = 37
    ORIGINAL_ATTEMPTS = 3
    ORIGINAL_STREAK_PROGRESS = 20
    NEW_POINTS_LARGER = 22
    NEW_ATTEMPTS = 5
    NEW_STREAK_PROGRESS_LARGER = 10
    NEW_POINTS_SMALLER = 0
    NEW_STREAK_PROGRESS_SMALLER = 0
    EXERCISE_ID = "number_line"
    EXERCISE_ID2 = "radius_diameter_and_circumference"
    USERNAME = "******"
    PASSWORD = "******"

    def setUp(self):
        super(TestSaveExerciseLog, self).setUp()

        # create a facility and user that can be referred to in models across tests
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.USERNAME, facility=self.facility)
        self.user.set_password(self.PASSWORD)
        self.user.save()

        # create an initial ExerciseLog instance so we have something to update later
        self.original_exerciselog = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user)
        self.original_exerciselog.points = self.ORIGINAL_POINTS
        self.original_exerciselog.attempts = self.ORIGINAL_ATTEMPTS
        self.original_exerciselog.streak_progress = self.ORIGINAL_STREAK_PROGRESS
        self.original_exerciselog.save()

    def test_new_exerciselog(self):

        # make sure the target exercise log does not already exist
        exerciselogs = ExerciseLog.objects.filter(exercise_id=self.EXERCISE_ID2, user__username=self.USERNAME)
        self.assertEqual(exerciselogs.count(), 0, "The target exercise log to be newly created already exists")

        c = KALiteClient()

        # login
        success = c.login(username=self.USERNAME, password=self.PASSWORD, facility=self.facility.id)
        self.assertTrue(success, "Was not able to login as the test user")

        # save a new exercise log
        result = c.save_exercise_log(
            exercise_id=self.EXERCISE_ID2,
            streak_progress=self.NEW_STREAK_PROGRESS_LARGER,
            points=self.NEW_POINTS_LARGER,
            correct=True,
            attempts=self.NEW_ATTEMPTS,
        )
        self.assertEqual(result.status_code, 200, "An error (%d) was thrown while saving the exercise log." % result.status_code)

        # get a reference to the newly created ExerciseLog
        exerciselog = ExerciseLog.objects.get(exercise_id=self.EXERCISE_ID2, user__username=self.USERNAME)

        # make sure the ExerciseLog was properly created
        self.assertEqual(exerciselog.points, self.NEW_POINTS_LARGER, "The ExerciseLog's points were not saved correctly.")
        self.assertEqual(exerciselog.streak_progress, self.NEW_STREAK_PROGRESS_LARGER, "The ExerciseLog's streak progress was not saved correctly.")
        self.assertEqual(exerciselog.attempts, self.NEW_ATTEMPTS, "The ExerciseLog did not have the correct number of attempts (%d)." % self.NEW_ATTEMPTS)

    def test_update_exerciselog(self):

        # get a new reference to the existing ExerciseLog
        exerciselog = ExerciseLog.objects.get(id=self.original_exerciselog.id)

        # make sure the ExerciseLog hasn't already been changed
        self.assertEqual(exerciselog.points, self.ORIGINAL_POINTS, "The ExerciseLog's points have already changed.")
        self.assertEqual(exerciselog.streak_progress, self.ORIGINAL_STREAK_PROGRESS, "The ExerciseLog's streak progress already changed.")
        self.assertEqual(exerciselog.attempts, self.ORIGINAL_ATTEMPTS, "The ExerciseLog's attempts have already changed.")

        c = KALiteClient()

        # login
        success = c.login(username=self.USERNAME, password=self.PASSWORD, facility=self.facility.id)
        self.assertTrue(success, "Was not able to login as the test user")

        # save a new record onto the exercise log, with a correct answer (increasing the points and streak)
        result = c.save_exercise_log(
            exercise_id=self.EXERCISE_ID,
            streak_progress=self.NEW_STREAK_PROGRESS_LARGER,
            points=self.NEW_POINTS_LARGER,
            correct=True,
            attempts=self.NEW_ATTEMPTS,
        )
        self.assertEqual(result.status_code, 200, "An error (%d) was thrown while saving the exercise log." % result.status_code)

        # get a reference to the updated ExerciseLog
        exerciselog = ExerciseLog.objects.get(exercise_id=self.EXERCISE_ID, user__username=self.USERNAME)

        # make sure the ExerciseLog was properly updated
        self.assertEqual(exerciselog.points, self.NEW_POINTS_LARGER, "The ExerciseLog's points were not updated correctly.")
        self.assertEqual(exerciselog.streak_progress, self.NEW_STREAK_PROGRESS_LARGER, "The ExerciseLog's streak progress was not updated correctly.")
        self.assertEqual(exerciselog.attempts, self.NEW_ATTEMPTS, "The ExerciseLog did not have the correct number of attempts (%d)." % self.NEW_ATTEMPTS)

        # save a new record onto the exercise log, with an incorrect answer (decreasing the points and streak)
        result = c.save_exercise_log(
            exercise_id=self.EXERCISE_ID,
            streak_progress=self.NEW_STREAK_PROGRESS_SMALLER,
            points=self.NEW_POINTS_SMALLER,
            correct=False,
            attempts=self.NEW_ATTEMPTS + 1,
        )
        self.assertEqual(result.status_code, 200, "An error (%d) was thrown while saving the exercise log." % result.status_code)

        # get a reference to the updated ExerciseLog
        exerciselog = ExerciseLog.objects.get(exercise_id=self.EXERCISE_ID, user__username=self.USERNAME)

        # make sure the ExerciseLog was properly updated
        self.assertEqual(exerciselog.points, self.NEW_POINTS_SMALLER, "The ExerciseLog's points were not saved correctly.")
        self.assertEqual(exerciselog.streak_progress, self.NEW_STREAK_PROGRESS_SMALLER, "The ExerciseLog's streak progress was not saved correctly.")
        self.assertEqual(exerciselog.attempts, self.NEW_ATTEMPTS + 1, "The ExerciseLog did not have the correct number of attempts.")
class ZoneDeletionTestCase(OrganizationManagementTestCase):
    def setUp(self):
        super(ZoneDeletionTestCase, self).setUp()
        self.zone = Zone(name=self.ZONE_NAME)
        self.zone.save()
        self.org.add_zone(self.zone)
        self.org.save()

    def test_delete_zone_from_org_admin(self):
        """Delete a zone from the org_management page"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        self.browser.find_element_by_css_selector(".zone-delete-link").click()
        self.browser.switch_to_alert().accept()
        self.browser_wait_for_no_element(".zone-delete-link")
        self.browser_check_django_message(message_type="success", contains="successfully deleted")
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".zone-delete-link"), None, "Make sure 'delete' link is gone."
            )

    def test_cancel_delete_zone_from_org_admin(self):
        """Delete a zone from the org_management page"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        self.browser.find_element_by_css_selector(".zone-delete-link").click()
        self.browser.switch_to_alert().dismiss()
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".zone-delete-link"),
            None,
            "Make sure 'delete' link still exists.",
        )
        self.browser_check_django_message(num_messages=0)

    def test_delete_zone_from_zone_admin(self):
        """Delete a zone from the org_management page"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        zone_url = self.browser.find_element_by_css_selector(".zone-manage-link").get_attribute("href")
        self.browse_to(zone_url),
        self.assertEqual(self.browser.current_url, zone_url, "Expect link to go to zone management page")

        self.browser.find_element_by_css_selector(".zone-delete-link").click()
        self.browser.switch_to_alert().accept()
        self.browser_wait_for_no_element(".zone-delete-link")
        self.browser_check_django_message(message_type="success", contains="successfully deleted")
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".zone-delete-link"), None, "Make sure 'delete' link is gone."
            )

    def test_cancel_delete_zone_from_zone_admin(self):
        """Delete a zone from the org_management page"""
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        zone_url = self.browser.find_element_by_css_selector(".zone-manage-link").get_attribute("href")
        self.browse_to(zone_url)
        self.assertEqual(self.browser.current_url, zone_url, "Expect link to go to zone management page")

        self.browser.find_element_by_css_selector(".zone-delete-link").click()
        self.browser.switch_to_alert().dismiss()
        self.assertNotEqual(
            self.browser.find_element_by_css_selector(".zone-delete-link"),
            None,
            "Make sure 'delete' link still exists.",
        )
        self.browser_check_django_message(num_messages=0)

    def test_cannot_delete_full_zone(self):
        # Save zone info, but without adding
        self.devicezone = DeviceZone(device=Device.get_own_device(), zone=self.zone)
        self.devicezone.save()

        # Check on the org management page
        self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".zone-delete-link"), None, "Make sure 'delete' link is gone."
            )

        # Follow the link, and confirm on the zone management page.
        zone_url = self.browser.find_element_by_css_selector(".zone-manage-link").get_attribute("href")
        self.browse_to(zone_url)
        self.assertEqual(self.browser.current_url, zone_url, "Expect link to go to zone management page")
        with self.assertRaises(NoSuchElementException):
            self.assertEqual(
                self.browser.find_element_by_css_selector(".zone-delete-link"), None, "Make sure 'delete' link is gone."
            )

    def test_issue_697(self):
        self.facility = Facility(name=self.FACILITY_NAME)
        self.facility.save()
        self.test_delete_zone_from_org_admin()
 def test_issue_697(self):
     self.facility = Facility(name=self.FACILITY_NAME)
     self.facility.save()
     self.test_delete_zone_from_org_admin()
Example #28
0
class TestSaveExerciseLog(KALiteTestCase):

    ORIGINAL_POINTS = 37
    ORIGINAL_ATTEMPTS = 3
    ORIGINAL_STREAK_PROGRESS = 20
    NEW_POINTS_LARGER = 22
    NEW_ATTEMPTS = 5
    NEW_STREAK_PROGRESS_LARGER = 10
    NEW_POINTS_SMALLER = 0
    NEW_STREAK_PROGRESS_SMALLER = 0
    EXERCISE_ID = "number_line"
    EXERCISE_ID2 = "radius_diameter_and_circumference"
    USERNAME = "******"
    PASSWORD = "******"

    def setUp(self):
        super(TestSaveExerciseLog, self).setUp()

        # create a facility and user that can be referred to in models across tests
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.USERNAME,
                                 facility=self.facility)
        self.user.set_password(self.PASSWORD)
        self.user.save()

        # create an initial ExerciseLog instance so we have something to update later
        self.original_exerciselog = ExerciseLog(exercise_id=self.EXERCISE_ID,
                                                user=self.user)
        self.original_exerciselog.points = self.ORIGINAL_POINTS
        self.original_exerciselog.attempts = self.ORIGINAL_ATTEMPTS
        self.original_exerciselog.streak_progress = self.ORIGINAL_STREAK_PROGRESS
        self.original_exerciselog.save()

    def test_new_exerciselog(self):

        # make sure the target exercise log does not already exist
        exerciselogs = ExerciseLog.objects.filter(
            exercise_id=self.EXERCISE_ID2, user__username=self.USERNAME)
        self.assertEqual(
            exerciselogs.count(), 0,
            "The target exercise log to be newly created already exists")

        c = KALiteClient()

        # login
        success = c.login(username=self.USERNAME,
                          password=self.PASSWORD,
                          facility=self.facility.id)
        self.assertTrue(success, "Was not able to login as the test user")

        # save a new exercise log
        result = c.save_exercise_log(
            exercise_id=self.EXERCISE_ID2,
            streak_progress=self.NEW_STREAK_PROGRESS_LARGER,
            points=self.NEW_POINTS_LARGER,
            correct=True,
            attempts=self.NEW_ATTEMPTS,
        )
        self.assertEqual(
            result.status_code, 200,
            "An error (%d) was thrown while saving the exercise log." %
            result.status_code)

        # get a reference to the newly created ExerciseLog
        exerciselog = ExerciseLog.objects.get(exercise_id=self.EXERCISE_ID2,
                                              user__username=self.USERNAME)

        # make sure the ExerciseLog was properly created
        self.assertEqual(exerciselog.points, self.NEW_POINTS_LARGER,
                         "The ExerciseLog's points were not saved correctly.")
        self.assertEqual(
            exerciselog.streak_progress, self.NEW_STREAK_PROGRESS_LARGER,
            "The ExerciseLog's streak progress was not saved correctly.")
        self.assertEqual(
            exerciselog.attempts, self.NEW_ATTEMPTS,
            "The ExerciseLog did not have the correct number of attempts (%d)."
            % self.NEW_ATTEMPTS)

    def test_update_exerciselog(self):

        # get a new reference to the existing ExerciseLog
        exerciselog = ExerciseLog.objects.get(id=self.original_exerciselog.id)

        # make sure the ExerciseLog hasn't already been changed
        self.assertEqual(exerciselog.points, self.ORIGINAL_POINTS,
                         "The ExerciseLog's points have already changed.")
        self.assertEqual(exerciselog.streak_progress,
                         self.ORIGINAL_STREAK_PROGRESS,
                         "The ExerciseLog's streak progress already changed.")
        self.assertEqual(exerciselog.attempts, self.ORIGINAL_ATTEMPTS,
                         "The ExerciseLog's attempts have already changed.")

        c = KALiteClient()

        # login
        success = c.login(username=self.USERNAME,
                          password=self.PASSWORD,
                          facility=self.facility.id)
        self.assertTrue(success, "Was not able to login as the test user")

        # save a new record onto the exercise log, with a correct answer (increasing the points and streak)
        result = c.save_exercise_log(
            exercise_id=self.EXERCISE_ID,
            streak_progress=self.NEW_STREAK_PROGRESS_LARGER,
            points=self.NEW_POINTS_LARGER,
            correct=True,
            attempts=self.NEW_ATTEMPTS,
        )
        self.assertEqual(
            result.status_code, 200,
            "An error (%d) was thrown while saving the exercise log." %
            result.status_code)

        # get a reference to the updated ExerciseLog
        exerciselog = ExerciseLog.objects.get(exercise_id=self.EXERCISE_ID,
                                              user__username=self.USERNAME)

        # make sure the ExerciseLog was properly updated
        self.assertEqual(
            exerciselog.points, self.NEW_POINTS_LARGER,
            "The ExerciseLog's points were not updated correctly.")
        self.assertEqual(
            exerciselog.streak_progress, self.NEW_STREAK_PROGRESS_LARGER,
            "The ExerciseLog's streak progress was not updated correctly.")
        self.assertEqual(
            exerciselog.attempts, self.NEW_ATTEMPTS,
            "The ExerciseLog did not have the correct number of attempts (%d)."
            % self.NEW_ATTEMPTS)

        # save a new record onto the exercise log, with an incorrect answer (decreasing the points and streak)
        result = c.save_exercise_log(
            exercise_id=self.EXERCISE_ID,
            streak_progress=self.NEW_STREAK_PROGRESS_SMALLER,
            points=self.NEW_POINTS_SMALLER,
            correct=False,
            attempts=self.NEW_ATTEMPTS + 1,
        )
        self.assertEqual(
            result.status_code, 200,
            "An error (%d) was thrown while saving the exercise log." %
            result.status_code)

        # get a reference to the updated ExerciseLog
        exerciselog = ExerciseLog.objects.get(exercise_id=self.EXERCISE_ID,
                                              user__username=self.USERNAME)

        # make sure the ExerciseLog was properly updated
        self.assertEqual(exerciselog.points, self.NEW_POINTS_SMALLER,
                         "The ExerciseLog's points were not saved correctly.")
        self.assertEqual(
            exerciselog.streak_progress, self.NEW_STREAK_PROGRESS_SMALLER,
            "The ExerciseLog's streak progress was not saved correctly.")
        self.assertEqual(
            exerciselog.attempts, self.NEW_ATTEMPTS + 1,
            "The ExerciseLog did not have the correct number of attempts.")