Exemple #1
0
    def test_finished_new_keycard_scan_timed_out(self):
        """ Longer than x minutes to scan new card -- timed out """
        t_info(
            'Creating NewKeycardScan object; setting creation '
            'time to 1 sec more than the time-out time......', 3)
        new_nks_obj = NewKeycardScan.objects.create(
            rfid='1111111111', assigner_user_id=self.staff_only_user.pk)
        min_till_timeout = 2.0
        time_delta = timedelta(minutes=min_till_timeout, seconds=1)
        fake_time_initiated = (datetime.datetime.now() - time_delta)
        new_nks_obj.time_initiated = fake_time_initiated
        new_nks_obj.save()

        t_info('Getting response..........', 3)
        response = self.client.get('/done_scan/%d/' % new_nks_obj.pk)

        t_info('Check response status code', 4)
        self.assertEqual(response.status_code, 200)

        t_info('Check response content type', 4)
        self.assertEqual(response['content-type'], 'application/json')

        t_info('Check response content', 4)
        self.assertEqual(simplejson.loads(response.content)['success'], False)
        # self.assertEqual(simplejson.loads(response.content)['error_mess'],
        # 'Sorry, the system timed out. You have %d minutes to scan the card,
        # then hit 'Done.' '  % default_timeout_minutes)
        self.assertEqual(
            simplejson.loads(response.content)['error_mess'],
            'Sorry, the system timed out. You have {} minutes to scan the card, '
            'then hit "Done." '.format(min_till_timeout))
    def setUp(self):
        t_info("LiveServerTestCase CreateLockUserAssignKeycardWalkthrough", 1)
        t_info(self._testMethodName, 2)

        # Set up browser and mouse
        self.browser = webdriver.Firefox()
        # self.mouse = ActionChains(self.browser)
        # tells webdriver to use a max timeout of 3 seconds
        self.browser.implicitly_wait(3)

        # Create dir for screenshots (archive existing)
        if SCREENSHOTS:
            self.screenshots_dir = self._testMethodName + '___screenshots'
            # just create new directories in os x (note)
            if os.path.exists(self.screenshots_dir):
                # os.rename(self.screenshots_dir,
                # "archive___"+self.screenshots_dir)
                try:
                    if os.path.isdir(self.screenshots_dir):
                        # delete folder
                        shutil.rmtree(self.screenshots_dir)
                    else:
                        # delete file
                        os.remove(self.screenshots_dir)
                except:
                    print("Exception: ", str(sys.exc_info()))
            else:
                print("not found: ", self.screenshots_dir)
            os.makedirs(self.screenshots_dir)
    def test_finished_new_keycard_scan_timed_out(self):
        """ Longer than x minutes to scan new card -- timed out """
        t_info("Creating NewKeycardScan object; setting creation " "time to 1 sec more than the time-out time......", 3)
        new_nks_obj = NewKeycardScan.objects.create(rfid="1111111111", assigner_user_id=self.staff_only_user.pk)
        min_till_timeout = 2.0
        time_delta = timedelta(minutes=min_till_timeout, seconds=1)
        fake_time_initiated = datetime.datetime.now() - time_delta
        new_nks_obj.time_initiated = fake_time_initiated
        new_nks_obj.save()

        t_info("Getting response..........", 3)
        response = self.client.get("/done_scan/%d/" % new_nks_obj.pk)

        t_info("Check response status code", 4)
        self.assertEqual(response.status_code, 200)

        t_info("Check response content type", 4)
        self.assertEqual(response["content-type"], "application/json")

        t_info("Check response content", 4)
        self.assertEqual(simplejson.loads(response.content)["success"], False)
        # self.assertEqual(simplejson.loads(response.content)['error_mess'],
        # 'Sorry, the system timed out. You have %d minutes to scan the card,
        # then hit 'Done.' '  % default_timeout_minutes)
        self.assertEqual(
            simplejson.loads(response.content)["error_mess"],
            "Sorry, the system timed out. You have {} minutes to scan the card, "
            'then hit "Done." '.format(min_till_timeout),
        )
    def test_custom_save_assign_keycard(self):
        """
        Check that custom save assigns (creates and saves) new RFIDkeycard for
        this LockUser
        """
        # need LockUser, NewKeycardScan with ready_to_assign=True (and its
        # assigner User)
        lu = LockUser.objects.create(
            first_name='Jane', last_name='Doe', email='*****@*****.**')
        t_info("Creating staff user doing this......", 3)
        staff_only_user = User.objects.create_user(
            'johnny_staff', '*****@*****.**', 'my_password')
        new_nks_obj = NewKeycardScan.objects.create(
            rfid='abcdefghij', assigner_user=staff_only_user,
            ready_to_assign=True)
        num_rk_before = len(RFIDkeycard.objects.all())
        lu.save()

        # refetch the NewKeycardScan object
        new_nks_obj = NewKeycardScan.objects.get(pk=new_nks_obj.pk)

        # check that the NewKeycardScan object's ready_to_assign is now False
        self.assertFalse(new_nks_obj.ready_to_assign)

        # check that a new RFIDkeycard has been created:  make sure there is
        # one more RFIDkeycard object now
        self.assertEqual(num_rk_before + 1, len(RFIDkeycard.objects.all()))

        # check that the new keycard has the right attributes
        new_rk = RFIDkeycard.objects.latest("date_created")
        self.assertEqual(new_rk.lockuser, lu)
        self.assertEqual(new_rk.the_rfid, new_nks_obj.rfid)
        self.assertEqual(new_rk.assigner, new_nks_obj.assigner_user)
    def setUp(self):
        t_info("LiveServerTestCase CreateLockUserAssignKeycardWalkthrough", 1)
        t_info(self._testMethodName, 2)

        # Set up browser and mouse
        self.browser = webdriver.Firefox()
        # self.mouse = ActionChains(self.browser)
        # tells webdriver to use a max timeout of 3 seconds
        self.browser.implicitly_wait(3)

        # Create dir for screenshots (archive existing)
        if SCREENSHOTS:
            self.screenshots_dir = self._testMethodName + '___screenshots'
            # just create new directories in os x (note)
            if os.path.exists(self.screenshots_dir):
                # os.rename(self.screenshots_dir,
                # "archive___"+self.screenshots_dir)
                try:
                    if os.path.isdir(self.screenshots_dir):
                        # delete folder
                        shutil.rmtree(self.screenshots_dir)
                    else:
                        # delete file
                        os.remove(self.screenshots_dir)
                except:
                    print "Exception: ", str(sys.exc_info())
            else:
                print "not found: ", self.screenshots_dir
            os.makedirs(self.screenshots_dir)
    def setUp(self):
        """ Start up Selenium WebDriver browser instance """
        t_info("LiveServerTestCase LogIn", 1)
        t_info(self._testMethodName + ": " + self._testMethodDoc, 2)

        # set up browser
        self.browser = webdriver.Firefox()
        # tells webdriver to use a max timeout of 3 seconds
        self.browser.implicitly_wait(3)
    def test_access_time_change_list(self):
        """ """
        # Issue #y (client vs browser.get)
        t_info("Opening browser to get to room access log page......", 3)
        self.browser.get(self.live_server_url +
            '/lockadmin/rfid_lock_management/accesstime/')
        self.browser.maximize_window()

        t_info("logging in as staff user....", 3)
        client = Client()
        client.login(username='******', password='******')
        response = client.get("/lockadmin/rfid_lock_management/accesstime/")

        t_info("Are we on the change list for access times? Check "
               "template and title.", 4)
        self.assertTemplateUsed(response,
            'admin/rfid_lock_management/change_list.html')
        title = self.browser.find_element_by_tag_name('title')
        self.assertEqual(title.text,
            'Room access log | RFID Lock Administration')

        t_info("Does user see listed the doors they are allowed to manage in "
               "top navigation bar?", 4)
        # in pk order
        navbar_doors = "Doors you manage: Community Theater, Seminar Room"
        base_page_body = self.browser.find_element_by_tag_name('body')
        self.assertIn(navbar_doors, base_page_body.text)
    def setUp(self):
        t_info("TestCase NewKeycardScanTests", 1)
        t_info(self._testMethodName + ": " + self._testMethodDoc, 2)
        self.client = Client()

        t_info("Creating staff user doing this......", 3)
        self.staff_only_user = User.objects.create_user("johnny_staff", "*****@*****.**", "my_password")

        t_info("logging in as staff user....", 3)
        self.client.login(username="******", password="******")
    def test_finished_new_keycard_scan_obj_does_not_have_rfid(self):
        """ NewKeycardScan object did not get an RFID num """
        t_info("Creating new NewKeycardScan object we should have at this point", 3)
        new_nks_obj = NewKeycardScan.objects.create(assigner_user_id=self.staff_only_user.pk)

        t_info("...and it does not have an rfid", 4)
        self.assertFalse(new_nks_obj.rfid)
        response = self.client.get("/done_scan/%d/" % new_nks_obj.pk)

        t_info("Check response status code", 4)
        self.assertEqual(response.status_code, 200)

        t_info("Check response content type", 4)
        self.assertEqual(response["content-type"], "application/json")

        t_info("Check response content", 4)
        self.assertEqual(simplejson.loads(response.content)["success"], False)
        self.assertEqual(simplejson.loads(response.content)["error_mess"], "NewKeycardScan does not have RFID.")
Exemple #10
0
    def setUp(self):
        t_info('TestCase NewKeycardScanTests', 1)
        t_info(self._testMethodName + ': ' + self._testMethodDoc, 2)
        self.client = Client()

        t_info('Creating staff user doing this......', 3)
        self.staff_only_user = User.objects.create_user(
            'johnny_staff', '*****@*****.**', 'my_password')

        t_info('logging in as staff user....', 3)
        self.client.login(username='******', password='******')
    def setUp(self):
        t_info("TestCase StaffUserTests", 1)
        t_info(self._testMethodName + ": " + self._testMethodDoc, 2)
        # Note: can also get additional information by setting  verbosity=2
        # with manage.py.

        t_info("Creating staff user......", 3)
        self.staff_only_user = User.objects.create_user("johnny_staff", "*****@*****.**", "my_password")

        t_info("logging in as staff user....", 3)
        self.client = Client()
        self.client.login(username="******", password="******")
Exemple #12
0
    def setUp(self):
        t_info("TestCase StaffUserTests", 1)
        t_info(self._testMethodName + ": " + self._testMethodDoc, 2)
        # Note: can also get additional information by setting  verbosity=2
        # with manage.py.

        t_info("Creating staff user......", 3)
        self.staff_only_user = User.objects.create_user(
            'johnny_staff', '*****@*****.**', 'my_password')

        t_info("logging in as staff user....", 3)
        self.client = Client()
        self.client.login(username='******', password='******')
    def test_finished_new_keycard_scan_no_keycardscan_obj_with_pk(self):
        """ No NewKeycardScan object with the pk specified in the URL """
        new_scan_pk = 1

        t_info("Check that there is no NewKeycardScan object with " "pk specified in the URL", 4)
        self.assertFalse(NewKeycardScan.objects.filter(pk=new_scan_pk))

        t_info("Getting response..........", 3)
        response = self.client.get("/done_scan/%d/" % new_scan_pk)

        t_info("Check response status code", 4)
        self.assertEqual(response.status_code, 200)

        t_info("Check response content type", 4)
        self.assertEqual(response["content-type"], "application/json")

        t_info("Check response content", 4)
        self.assertEqual(simplejson.loads(response.content)["success"], False)
        self.assertEqual(
            simplejson.loads(response.content)["error_mess"], "No NewKeycardScan obj with pk %d." % new_scan_pk
        )
    def test_get_object_type(self):
        """
        Test that get_object_type custom filter returns the object.
        """
        t_info("Correct content types for models?", 4)
        lu_ct = ContentType.objects.get(model__iexact=LockUser.__name__)
        self.assertEqual(custom_filters.get_object_type(lu_ct.pk), 
            LockUser.__name__.lower())

        rf_ct = ContentType.objects.get(model__iexact=RFIDkeycard.__name__)
        self.assertEqual(custom_filters.get_object_type(rf_ct.pk),
            RFIDkeycard.__name__.lower())

        door_ct = ContentType.objects.get(model__iexact=Door.__name__)
        self.assertEqual(custom_filters.get_object_type(door_ct.pk),
            Door.__name__.lower())

        # Obj pk that is greater than count of objects: result will have to be
        # None
        fake_pk = len(ContentType.objects.all())
        self.assertEqual(custom_filters.get_object_type(fake_pk + 1), None)
Exemple #15
0
    def test_get_object_type(self):
        """
        Test that get_object_type custom filter returns the object.
        """
        t_info("Correct content types for models?", 4)
        lu_ct = ContentType.objects.get(model__iexact=LockUser.__name__)
        self.assertEqual(custom_filters.get_object_type(lu_ct.pk),
                         LockUser.__name__.lower())

        rf_ct = ContentType.objects.get(model__iexact=RFIDkeycard.__name__)
        self.assertEqual(custom_filters.get_object_type(rf_ct.pk),
                         RFIDkeycard.__name__.lower())

        door_ct = ContentType.objects.get(model__iexact=Door.__name__)
        self.assertEqual(custom_filters.get_object_type(door_ct.pk),
                         Door.__name__.lower())

        # Obj pk that is greater than count of objects: result will have to be
        # None
        fake_pk = len(ContentType.objects.all())
        self.assertEqual(custom_filters.get_object_type(fake_pk + 1), None)
    def test_staff_only_user_can_only_see_doors_they_have_permission_for(self):
        """
        Check that staff users can only see the doors they are permitted to
        manage.
        """
        t_info("Assign permissions (only superuser should be able to)...", 3)
        perm_codename = "some_permission_x"
        perm_name = "Permission Number X"

        # Create the permission object
        content_type = ContentType.objects.get(app_label="rfid_lock_management", model="lockuser")
        perm = Permission.objects.create(codename=perm_codename, name=perm_name, content_type=content_type)

        t_info("Testing whether user has permission already (should not)", 4)
        self.assertFalse(self.staff_only_user.has_perm(perm_codename))

        # Now add the permission
        self.staff_only_user.user_permissions.add(perm)
        # Django does cache user permissions, so refetch user from the database
        # (http://stackoverflow.com/a/10103291)
        # should now have the assigned permission
        self.staff_only_user = User.objects.get(pk=self.staff_only_user.pk)

        t_info("Testing whether user has the permission now", 4)
        # self.assertTrue(self.staff_only_user.has_perm(perm_codename),
        # self.staff_only_user.profile)
        self.assertTrue(self.staff_only_user.has_perm("rfid_lock_management." + perm_codename))
Exemple #17
0
    def test_chartify(self):
        """ Does chartify() return response with the correct(ly formatted) data
        for HighChart plot of access times?  """
        # login as staff user in fixture
        self.client.login(username='******', password='******')
        response = self.client.get('/chart/')
        #response.context['chart_data']

        t_info('Check response status code', 4)
        self.assertEqual(response.status_code, 200)

        t_info('Check response content type', 4)
        self.assertEqual(response['content-type'], 'text/html; charset=utf-8')

        # tooltip hardcoded in view as well
        tooltip = {'followPointer': 'false', 'pointFormat': '"{point.user}"'}
        all_doors_series = []
        for door in Door.objects.all():
            # get the data points for this door
            at_this_door = AccessTime.objects.filter(door=door)
            data_points_values_list = at_this_door.values_list('data_point')
            data = [simplejson.loads(dp[0]) for dp in data_points_values_list]
            # create door series
            door_series = {
                'name': '"%s"' % door.name,
                'data': data,
                'tooltip': tooltip
            }
            # append to list of all door series
            all_doors_series.append(door_series)

        t_info('Check response context for chart_type string', 4)
        # the one we're really interested in
        self.assertEqual(response.context['chart_data'],
                         simplejson.dumps(all_doors_series, indent=''))
Exemple #18
0
    def test_staff_only_user_can_only_see_doors_they_have_permission_for(self):
        """
        Check that staff users can only see the doors they are permitted to
        manage.
        """
        t_info("Assign permissions (only superuser should be able to)...", 3)
        perm_codename = "some_permission_x"
        perm_name = "Permission Number X"

        # Create the permission object
        content_type = ContentType.objects.get(
            app_label='rfid_lock_management', model='lockuser')
        perm = Permission.objects.create(codename=perm_codename,
                                         name=perm_name,
                                         content_type=content_type)

        t_info("Testing whether user has permission already (should not)", 4)
        self.assertFalse(self.staff_only_user.has_perm(perm_codename))

        # Now add the permission
        self.staff_only_user.user_permissions.add(perm)
        # Django does cache user permissions, so refetch user from the database
        # (http://stackoverflow.com/a/10103291)
        # should now have the assigned permission
        self.staff_only_user = User.objects.get(pk=self.staff_only_user.pk)

        t_info("Testing whether user has the permission now", 4)
        # self.assertTrue(self.staff_only_user.has_perm(perm_codename),
        # self.staff_only_user.profile)
        self.assertTrue(
            self.staff_only_user.has_perm('rfid_lock_management.' +
                                          perm_codename))
    def test_chartify(self):
        """ Does chartify() return response with the correct(ly formatted) data
        for HighChart plot of access times?  """
        # login as staff user in fixture
        self.client.login(username="******", password="******")
        response = self.client.get("/chart/")
        # response.context['chart_data']

        t_info("Check response status code", 4)
        self.assertEqual(response.status_code, 200)

        t_info("Check response content type", 4)
        self.assertEqual(response["content-type"], "text/html; charset=utf-8")

        # tooltip hardcoded in view as well
        tooltip = {"followPointer": "false", "pointFormat": '"{point.user}"'}
        all_doors_series = []
        for door in Door.objects.all():
            # get the data points for this door
            at_this_door = AccessTime.objects.filter(door=door)
            data_points_values_list = at_this_door.values_list("data_point")
            data = [simplejson.loads(dp[0]) for dp in data_points_values_list]
            # create door series
            door_series = {"name": '"%s"' % door.name, "data": data, "tooltip": tooltip}
            # append to list of all door series
            all_doors_series.append(door_series)

        t_info("Check response context for chart_type string", 4)
        # the one we're really interested in
        self.assertEqual(response.context["chart_data"], simplejson.dumps(all_doors_series, indent=""))
Exemple #20
0
    def test_creating_new_obj_and_saving_it_to_db(self):
        """
        Create new LockUser, set attributes, save to database
        """
        t_info("Can we create new LockUser; set attributes; save it?", 4)
        lockuser = LockUser()
        lockuser.first_name = "Homer"
        lockuser.last_name = "Simpson"
        lockuser.email = "*****@*****.**"
        lockuser.address = "742 Evergreen Terrace, Springfield, USA"
        lockuser.phone_number = "(939) 555-5555"
        lockuser.save()  # i.e., INSERT

        t_info("Can we find it in the database again?", 4)
        all_lockusers_in_db = LockUser.objects.all()
        self.assertEqual(len(all_lockusers_in_db), 1)
        the_only_lockuser_in_db = all_lockusers_in_db[0]
        self.assertEqual(the_only_lockuser_in_db, lockuser)

        t_info("Were the attributes saved?", 4)
        self.assertEqual(the_only_lockuser_in_db.first_name, "Homer")
        self.assertEqual(the_only_lockuser_in_db.last_name, "Simpson")
        self.assertEqual(the_only_lockuser_in_db.email,
                         "*****@*****.**")
        self.assertEqual(the_only_lockuser_in_db.address,
                         "742 Evergreen Terrace, Springfield, USA")
        self.assertEqual(the_only_lockuser_in_db.phone_number,
                         "(939) 555-5555")
    def test_creating_new_obj_and_saving_it_to_db(self):
        """
        Create new LockUser, set attributes, save to database
        """
        t_info("Can we create new LockUser; set attributes; save it?", 4)
        lockuser = LockUser()
        lockuser.first_name = "Homer"
        lockuser.last_name = "Simpson"
        lockuser.email = "*****@*****.**"
        lockuser.address = "742 Evergreen Terrace, Springfield, USA"
        lockuser.phone_number = "(939) 555-5555"
        lockuser.save()  # i.e., INSERT

        t_info("Can we find it in the database again?", 4)
        all_lockusers_in_db = LockUser.objects.all()
        self.assertEqual(len(all_lockusers_in_db), 1)
        the_only_lockuser_in_db = all_lockusers_in_db[0]
        self.assertEqual(the_only_lockuser_in_db, lockuser)

        t_info("Were the attributes saved?", 4)
        self.assertEqual(the_only_lockuser_in_db.first_name, "Homer")
        self.assertEqual(the_only_lockuser_in_db.last_name, "Simpson")
        self.assertEqual(the_only_lockuser_in_db.email, 
            "*****@*****.**")
        self.assertEqual(the_only_lockuser_in_db.address,
             "742 Evergreen Terrace, Springfield, USA")
        self.assertEqual(the_only_lockuser_in_db.phone_number, "(939) 555-5555")
Exemple #22
0
    def test_finished_new_keycard_scan_no_keycardscan_obj_with_pk(self):
        """ No NewKeycardScan object with the pk specified in the URL """
        new_scan_pk = 1

        t_info(
            'Check that there is no NewKeycardScan object with '
            'pk specified in the URL', 4)
        self.assertFalse(NewKeycardScan.objects.filter(pk=new_scan_pk))

        t_info('Getting response..........', 3)
        response = self.client.get('/done_scan/%d/' % new_scan_pk)

        t_info('Check response status code', 4)
        self.assertEqual(response.status_code, 200)

        t_info('Check response content type', 4)
        self.assertEqual(response['content-type'], 'application/json')

        t_info('Check response content', 4)
        self.assertEqual(simplejson.loads(response.content)['success'], False)
        self.assertEqual(
            simplejson.loads(response.content)['error_mess'],
            'No NewKeycardScan obj with pk %d.' % new_scan_pk)
Exemple #23
0
    def test_finished_new_keycard_scan_obj_does_not_have_rfid(self):
        """ NewKeycardScan object did not get an RFID num """
        t_info(
            'Creating new NewKeycardScan object we should have at this point',
            3)
        new_nks_obj = NewKeycardScan.objects.create(
            assigner_user_id=self.staff_only_user.pk)

        t_info('...and it does not have an rfid', 4)
        self.assertFalse(new_nks_obj.rfid)
        response = self.client.get('/done_scan/%d/' % new_nks_obj.pk)

        t_info('Check response status code', 4)
        self.assertEqual(response.status_code, 200)

        t_info('Check response content type', 4)
        self.assertEqual(response['content-type'], 'application/json')

        t_info('Check response content', 4)
        self.assertEqual(simplejson.loads(response.content)['success'], False)
        self.assertEqual(
            simplejson.loads(response.content)['error_mess'],
            'NewKeycardScan does not have RFID.')
Exemple #24
0
    def test_custom_save_assign_keycard(self):
        """
        Check that custom save assigns (creates and saves) new RFIDkeycard for
        this LockUser
        """
        # need LockUser, NewKeycardScan with ready_to_assign=True (and its
        # assigner User)
        lu = LockUser.objects.create(first_name='Jane',
                                     last_name='Doe',
                                     email='*****@*****.**')
        t_info("Creating staff user doing this......", 3)
        staff_only_user = User.objects.create_user('johnny_staff',
                                                   '*****@*****.**',
                                                   'my_password')
        new_nks_obj = NewKeycardScan.objects.create(
            rfid='abcdefghij',
            assigner_user=staff_only_user,
            ready_to_assign=True)
        num_rk_before = len(RFIDkeycard.objects.all())
        lu.save()

        # refetch the NewKeycardScan object
        new_nks_obj = NewKeycardScan.objects.get(pk=new_nks_obj.pk)

        # check that the NewKeycardScan object's ready_to_assign is now False
        self.assertFalse(new_nks_obj.ready_to_assign)

        # check that a new RFIDkeycard has been created:  make sure there is
        # one more RFIDkeycard object now
        self.assertEqual(num_rk_before + 1, len(RFIDkeycard.objects.all()))

        # check that the new keycard has the right attributes
        new_rk = RFIDkeycard.objects.latest("date_created")
        self.assertEqual(new_rk.lockuser, lu)
        self.assertEqual(new_rk.the_rfid, new_nks_obj.rfid)
        self.assertEqual(new_rk.assigner, new_nks_obj.assigner_user)
    def setUp(self):
        """ Start up Selenium WebDriver browser instance """
        t_info("LiveServerTestCase GeneralFunctionalTests", 1)
        t_info(self._testMethodName + ": " + self._testMethodDoc, 2)

        # set up browser
        self.browser = webdriver.Firefox()
        # tells webdriver to use a max timeout of 3 seconds
        self.browser.implicitly_wait(3)

        # open browser and log in
        t_info("Opening browser to get to lockuser's change_form (login first)...", 3)
        self.browser.get(self.live_server_url + '/lockadmin')
        self.browser.maximize_window()

        t_info("But login first..........", 3)
        username_field = self.browser.find_element_by_name('username')
        username_field.send_keys('moe')
        password_field = self.browser.find_element_by_name('password')
        password_field.send_keys('moe')
        password_field.send_keys(Keys.RETURN)
Exemple #26
0
    def test_deactivate(self):
        """
        On deactivation, is RFIDkeycard object's date revoked and revoker set
        correctly?
        """
        # create keycard and associated lockuser
        lu = LockUser.objects.create(first_name='Jane',
                                     last_name='Doe',
                                     email='*****@*****.**')
        staff_only_user = User.objects.create_user('johnny_staff',
                                                   '*****@*****.**',
                                                   'my_password')
        rk = RFIDkeycard.objects.create(the_rfid='abcde12345',
                                        lockuser=lu,
                                        assigner=staff_only_user)

        # need logged in user so we can assign the revoker
        self.client = Client()
        self.client.login(username='******', password='******')

        # Check that the time revoked is correct -- i.e. that it's now. But we
        # need to account for lag in time between setting the now variable and
        # executing deactivate (including the print statement). This can be
        # done with assertAlmostEqual(first, second, delta=None). This is my
        # approach to calculate the delta:
        #   - get the time at t1
        #   - RFIDkeycard.deactivate() at time t2=t1+x
        #   - assert for RFIDkeycard.date_revoked at time t3=t1+x+y
        #   - So deactivation happened AT MOST x+y microseconds ago,
        #     at time of assertion
        #   - So, setting delta to the time difference between t1 and t3,
        #     or x + y
        #   - i.e. now() minus t1
        t1 = datetime.datetime.now()
        t_info("Deactivating keycard......", 3)
        rk.deactivate(staff_only_user)

        t_info("Is the date revoked correct", 4)
        self.assertAlmostEqual(rk.date_revoked,
                               datetime.datetime.now(),
                               delta=datetime.datetime.now() - t1)
        t_info("Is the revoker our user", 4)
        self.assertEqual(rk.revoker, staff_only_user)
    def test_deactivate(self):
        """
        On deactivation, is RFIDkeycard object's date revoked and revoker set
        correctly?
        """
        # create keycard and associated lockuser
        lu = LockUser.objects.create(
            first_name='Jane', last_name='Doe', email='*****@*****.**')
        staff_only_user = User.objects.create_user(
            'johnny_staff', '*****@*****.**', 'my_password')
        rk = RFIDkeycard.objects.create(
            the_rfid='abcde12345', lockuser=lu, assigner=staff_only_user)

        # need logged in user so we can assign the revoker
        self.client = Client()
        self.client.login(username='******', password='******')

        # Check that the time revoked is correct -- i.e. that it's now. But we
        # need to account for lag in time between setting the now variable and
        # executing deactivate (including the print statement). This can be
        # done with assertAlmostEqual(first, second, delta=None). This is my
        # approach to calculate the delta:
        #   - get the time at t1
        #   - RFIDkeycard.deactivate() at time t2=t1+x
        #   - assert for RFIDkeycard.date_revoked at time t3=t1+x+y
        #   - So deactivation happened AT MOST x+y microseconds ago,
        #     at time of assertion
        #   - So, setting delta to the time difference between t1 and t3,
        #     or x + y
        #   - i.e. now() minus t1
        t1 = datetime.datetime.now()
        t_info("Deactivating keycard......", 3)
        rk.deactivate(staff_only_user)

        t_info("Is the date revoked correct", 4)
        self.assertAlmostEqual(rk.date_revoked, 
            datetime.datetime.now(),
            delta=datetime.datetime.now() - t1)
        t_info("Is the revoker our user", 4)
        self.assertEqual(rk.revoker, staff_only_user)
Exemple #28
0
    def test_initiate_new_keycard_scan_but_lockuser_has_keycard(self):
        """ Lockuser with specified id already has an assigned keycard: check for
        appropriate response and that a new NewKeycardScan object is not
        created """
        t_info('No LockUsers at all, right?', 4)
        self.assertEqual(len(LockUser.objects.all()), 0)

        t_info('Creating new lockuser..........', 3)
        lu = LockUser.objects.create(first_name='Jane',
                                     last_name='Doe',
                                     email='*****@*****.**')

        t_info('...with pk 1', 4)
        self.assertEqual(lu.pk, 1)

        t_info('Now there should be one LockUser, the one we just'
               ' made....', 4)
        self.assertEqual(LockUser.objects.all()[0], lu)

        t_info('...with pk 1', 4)
        self.assertEqual(LockUser.objects.all()[0].pk, 1)

        t_info(
            'Creating new RFIDkeycard and assigning to our '
            'LockUser..........', 3)
        rk = RFIDkeycard.objects.create(the_rfid='1111111111',
                                        lockuser=lu,
                                        assigner=self.staff_only_user)

        t_info('Make sure this LockUser already has a keycard', 4)
        self.assertTrue(lu.is_active())  # or lu.get_current_rfid()...

        num_new_keycard_scan_obj_before = len(NewKeycardScan.objects.all())

        t_info('Getting response..........', 3)
        response = self.client.get('/start_scan/1/')  # lockuser object id is 1

        # Parallels test_initiate_new_keycard_scan
        t_info('Check that a NewKeycardScan object has not been ' 'created', 4)
        num_new_keycard_scan_obj_after = len(NewKeycardScan.objects.all())
        self.assertEqual(num_new_keycard_scan_obj_before,
                         num_new_keycard_scan_obj_after)

        t_info('Check response status code', 4)
        self.assertEqual(response.status_code, 200)

        t_info('Check response content type', 4)
        self.assertEqual(response['content-type'], 'application/json')

        t_info('Check response content', 4)
        self.assertFalse(simplejson.loads(response.content)['success'])
        self.assertEqual(
            simplejson.loads(response.content)['error_mess'],
            'This lock user is already assigned a keycard.')
 def setUp(self):
     t_info("TestCase LockUserModelTests", 1)
     t_info(self._testMethodName + ": " + self._testMethodDoc, 3)
 def setUp(self):
     t_info("TestCase DoorModelTests", 1)
     t_info(self._testMethodName + ": " + self._testMethodDoc, 2)
Exemple #31
0
 def setUp(self):
     t_info("TestCase LockUserAdminActionsTests", 1)
     t_info(self._testMethodName + ": " + self._testMethodDoc, 2)
     self.client = Client()
     self.client.login(username='******', password='******')
Exemple #32
0
 def setUp(self):
     t_info("TestCase AccessTimeAdminTests", 1)
     t_info(self._testMethodName + ": " + self._testMethodDoc, 2)
     self.client = Client()
     self.client.login(username='******', password='******')
Exemple #33
0
    def test_initiate_new_keycard_scan_but_no_lockuser(self):
        """ Lockuser with specified id does not exist:
            - check for appropriate response
            - and that a new NewKeycardScan object is not created """
        t_info('There\'s no LockUser with pk 1, right?', 4)
        self.assertFalse(LockUser.objects.filter(pk=1))

        num_new_keycard_scan_obj_before = len(NewKeycardScan.objects.all())

        t_info('Getting response..........', 3)
        response = self.client.get('/start_scan/1/')  # lockuser object id is 1

        # check that NewKeycardScan object has NOT been created (by comparing
        # before and after NewKeycardScan objects count)
        t_info('Check that a NewKeycardScan object has not been created', 4)
        num_new_keycard_scan_obj_after = len(NewKeycardScan.objects.all())
        self.assertEqual(num_new_keycard_scan_obj_before,
                         num_new_keycard_scan_obj_after)

        t_info('Check response status code', 4)
        self.assertEqual(response.status_code, 200)

        t_info('Check response content type', 4)
        self.assertEqual(response['content-type'], 'application/json')

        t_info('Check response content', 4)
        self.assertFalse(simplejson.loads(response.content)['success'])
        self.assertEqual(
            simplejson.loads(response.content)['error_mess'],
            'This lock user was probably not found in the system.')
 def tearDown(self):
     """ Shut down Selenium WebDriver browser instance """
     t_info("(tearing down)", 2)
     self.browser.quit()
Exemple #35
0
 def setUp(self):
     t_info("TestCase RFIDkeycardModelTests", 1)
     t_info(self._testMethodName + ": " + self._testMethodDoc, 3)
    def test_keycard_deactivation(self):
        """
        Change form for an active (i.e. has assigned keycard) lock user: after
        checking 'Deactivate current keycard' and saving, does the change list
        show the deactivation/saved message? Does the change list show this
        lockuser as inactive? Back on the change form, there should not be an
        assigned keycard (Current RFID: None) and 'Deactivate current keycard'
        should be unchecked.
        """
        t_info("Opening browser to get to lockuser's change_form.......", 3)
        lockuser_id = 3
        self.browser.get(self.live_server_url +
             '/lockadmin/rfid_lock_management/lockuser/%d' % lockuser_id)
        self.browser.maximize_window()

        # Issue #a
        t_info("Before any changes / saving, 'Current RFID' should be "
               "something", 4)
        current_rfid_field = self.browser.find_element_by_css_selector(
            '.form-row.field-prettify_get_current_rfid')
        current_rfid_field = current_rfid_field.find_element_by_tag_name('p')
        self.assertNotEqual(current_rfid_field.text, 'None')

        # strip out whitespace in case template formatting introduces extra
        # white space
        current_rfid_no_ws = ''.join(current_rfid_field.text.split())
        self.assertTrue(current_rfid_no_ws)
        self.assertNotEqual(current_rfid_field.text, 'None')

        t_info("Find the 'Deactivate keycard' checkbox and verify it's "
               "not checked", 4)
        deact_checkbox = self.browser.find_element_by_css_selector(
            "input[id='id_deactivate_current_keycard']")
        self.assertFalse(deact_checkbox.is_selected())

        t_info("Check the 'Deactivate keycard' checkbox", 3)
        deact_checkbox.click()

        t_info("Find and click 'Save'", 3)
        save_button = self.browser.find_element_by_css_selector(
            "input[value='Save']")
        save_button.click()

        t_info("Are we back on the change form? Check title.", 4)
        title = self.browser.find_element_by_tag_name('title')
        self.assertEqual(title.text,
            'Manage lock users | RFID Lock Administration')

        t_info("Back on change list, change message(s) correct", 4)
        test_lockuser = LockUser.objects.get(pk=lockuser_id)
        message1 = 'The lock user "%s %s" was changed successfully.' % (
            test_lockuser.first_name, test_lockuser.last_name)
        message2 = "%s %s's keycard was deactivated successfully." % (
            test_lockuser.first_name, test_lockuser.last_name)
        info_messages_elements = self.browser.find_elements_by_class_name(
            'info')
        info_messages = [mess.text for mess in info_messages_elements]
        self.assertIn(message1, info_messages)
        self.assertIn(message2, info_messages)

        t_info("Back on change list, lockuser should no longer have "
               "keycard and active status is now False", 4)
        rows = self.browser.find_elements_by_tag_name('tr')
        rows_text = [row.text for row in rows]

        self.assertIn(
            'Lisa Simpson [email protected] False None Community Theater (None)',
            rows_text)

        t_info("Hit back to go back to the change form........", 3)
        self.browser.back()

        t_info("Are we back on the change form? Check title.", 4)
        title = self.browser.find_element_by_tag_name('title')
        self.assertEqual(title.text,
            'Change lock user | RFID Lock Administration')

        t_info("Back on change form, 'Current RFID' should now be None", 4)
        current_rfid_field = self.browser.find_element_by_css_selector(
            '.form-row.field-prettify_get_current_rfid')
        current_rfid = current_rfid_field.find_element_by_tag_name('p')
        self.assertEqual(current_rfid.text, 'None')

        t_info("Back on change form, 'Deactivate current keycard' "
               "SHOULD be checked", 4)
        deact_checkbox = self.browser.find_element_by_css_selector(
            "input[id='id_deactivate_current_keycard']")
        self.assertTrue(deact_checkbox.is_selected())
 def setUp(self):
     t_info("TestCase RFIDkeycardModelTests", 1)
     t_info(self._testMethodName + ": " + self._testMethodDoc, 3)
 def setUp(self):
     t_info("TestCase AccessTimeModelTests", 1)
     t_info(self._testMethodName + ": " + self._testMethodDoc, 2)
    def test_initiate_new_keycard_scan_but_lockuser_has_keycard(self):
        """ Lockuser with specified id already has an assigned keycard: check for
        appropriate response and that a new NewKeycardScan object is not
        created """
        t_info("No LockUsers at all, right?", 4)
        self.assertEqual(len(LockUser.objects.all()), 0)

        t_info("Creating new lockuser..........", 3)
        lu = LockUser.objects.create(first_name="Jane", last_name="Doe", email="*****@*****.**")

        t_info("...with pk 1", 4)
        self.assertEqual(lu.pk, 1)

        t_info("Now there should be one LockUser, the one we just" " made....", 4)
        self.assertEqual(LockUser.objects.all()[0], lu)

        t_info("...with pk 1", 4)
        self.assertEqual(LockUser.objects.all()[0].pk, 1)

        t_info("Creating new RFIDkeycard and assigning to our " "LockUser..........", 3)
        rk = RFIDkeycard.objects.create(the_rfid="1111111111", lockuser=lu, assigner=self.staff_only_user)

        t_info("Make sure this LockUser already has a keycard", 4)
        self.assertTrue(lu.is_active())  # or lu.get_current_rfid()...

        num_new_keycard_scan_obj_before = len(NewKeycardScan.objects.all())

        t_info("Getting response..........", 3)
        response = self.client.get("/start_scan/1/")  # lockuser object id is 1

        # Parallels test_initiate_new_keycard_scan
        t_info("Check that a NewKeycardScan object has not been " "created", 4)
        num_new_keycard_scan_obj_after = len(NewKeycardScan.objects.all())
        self.assertEqual(num_new_keycard_scan_obj_before, num_new_keycard_scan_obj_after)

        t_info("Check response status code", 4)
        self.assertEqual(response.status_code, 200)

        t_info("Check response content type", 4)
        self.assertEqual(response["content-type"], "application/json")

        t_info("Check response content", 4)
        self.assertFalse(simplejson.loads(response.content)["success"])
        self.assertEqual(
            simplejson.loads(response.content)["error_mess"], "This lock user is already assigned a keycard."
        )
    def test_initiate_new_keycard_scan_but_no_lockuser(self):
        """ Lockuser with specified id does not exist:
            - check for appropriate response
            - and that a new NewKeycardScan object is not created """
        t_info("There's no LockUser with pk 1, right?", 4)
        self.assertFalse(LockUser.objects.filter(pk=1))

        num_new_keycard_scan_obj_before = len(NewKeycardScan.objects.all())

        t_info("Getting response..........", 3)
        response = self.client.get("/start_scan/1/")  # lockuser object id is 1

        # check that NewKeycardScan object has NOT been created (by comparing
        # before and after NewKeycardScan objects count)
        t_info("Check that a NewKeycardScan object has not been created", 4)
        num_new_keycard_scan_obj_after = len(NewKeycardScan.objects.all())
        self.assertEqual(num_new_keycard_scan_obj_before, num_new_keycard_scan_obj_after)

        t_info("Check response status code", 4)
        self.assertEqual(response.status_code, 200)

        t_info("Check response content type", 4)
        self.assertEqual(response["content-type"], "application/json")

        t_info("Check response content", 4)
        self.assertFalse(simplejson.loads(response.content)["success"])
        self.assertEqual(
            simplejson.loads(response.content)["error_mess"], "This lock user was probably not found in the system."
        )
Exemple #41
0
    def test_finished_new_keycard_scan(self):
        """ Everything went ok (no active keycard with this RFID num already;
        a NewKeycardScan object with this pk does exist and has an RFID num;
        not timed out), so can assign keycard.  """
        new_scan_pk = 1
        new_rfid = '9999999999'

        t_info(
            'Creating new NewKeycardScan object we should have'
            'at this point..........', 3)
        new_nks_obj = NewKeycardScan.objects.create(
            rfid=new_rfid, assigner_user_id=self.staff_only_user.pk)

        t_info('Make sure it has the pk from URL', 4)
        self.assertEqual(new_nks_obj.pk, new_scan_pk)

        t_info('Getting response..........', 3)
        response = self.client.get('/done_scan/%d/' % new_scan_pk)

        t_info('Check response status code', 4)
        self.assertEqual(response.status_code, 200)

        t_info('Check response content type', 4)
        self.assertEqual(response['content-type'], 'application/json')

        t_info('Check response content', 4)
        self.assertEqual(simplejson.loads(response.content)['success'], True)
        self.assertEqual(simplejson.loads(response.content)['rfid'], new_rfid)

        t_info('Getting the changed NewKeycardScan obj........', 3)
        new_nks_obj = NewKeycardScan.objects.get(pk=1)

        t_info('Check that NewKeycardScan object has correct attributes', 4)
        self.assertFalse(new_nks_obj.waiting_for_scan)
        self.assertTrue(new_nks_obj.ready_to_assign)
Exemple #42
0
 def setUp(self):
     t_info('TestCase ChartDataTests', 1)
     t_info(self._testMethodName + ': ' + self._testMethodDoc, 2)
     self.client = Client()
Exemple #43
0
    def test_initiate_new_keycard_scan(self):
        """ Lockuser with specified id exists, does not have assigned keycard:
            - check for appropriate response
            - and that a new NewKeycardScan object is created,
            - and it has correct attributes (waiting_for_scan = True;
              assigner_user = request.user) """
        t_info('No LockUsers at all, right?', 4)
        self.assertEqual(len(LockUser.objects.all()), 0)
        t_info('Creating new lockuser..........', 3)
        lu = LockUser.objects.create(first_name='Jane',
                                     last_name='Doe',
                                     email='*****@*****.**')
        t_info('...with pk 1', 4)
        self.assertEqual(lu.pk, 1)

        t_info('There should be no NewKeycardScan objects to begin with', 4)
        self.assertFalse(NewKeycardScan.objects.all())

        t_info('Getting response..........', 3)
        response = self.client.get('/start_scan/1/')  # lockuser object id is 1

        t_info('Check response status code', 4)
        self.assertEqual(response.status_code, 200)

        t_info('There should be a new NewKeycardScan object now...', 4)
        self.assertEqual(len(NewKeycardScan.objects.all()), 1)

        t_info('...with pk 1', 4)
        new_nks_obj = NewKeycardScan.objects.all()[0]
        self.assertEqual(new_nks_obj.pk, 1)

        t_info('Check response content type', 4)
        self.assertEqual(response['content-type'], 'application/json')

        t_info('Check response content', 4)
        self.assertEqual(simplejson.loads(response.content)['success'], True)
        self.assertEqual(simplejson.loads(response.content)['new_scan_pk'], 1)

        t_info('Check that NewKeycardScan object has correct attributes', 4)
        self.assertTrue(new_nks_obj.waiting_for_scan)
        self.assertEqual(new_nks_obj.assigner_user, self.staff_only_user)
    def test_lockuser_change_form(self):
        """
        Is this the change_form for the right lock user?
        """
        # will be looking at change form for this lockuser
        object_id = 2
        lockuser = LockUser.objects.get(pk=object_id)

        t_info("Opening browser to get to lockuser's change_form.......", 3)
        # Issue #y
        self.browser.get(self.live_server_url +
            '/lockadmin/rfid_lock_management/lockuser/%d' % object_id)
        self.browser.maximize_window()

        # Non-form-field things
        t_info("check that in div with id='main_form', the first/only "
               "h2 tag text is: '<h2> Lock user/keycard assignment</h2>", 4)
        main_form_div = self.browser.find_element_by_id('main_form')
        first_h2 = main_form_div.find_element_by_tag_name('h2')
        self.assertEqual(first_h2.text, "Lock user / keycard assignment")

        # Check the form fields
        t_info("Check that various form fields that are filled in reflect "
               "the attributes for the LockUser whose pk is in the url.", 4)

        t_info("Is the staff user able to see - but not interact with - the "
               "doors that this lock user has access to, but the staff user "
               "does not?", 5)

        # create LockUserAdmin object so we can get other doors
        lua = LockUserAdmin(LockUser, AdminSite())

        client = Client()
        client.login(username='******', password='******')
        response = client.get(
            "/lockadmin/rfid_lock_management/lockuser/%d/" % object_id)
        request = response.context['request']
        actual_other_doors = lua.get_other_doors(request, object_id)
        door_names = [door.name for door in list(actual_other_doors)]
        # get the other doors as page displays them
        actual_other_doors_str = ", ".join(door_names)
        field = self.browser.find_element_by_id('other_doors')
        self.assertEqual(field.text, actual_other_doors_str)
        # test that we see the same thing the admin function would return
        # Issue #x
        #    (Here specifically: alternative -  hardcode actual_doors_str, i.e.
        #    actual_other_doors_str = "Space 1 Space 4"  )

        t_info("Comparing the value of the relevant text input field "
               "with the lockuser's actual email.", 4)

        field = self.browser.find_element_by_name('email')
        self.assertEqual(field.get_attribute('value'), lockuser.email)

        field = self.browser.find_element_by_name('first_name')
        self.assertEqual(field.get_attribute('value'), lockuser.first_name)

        field = self.browser.find_element_by_name('last_name')
        self.assertEqual(field.get_attribute('value'), lockuser.last_name)

        field = self.browser.find_element_by_name('address')
        self.assertEqual(field.get_attribute('value'), lockuser.address)

        field = self.browser.find_element_by_name('phone_number')
        self.assertEqual(field.get_attribute('value'), lockuser.phone_number)

        field = self.browser.find_element_by_name('phone_number')
        self.assertEqual(field.get_attribute('value'), lockuser.phone_number)

        doors_pk_tuples = lockuser.doors.values_list('pk')
        # make list of str, not list of tuples
        doors_pk_list = [t[0] for t in doors_pk_tuples]

        door_checkboxes = self.browser.find_elements_by_css_selector(
            "input[name='doors']")
        for door_checkbox in door_checkboxes:
            if door_checkbox.is_selected():
                self.assertIn(
                    int(door_checkbox.get_attribute('value')), doors_pk_list)

        deact_checkbox = self.browser.find_element_by_css_selector(
            "input[id='id_deactivate_current_keycard']")
        self.assertEqual(deact_checkbox.is_selected(),
            lockuser.deactivate_current_keycard)

        current_rfid_field = self.browser.find_element_by_css_selector(
            '.form-row.field-prettify_get_current_rfid')
        current_rfid_field = current_rfid_field.find_element_by_tag_name('p')
        self.assertEqual(current_rfid_field.text,
            lockuser.prettify_get_current_rfid())

        last_access_time_field = self.browser.find_element_by_css_selector(
            '.form-row.field-last_access_time_and_door_and_link_to_more')
        last_access_field = last_access_time_field.find_element_by_tag_name(
            'p')
        self.assertIn(lockuser.prettify_get_last_access_time(),
            last_access_time_field.text)
    def setUp(self):
	    t_info("TestCase NewKeycardScanTests", 1)
	    t_info(self._testMethodName + ": " + self._testMethodDoc, 2)  
    def test_keycard_deactivation_but_some_doors_permitted(self):
        """ Tests is the situation where the lock user is permitted access to
        some door(s), but not the one(s) the staff user is allowed access to.
        That is, on the change form, there will be no checked Door(s), so
        checking 'Deactive keycard' should not deactivate the keycard.
        """
        t_info("Opening browser to get to lockuser's change_form.......", 3)
        lockuser_id = 1
        # in fixture, lock user 1  assigned a keycard and is permitted Space 1
        # and Space 4 access; the logged in staff user is not permitted access
        # to either of those.
        self.browser.get(self.live_server_url +
             '/lockadmin/rfid_lock_management/lockuser/%d' % lockuser_id)
        self.browser.maximize_window()

        # Issue #a
        # possibly redundant double checking.....
        t_info("Before any changes / saving, 'Current RFID' should be"
               "something (but not None and not nothing)", 4)
        # current_rfid_field = self.browser.find_element_by_class_name(
        #   'form-row field-prettify_get_current_rfid')
        # Note: above throws WebDriverException: Message: u'Compound class
        # names not permitted'
        current_rfid_field = self.browser.find_element_by_css_selector(
            '.form-row.field-prettify_get_current_rfid')
        current_rfid_field = current_rfid_field.find_element_by_tag_name('p')
        self.assertNotEqual(current_rfid_field.text, 'None')

        # strip out whitespace in case template formatting introduces extra
        # white space
        current_rfid_no_ws = ''.join(current_rfid_field.text.split())
        self.assertTrue(current_rfid_no_ws)

        # a key difference between this test and test_keycard_deactivation
        t_info("Check that no doors are selected", 4)
        door_checkboxes = self.browser.find_elements_by_css_selector(
            "input[name='doors']")
        door_checkbox_statuses = [door_checkbox.is_selected()
                                  for door_checkbox in door_checkboxes]
        self.assertFalse(any(door_checkbox_statuses))

        t_info("Find the 'Deactivate keycard' checkbox and verify it's "
               "not checked", 4)
        deact_checkbox = self.browser.find_element_by_css_selector(
            "input[id='id_deactivate_current_keycard']")
        self.assertFalse(deact_checkbox.is_selected())

        # a key difference between this test and test_keycard_deactivation
        t_info("Find the other doors text and verify there is at least "
               "one door listed", 4)

        other_doors_field = self.browser.find_element_by_id('other_doors')

        # Stripping out whitespace in case template formatting introduces extra
        # white space
        other_doors_text = other_doors_field.text
        other_doors_no_ws = ''.join(other_doors_text.split())
        self.assertTrue(other_doors_no_ws)

        t_info("Check the 'Deactivate keycard' checkbox", 3)
        deact_checkbox.click()

        t_info("Find and click 'Save'", 3)
        save_button = self.browser.find_element_by_css_selector(
            "input[value='Save']")
        save_button.click()

        t_info("Are we back on the change list?", 4)
        # check change list title
        title = self.browser.find_element_by_tag_name('title')
        self.assertEqual(title.text,
            'Manage lock users | RFID Lock Administration')

        t_info("Back on change list, change message(s) correct", 4)
        test_lockuser = LockUser.objects.get(pk=lockuser_id)
        message1 = 'The lock user "%s %s" was changed successfully.' % (
            test_lockuser.first_name, test_lockuser.last_name)

        # message 2: a key difference between this test and
        # test_keycard_deactivation
        # message2 = "%s % s's keycard was not deactivated because you do not
        #    have permission to manage % s.".format(test_lockuser.first_name,
        #    test_lockuser.last_name, other_doors_text)
        message2 = ("{} {}'s keycard was not deactivated because you do not "
                    "have permission to manage {}.").format(
                        test_lockuser.first_name,
                        test_lockuser.last_name,
                        other_doors_text
                    )

        # todo:  note that using earlier result from body of change
        # form to compare with messages on change list...
        info_messages_elements = self.browser.find_elements_by_class_name(
            'info')
        info_messages = [mess.text for mess in info_messages_elements]
        self.assertIn(message1, info_messages)
        self.assertIn(message2, info_messages)

        # a key difference between this test and test_keycard_deactivation
        t_info("Back on change list, lockuser should still have "
               "keycard(active: True).", 4)

        rows = self.browser.find_elements_by_tag_name('tr')
        rows_text = [row.text for row in rows]

        # implicitly joining long string
        burns_row = ('C. M. Burns [email protected] '
                    'True RFID: 1122135122 (activated on April 10, 2013, 12:52'
                    ' AM by superuser) Springfield Mafia Secret Meeting Room, '
                    'Junior Achievers Club April 10, 2013, 12:57 AM '
                    '(Springfield ' 'Mafia Secret Meeting Room)')
        self.assertIn(burns_row, rows_text)

        t_info("Hit back to go back to the change form", 3)
        self.browser.back()

        t_info("Are we back on the change form?", 4)
        title = self.browser.find_element_by_tag_name('title')
        self.assertEqual(title.text,
            'Change lock user | RFID Lock Administration')

        # a key difference between this test and test_keycard_deactivation
        t_info("Back on change form, 'Current RFID' should not be "
               "None, still have the RFID keycard info", 4)
        current_rfid_field = self.browser.find_element_by_css_selector(
            '.form-row.field-prettify_get_current_rfid')
        current_rfid = current_rfid_field.find_element_by_tag_name('p')
        current_rfid_no_ws = ''.join(current_rfid_field.text.split())
        self.assertTrue(current_rfid_no_ws)
        self.assertNotEqual(current_rfid_field.text, 'None')

        t_info("Back on change form, 'Deactivate current keycard' "
               "SHOULD be checked", 4)
        deact_checkbox = self.browser.find_element_by_css_selector(
            "input[id='id_deactivate_current_keycard']")
        self.assertTrue(deact_checkbox.is_selected())
 def setUp(self):
     self.client = Client()
     t_info("TestCase LockCommunicationTests", 1)
     t_info(self._testMethodName + ": " + self._testMethodDoc, 2)
 def setUp(self):
     self.client = Client()
     t_info("TestCase LockCommunicationTests", 1)
     t_info(self._testMethodName + ": " + self._testMethodDoc, 2)
Exemple #49
0
    def test_finished_new_keycard_scan_keycard_with_same_rfid_exists(self):
        """ A keycard with the same RFID is already assigned to another
        lockuser """
        # create the RFIDkeycard whose rfid is the same as the one trying to
        # assign; create the lockuser with that rfid
        t_info('Creating new lockuser..........', 3)
        lu = LockUser.objects.create(first_name='Jane',
                                     last_name='Doe',
                                     email='*****@*****.**')

        # attempting to assign this one, but it already belongs to an active lock user
        duplicate_rfid = '1111111111'
        new_scan_pk = 1

        t_info(
            'Creating new RFIDkeycard and assigning to our '
            'LockUser..........', 3)
        rk = RFIDkeycard.objects.create(the_rfid=duplicate_rfid,
                                        lockuser=lu,
                                        assigner=self.staff_only_user)

        t_info('Make sure this LockUser has this keycard', 4)
        self.assertTrue(lu.is_active())  # or lu.get_current_rfid()...

        t_info(
            'Creating new NewKeycardScan object we should have '
            'at this point..........', 3)
        new_nks_obj = NewKeycardScan.objects.create(
            rfid=duplicate_rfid, assigner_user_id=self.staff_only_user.pk)

        t_info(
            'Check that the NewKeycardScan object with pk '
            'specified in the URL has the duplicate rfid', 4)
        # todo:  or is this actually covered in NewKeycardScan model tests?
        self.assertTrue(
            NewKeycardScan.objects.filter(pk=new_scan_pk, rfid=duplicate_rfid))

        t_info('Getting response..........', 3)
        response = self.client.get('/done_scan/%d/' % new_nks_obj.pk)

        t_info('Check response status code', 4)
        self.assertEqual(response.status_code, 200)

        t_info('Check response content type', 4)
        self.assertEqual(response['content-type'], 'application/json')

        t_info('Check response content', 4)
        self.assertEqual(simplejson.loads(response.content)['success'], False)
        self.assertEqual(
            simplejson.loads(response.content)['error_mess'],
            'A keycard with the same RFID is already assigned to %s.' % lu)
    def test_can_do_stuff_in_browser(self):
        """ Logging in; making sure correct user and other info displayed """
        t_info("Does user see the login screen when going to /lockadmin; "
               "able to log in; see the right stuff on the following screen?", 4)

        t_info(
            "Opening browser to get to the log in screen at /lockadmin....", 3)
        # user opens web browser; goes to main admin page
        self.browser.get(self.live_server_url + '/lockadmin')
        self.browser.maximize_window()

        t_info("Does it say RFID Lock Administration?", 4)
        # returns WebElement object
        login_page_body = self.browser.find_element_by_tag_name('body')
        # .text strips out the HTML markup
        self.assertIn("RFID Lock Administration", login_page_body.text)

        t_info("Can user actually log in via website?", 4)
        # User types in username and password and hits return
        username_field = self.browser.find_element_by_name('username')
        username_field.send_keys('moe')
        password_field = self.browser.find_element_by_name('password')
        password_field.send_keys('moe')
        password_field.send_keys(Keys.RETURN)

        t_info("After username and password accepted, is the user "
               "taken to the main page", 4)
        base_page_body = self.browser.find_element_by_tag_name('body')
        self.assertIn("Logged in as moe", base_page_body.text)

        # todo: Issue #q
        t_info("Does user see main links in the body?", 4)
        base_page_body = self.browser.find_element_by_tag_name('body')
        navbar_links = "Lock users\nRoom access log\nCreate user and assign new keycard"
        self.assertIn(navbar_links, base_page_body.text)

        t_info("Does user see listed the doors they are allowed to "
               "manage in top navigation bar?", 4)
        # in pk order
        navbar_doors = "Doors you manage: Community Theater, Seminar Room"
        self.assertIn(navbar_doors, base_page_body.text)
    def test_finished_new_keycard_scan_keycard_with_same_rfid_exists(self):
        """ A keycard with the same RFID is already assigned to another
        lockuser """
        # create the RFIDkeycard whose rfid is the same as the one trying to
        # assign; create the lockuser with that rfid
        t_info("Creating new lockuser..........", 3)
        lu = LockUser.objects.create(first_name="Jane", last_name="Doe", email="*****@*****.**")

        # attempting to assign this one, but it already belongs to an active lock user
        duplicate_rfid = "1111111111"
        new_scan_pk = 1

        t_info("Creating new RFIDkeycard and assigning to our " "LockUser..........", 3)
        rk = RFIDkeycard.objects.create(the_rfid=duplicate_rfid, lockuser=lu, assigner=self.staff_only_user)

        t_info("Make sure this LockUser has this keycard", 4)
        self.assertTrue(lu.is_active())  # or lu.get_current_rfid()...

        t_info("Creating new NewKeycardScan object we should have " "at this point..........", 3)
        new_nks_obj = NewKeycardScan.objects.create(rfid=duplicate_rfid, assigner_user_id=self.staff_only_user.pk)

        t_info("Check that the NewKeycardScan object with pk " "specified in the URL has the duplicate rfid", 4)
        # todo:  or is this actually covered in NewKeycardScan model tests?
        self.assertTrue(NewKeycardScan.objects.filter(pk=new_scan_pk, rfid=duplicate_rfid))

        t_info("Getting response..........", 3)
        response = self.client.get("/done_scan/%d/" % new_nks_obj.pk)

        t_info("Check response status code", 4)
        self.assertEqual(response.status_code, 200)

        t_info("Check response content type", 4)
        self.assertEqual(response["content-type"], "application/json")

        t_info("Check response content", 4)
        self.assertEqual(simplejson.loads(response.content)["success"], False)
        self.assertEqual(
            simplejson.loads(response.content)["error_mess"],
            "A keycard with the same RFID is already assigned to %s." % lu,
        )