def test_can_see_devices(self): # a device is already created device = IpadFactory() # goes to the device index res = self.app.get('/', user=self.reader.user).follow() # sees the device name res.mustcontain(device.name, device.get_status_display(), device.serial_number)
def test_can_see_device_detail(self): # a device is created device = IpadFactory() # goes to its detail page res = self.app.get('/devices/ipads/{pk}/'.format(pk=device.pk)) res.mustcontain(device.name, device.get_verbose_status(), device.get_condition_display(), device.serial_number) assert_in('Check-in Comments', res)
class IpadTest(TestCase): def setUp(self): self.ipad = IpadFactory() def test_model(self): ipad = IpadFactory() assert_true(ipad.pk) assert_true(ipad.status) assert_true(ipad.created_at) assert_true(ipad.updated_at) assert_false(ipad.lendee) assert_false(ipad.lender) def test_saving_to_database(self): init_count = Ipad.objects.count() IpadFactory() assert_equal(Ipad.objects.count(), init_count + 1) def test_check_in(self): self.ipad.check_in(condition='excellent') assert_equal(self.ipad.status, Device.CHECKED_IN_NOT_READY) self.ipad.check_in(condition='scratched') assert_equal(self.ipad.status, Device.CHECKED_IN_NOT_READY) assert_equal(self.ipad.condition, Device.SCRATCHED) self.ipad.check_in(condition='broken') assert_equal(self.ipad.status, Device.BROKEN) assert_equal(self.ipad.condition, Device.BROKEN) self.ipad.check_in(condition='missing') assert_equal(self.ipad.status, Device.MISSING) assert_equal(self.ipad.condition, Device.MISSING) def test_checkout_with_other_devices(self): assert False, 'finish me'
def test_can_checkout_ipad_to_user(self): # an ipad is created device = IpadFactory(status=Device.CHECKED_IN_READY) # a user is created user = UserFactory() # checks out the device to the user self._checkout(device, user.username)
def test_cannot_remove_device(self): # a device is created IpadFactory() # goes to devices page res = self.app.get('/', user=self.experimenter.user).follow() # cannot see delete device assert_not_in('Delete', res)
def test_can_check_in(self): # There's a checked out device device = IpadFactory(status=Device.CHECKED_OUT, created_at=timezone.now(), updated_at=timezone.now()) self.open('/') # clicks on the table row for the checked IN device (second row) self.driver.find_css('tbody tr')[1].click() # clicks check in self.driver.find_css('.btn-checkin').click() # an alert dialog comes up saying that the device is already checked in dialog = self.driver.switch_to_alert() assert_in(u"Device is already checked in", dialog.text) # dismisses the alert dialog.accept() # clicks on the table row for the checked out device (top row) self.driver.find_css("tbody tr")[0].click() # clicks check in self.driver.find_css('.btn-checkin').click() # at the checkin page self.driver.click_submit() # saved to db device = Ipad.objects.get(pk=device.pk) assert_equal(device.status, Device.CHECKED_IN_NOT_READY) assert_in('Successfully checked in', self.driver.body_text())
def test_cannot_remove_device(self): # a device is created IpadFactory() # goes to devices page res = self.app.get('/', user=self.reader.user).follow() # there's no delete button assert_not_in('Delete', res)
def test_can_edit_ipad_comment(self): # A device is created device = IpadFactory() # It has a check-in comment comment = IpadCommentFactory(text="Just a bigger iPhone", device=device, user=self.experimenter.user) # goes to the detail page res = self.app.get('/devices/ipads/{pk}/'.format(pk=device.pk), user=self.experimenter.user) # can see the comment assert_in(comment.text, res) # clicks the edit link res = res.click('Edit') # sees a form assert_in('Edit comment', res) form = res.forms['id-edit_comment_form'] # changes the comment text form['text'] = 'Or a flat MacBook Air' # submits the form res = form.submit().follow() # back at the detail page assert_equal(res.request.path, '/devices/ipads/{pk}/'.format(pk=device.pk)) # sees the new comment text assert_in('Or a flat MacBook Air', res)
def test_model(self): ipad = IpadFactory() assert_true(ipad.pk) assert_true(ipad.status) assert_true(ipad.created_at) assert_true(ipad.updated_at) assert_false(ipad.lendee) assert_false(ipad.lender)
def test_can_checkin_screatched_ipad(self): # an ipad is created device = IpadFactory(status=Device.CHECKED_OUT) # checks it in (sets condition to 'Scratched') self._checkin(device, condition='scratched', expected_status=Device.CHECKED_IN_NOT_READY) # devices condition is updated device = device.__class__.objects.get(pk=device.pk) assert_equal(device.condition, Device.SCRATCHED)
def test_can_delete_ipad_comment(self): device = IpadFactory() comment = IpadCommentFactory(device=device, user=self.experimenter.user) self._test_delete_comment(device, comment, detail_url='/devices/ipads/{pk}/'.format(pk=device.pk), delete_url=reverse('comments:ipad_delete', args=(device.pk, comment.pk)) )
def setUp(self): # Create a user (Experimenter) self.experimenter = ExperimenterFactory() # Create a subject self.subject = SubjectFactory() # create a device self.device = IpadFactory(status=Device.CHECKED_IN_NOT_READY) self.driver = CustomWebDriver() self._login()
def test_can_edit_ipad(self): # an ipad is created device = IpadFactory(name="iPad", make="iPad 4", status=Device.CHECKED_IN_NOT_READY) # goes to edit page res = self.app.get('/devices/ipads/{pk}/edit/'.format(pk=device.pk)) # there's a form for editing form = res.forms['id-edit_form'] form['status'] = Device.CHECKED_IN_READY # submits res = form.submit().follow() assert_equal(res.request.path, '/devices/ipads/') # device is updated in db device = Ipad.objects.get(pk=device.pk) assert_equal(device.status, Device.CHECKED_IN_READY)
def test_saving_to_database(self): init_count = Ipad.objects.count() IpadFactory() assert_equal(Ipad.objects.count(), init_count + 1)
def setUp(self): self.ipad = IpadFactory()
def test_can_checkin_ipad(self): # an ipad is created device = IpadFactory(status=Device.CHECKED_OUT) # checks it in self._checkin(device, expected_status=Device.CHECKED_IN_NOT_READY)
def test_can_checkout_to_subject_without_dashes(self): # an ipad is created device = IpadFactory(status=Device.CHECKED_IN_READY) # checks out the device to a subject by entering their subject id self._checkout(device, '123451')