def setUp(self): self.proposal = mixer.blend(Proposal) self.pi_user = blend_user() self.ci_user = blend_user() Membership.objects.create(user=self.pi_user, proposal=self.proposal, role=Membership.PI) Membership.objects.create(user=self.ci_user, proposal=self.proposal, role=Membership.CI)
def setUp(self): self.pi_user = blend_user() self.ci_user = blend_user() self.proposal = mixer.blend(Proposal) mixer.blend(Membership, user=self.pi_user, role=Membership.PI, proposal=self.proposal) self.cim = mixer.blend(Membership, user=self.ci_user, role=Membership.CI, proposal=self.proposal)
def test_requestgroup_admin_staff_view_enabled(self): user = blend_user(user_params={'is_staff': True}, profile_params={'staff_view': True}) self.client.force_login(user) response = self.client.get(reverse('requestgroups:list')) for rg in self.request_groups: self.assertContains(response, rg.name)
def setUp(self): self.user = blend_user(user_params={'is_staff': True}) self.proposal = mixer.blend(Proposal) self.semester = mixer.blend(Semester) self.ta = mixer.blend(TimeAllocation, semester=self.semester, proposal=self.proposal)
def test_proposal_table_not_staff(self): user = blend_user() self.client.force_login(user) response = self.client.get( reverse('proposals:semester-admin', kwargs={'pk': self.semester.id})) self.assertEqual(response.status_code, 403)
def test_request_detail_admin(self): user = blend_user(user_params={'is_staff': True}) self.client.force_login(user) response = self.client.get( reverse('requestgroups:request-detail', kwargs={'pk': self.request.id})) self.assertEqual(response.status_code, 404)
def setUp(self): self.pi_user = blend_user() self.ci_user = blend_user() proposal = mixer.blend(Proposal) Membership.objects.create(user=self.pi_user, proposal=proposal, role=Membership.PI) Membership.objects.create(user=self.ci_user, proposal=proposal, role=Membership.CI) self.proposal_invite = ProposalInvite.objects.create( proposal=proposal, role=Membership.CI, email='*****@*****.**', sent=timezone.now(), used=None)
def test_staff_dont_need_to_accept(self): user = blend_user(user_params={'is_staff': True, 'is_superuser': True}) user.profile.terms_accepted = None user.profile.save() self.client.force_login(user) response = self.client.get(reverse('requestgroups:list')) self.assertContains(response, 'Submitted Requests')
def test_request_detail_admin_staff_view_enabled(self): user = blend_user(user_params={'is_staff': True}, profile_params={'staff_view': True}) self.client.force_login(user) response = self.client.get( reverse('requestgroups:request-detail', kwargs={'pk': self.request.id})) self.assertContains(response, self.request.id)
def test_user_has_not_accepted_terms(self): user = blend_user() user.profile.terms_accepted = None user.profile.save() self.client.force_login(user) response = self.client.get(reverse('requestgroups:list')) self.assertRedirects(response, reverse('accept-terms'))
def test_cannot_invite_to_other_proposal(self): self.client.force_login(blend_user()) response = self.client.post(reverse('proposals:invite', kwargs={'pk': self.proposal.id}), data={'email': '*****@*****.**'}, follow=True) self.assertEqual(response.status_code, 404) self.assertFalse( ProposalInvite.objects.filter(email='*****@*****.**', proposal=self.proposal).exists())
def test_cannot_view_others_details(self): other_user = blend_user() app = mixer.blend( ScienceApplication, status=ScienceApplication.DRAFT, submitter=other_user, call=self.call ) response = self.client.get(reverse('sciapplications:detail', kwargs={'pk': app.id})) self.assertEqual(response.status_code, 404)
def setUp(self): self.user = blend_user() self.proposal = mixer.blend(Proposal) mixer.blend(Membership, proposal=self.proposal, user=self.user) self.request_group = mixer.blend(RequestGroup, proposal=self.proposal, name=mixer.RANDOM, observation_type=RequestGroup.NORMAL) self.request = mixer.blend(Request, request_group=self.request_group) mixer.blend(Configuration, request=self.request, instrument_type='1M0-SCICAM-SBIG') self.client.force_login(self.user) super().setUp()
def test_staff_can_view_details(self): staff_user = blend_user(user_params={'is_staff': True}) self.client.force_login(staff_user) app = mixer.blend( ScienceApplication, status=ScienceApplication.DRAFT, submitter=self.user, call=self.call ) response = self.client.get(reverse('sciapplications:detail', kwargs={'pk': app.id})) self.assertContains(response, app.title)
def setUp(self): self.semester = mixer.blend( Semester, start=timezone.now() + timedelta(days=1), end=timezone.now() + timedelta(days=365) ) self.user = blend_user() self.client.force_login(self.user) self.call = mixer.blend( Call, semester=self.semester, deadline=timezone.now() + timedelta(days=7), proposal_type=Call.SCI_PROPOSAL ) mixer.blend(Instrument, call=self.call)
def setUp(self): self.user = blend_user() self.proposals = mixer.cycle(3).blend(Proposal) for proposal in self.proposals: mixer.blend(Membership, proposal=proposal, user=self.user) self.request_groups = mixer.cycle(3).blend( RequestGroup, proposal=(p for p in self.proposals)) self.requests = mixer.cycle(3).blend( Request, request_group=(rg for rg in self.request_groups), ) self.client.force_login(self.user)
def test_terms_accepted(self): user = blend_user() user.profile.terms_accepted = None user.profile.save() self.client.force_login(user) form_data = {'accept': True} response = self.client.post(reverse('accept-terms'), data=form_data, follow=True) self.assertRedirects(response, reverse('requestgroups:list')) user.profile.refresh_from_db() self.assertTrue(user.profile.terms_accepted)
def test_terms_not_accepted(self): user = blend_user() user.profile.terms_accepted = None user.profile.save() self.client.force_login(user) form_data = {'accept': False} response = self.client.post(reverse('accept-terms'), data=form_data, follow=True) self.assertContains(response, 'Accept Terms') user.profile.refresh_from_db() self.assertFalse(user.profile.terms_accepted)
def test_no_proposals_for_semester(self): user = blend_user() semester = mixer.blend(Semester, id='2016A') other_semester = mixer.blend(Semester, id='2017A') proposal = mixer.blend(Proposal) mixer.blend(TimeAllocation, semester=semester) mixer.blend(Membership, user=user, proposal=proposal) self.client.force_login(user) response = self.client.get( reverse('proposals:list') + '?semester={}'.format(other_semester.id)) self.assertContains(response, 'No proposals for this semester.')
def test_cannot_set_others_limit(self): self.client.force_login(self.pi_user) other_user = blend_user() other_proposal = mixer.blend(Proposal) membership = Membership.objects.create(user=other_user, proposal=other_proposal) response = self.client.post( reverse('proposals:membership-limit', kwargs={'pk': membership.id}), data={'time_limit': 300}, ) membership.refresh_from_db() self.assertEqual(response.status_code, 404) self.assertEqual(membership.time_limit, -1)
def test_cannot_set_global_limit_other_proposal(self): self.client.force_login(self.pi_user) other_user = blend_user() other_proposal = mixer.blend(Proposal) membership = mixer.blend(Membership, user=other_user, proposal=other_proposal) response = self.client.post( reverse('proposals:membership-global', kwargs={'pk': other_proposal.id}), data={'time_limit': 2}, ) self.assertEqual(response.status_code, 404) self.assertEqual(membership.time_limit, -1)
def test_ci_cannot_remove_ci(self): other_user = blend_user() other_cim = mixer.blend(Membership, user=other_user, proposal=self.proposal) self.client.force_login(self.ci_user) self.assertEqual(self.proposal.membership_set.count(), 3) response = self.client.post(reverse('proposals:membership-delete', kwargs={'pk': other_cim.id}), data={'submit': 'Confirm'}, follow=True) self.assertEqual(response.status_code, 404) self.assertEqual(self.proposal.membership_set.count(), 3)
def test_cannot_delete_others(self): other_user = blend_user() app = mixer.blend( ScienceApplication, status=ScienceApplication.DRAFT, submitter=other_user, call=self.call ) response = self.client.post( reverse('sciapplications:delete', kwargs={'pk': app.id}), data={'submit': 'Confirm'}, follow=True ) self.assertEqual(response.status_code, 404) self.assertTrue(ScienceApplication.objects.filter(pk=app.id).exists())
def setUp(self): super().setUp() self.profile = blend_user(profile_params={ 'notifications_enabled': True }).profile self.data = { 'first_name': self.profile.user.first_name, 'last_name': self.profile.user.last_name, 'email': self.profile.user.email, 'username': self.profile.user.username, 'institution': self.profile.institution, 'title': self.profile.title, 'notifications_enabled': self.profile.notifications_enabled } self.client.force_login(self.profile.user)
def test_staff_can_view_pdf(self): PdfFileMerger.merge = MagicMock HTML.write_pdf = MagicMock staff_user = blend_user(user_params={'is_staff': True}) self.client.force_login(staff_user) self.client.force_login(staff_user) app = mixer.blend( ScienceApplication, status=ScienceApplication.DRAFT, submitter=self.user, call=self.call ) response = self.client.get(reverse('sciapplications:pdf', kwargs={'pk': app.id})) self.assertTrue(PdfFileMerger.merge.called) self.assertTrue(HTML.write_pdf.called) self.assertEqual(response.status_code, 200)
def setUp(self): self.semester = mixer.blend( Semester, start=timezone.now() + timedelta(days=1), end=timezone.now() + timedelta(days=365) ) self.user = blend_user() self.client.force_login(self.user) self.call = mixer.blend( Call, semester=self.semester, deadline=timezone.now() + timedelta(days=7), proposal_type=Call.SCI_PROPOSAL ) self.instrument = mixer.blend(Instrument, call=self.call) self.app = mixer.blend( ScienceApplication, status=ScienceApplication.DRAFT, submitter=self.user, call=self.call ) tr = mixer.blend(TimeRequest, science_application=self.app) coi = mixer.blend(CoInvestigator, science_application=self.app) self.data = { 'call': self.call.id, 'title': 'updates', 'status': 'DRAFT', 'timerequest_set-TOTAL_FORMS': 1, 'timerequest_set-INITIAL_FORMS': 1, 'timerequest_set-MIN_NUM_FORMS': 1, 'timerequest_set-MAX_NUM_FORMS': 1000, 'timerequest_set-0-id': tr.id, 'timerequest_set-0-instrument': self.instrument.id, 'timerequest_set-0-std_time': tr.std_time, 'timerequest_set-0-rr_time': tr.rr_time, 'timerequest_set-0-tc_time': tr.tc_time, 'coinvestigator_set-TOTAL_FORMS': 1, 'coinvestigator_set-INITIAL_FORMS': 1, 'coinvestigator_set-MIN_NUM_FORMS': 1, 'coinvestigator_set-MAX_NUM_FORMS': 1000, 'coinvestigator_set-0-id': coi.id, 'coinvestigator_set-0-email': coi.email, 'coinvestigator_set-0-first_name': coi.first_name, 'coinvestigator_set-0-last_name': coi.last_name, 'coinvestigator_set-0-institution': coi.institution }
def test_user_has_accepted_terms(self): user = blend_user() self.client.force_login(user) response = self.client.get(reverse('requestgroups:list')) self.assertContains(response, 'Submitted Requests')
def setUp(self): self.user = blend_user() self.client.force_login(self.user)
def setUp(self): self.user = blend_user( user_params=dict(username='******', email='*****@*****.**')) self.user.set_password('sopassword') self.user.save()
def setUp(self) -> None: super(TestRevokeTokenAPI, self).setUp() self.user = blend_user() self.client.force_login(self.user)