Exemplo n.º 1
0
 def test_superuser_all_proposals(self, post_mock, get_mock):
     self.admin_user.backend = settings.AUTHENTICATION_BACKENDS[0]
     self.client.force_login(self.admin_user)
     FrameFactory.create(PROPID='prop1')
     FrameFactory.create(PROPID='prop2')
     self.assertEqual(['prop1', 'prop2'], self.admin_user.profile.proposals)
     self.assertFalse(get_mock.called)
Exemplo n.º 2
0
    def test_filters_public(self):
        user = User.objects.create(username='******', password='******')
        Profile.objects.create(user=user)
        user.backend = settings.AUTHENTICATION_BACKENDS[0]
        responses.add(responses.GET,
                      settings.OAUTH_CLIENT['PROFILE_URL'],
                      body=json.dumps({'proposals': [{
                          'id': 'prop1'
                      }]}),
                      status=200,
                      content_type='application/json')
        self.client.force_login(user)
        proposal_frame = FrameFactory(L1PUBDAT=datetime.datetime(2999,
                                                                 1,
                                                                 1,
                                                                 tzinfo=UTC),
                                      PROPID='prop1')
        public_frame = PublicFrameFactory()

        for false_string in ['false', 'False', '0']:
            response = self.client.get(
                reverse('frame-list') + '?public={}'.format(false_string))
            self.assertContains(response, proposal_frame.basename)
            self.assertNotContains(response, public_frame.basename)

        self.client.logout()

        for false_string in ['false', 'False', '0']:
            response = self.client.get(
                reverse('frame-list') + '?public={}'.format(false_string))
            self.assertNotContains(response, proposal_frame.basename)
            self.assertNotContains(response, public_frame.basename)
 def setUp(self):
     user = User.objects.create(username='******',
                                password='******',
                                is_superuser=True)
     user.backend = settings.AUTHENTICATION_BACKENDS[0]
     self.client.force_login(user)
     self.frames = FrameFactory.create_batch(5)
     self.frame = self.frames[0]
Exemplo n.º 4
0
 def setUp(self):
     boto3.client = MagicMock()
     self.normal_user = User.objects.create(username='******',
                                            password='******')
     self.normal_user.backend = settings.AUTHENTICATION_BACKENDS[0]
     Profile(user=self.normal_user,
             access_token='test',
             refresh_token='test').save()
     self.public_frame = FrameFactory(PROPID='public',
                                      L1PUBDAT=datetime.datetime(
                                          2000, 1, 1, tzinfo=UTC))
     self.proposal_frame = FrameFactory(PROPID='prop1',
                                        L1PUBDAT=datetime.datetime(
                                            2099, 1, 1, tzinfo=UTC))
     self.not_owned = FrameFactory(PROPID='notyours',
                                   L1PUBDAT=datetime.datetime(2099,
                                                              1,
                                                              1,
                                                              tzinfo=UTC))
 def setUp(self):
     self.normal_user = User.objects.create(username='******',
                                            password='******')
     self.normal_user.backend = settings.AUTHENTICATION_BACKENDS[0]
     Profile.objects.update_or_create(user=self.normal_user,
                                      defaults={
                                          'access_token': 'test',
                                          'refresh_token': 'test'
                                      })
     self.auth_profile = AuthProfile.objects.create(user=self.normal_user,
                                                    api_token='myApiToken')
     self.public_frame = FrameFactory(proposal_id='public',
                                      public_date=datetime.datetime(
                                          2000, 1, 1, tzinfo=UTC))
     self.proposal_frame = FrameFactory(proposal_id='prop1',
                                        public_date=datetime.datetime(
                                            2099, 1, 1, tzinfo=UTC))
     self.not_owned = FrameFactory(proposal_id='notyours',
                                   public_date=datetime.datetime(
                                       2099, 1, 1, tzinfo=UTC))
Exemplo n.º 6
0
 def setUp(self):
     boto3.client = MagicMock()
     is_public_date = timezone.now() - datetime.timedelta(days=7)
     is_not_public_date = timezone.now() + datetime.timedelta(days=7)
     FrameFactory.create(OBSTYPE='EXPOSE',
                         TELID='1m0a',
                         SITEID='bpl',
                         INSTRUME='kb46',
                         PROPID='prop1',
                         FILTER='rp',
                         L1PUBDAT=is_public_date)
     FrameFactory.create(OBSTYPE='BIAS',
                         TELID='0m4a',
                         SITEID='coj',
                         INSTRUME='en05',
                         PROPID='prop2',
                         FILTER='V',
                         L1PUBDAT=is_not_public_date)
     FrameFactory.create(OBSTYPE='SKYFLAT',
                         TELID='2m0b',
                         SITEID='ogg',
                         INSTRUME='fl10',
                         PROPID='prop3',
                         FILTER='B',
                         L1PUBDAT=is_public_date)
Exemplo n.º 7
0
 def test_post_duplicate_data(self):
     frame = FrameFactory()
     version = frame.version_set.all()[0]
     frame_payload = self.single_frame_payload
     frame_payload['version_set'] = [{
         'md5': version.md5,
         'key': 'random_key',
         'extension': '.fits.fz'
     }]
     response = self.client.post(reverse('frame-list'),
                                 json.dumps(frame_payload),
                                 content_type='application/json')
     self.assertEqual(response.json()['version_set'], [{
         'md5': ['version with this md5 already exists.']
     }])
     self.assertEqual(response.status_code, 400)
 def setUp(self):
     is_public_date = timezone.now() - datetime.timedelta(days=7)
     is_not_public_date = timezone.now() + datetime.timedelta(days=7)
     FrameFactory.create(configuration_type='EXPOSE',
                         telescope_id='1m0a',
                         site_id='bpl',
                         instrument_id='kb46',
                         proposal_id='prop1',
                         primary_optical_element='rp',
                         public_date=is_public_date)
     FrameFactory.create(configuration_type='BIAS',
                         telescope_id='0m4a',
                         site_id='coj',
                         instrument_id='en05',
                         proposal_id='prop2',
                         primary_optical_element='V',
                         public_date=is_not_public_date)
     FrameFactory.create(configuration_type='SKYFLAT',
                         telescope_id='2m0b',
                         site_id='ogg',
                         instrument_id='fl10',
                         proposal_id='prop3',
                         primary_optical_element='B',
                         public_date=is_public_date)
Exemplo n.º 9
0
 def test_get_headers(self):
     frame = FrameFactory.create()
     response = self.client.get(reverse('frame-headers', args=(frame.id, )))
     self.assertContains(response, frame.headers.data['TRACKNUM'])
Exemplo n.º 10
0
 def test_get_related(self):
     frame = FrameFactory.create()
     related_frame = FrameFactory.create(related_frames=[frame])
     response = self.client.get(reverse('frame-related', args=(frame.id, )))
     self.assertContains(response, related_frame.basename)
Exemplo n.º 11
0
 def test_version_delete(self, mock):
     frame = FrameFactory()
     frame.delete()
     self.assertTrue(mock.called)
 def setUp(self):
     self.frame = FrameFactory(
         observation_day=datetime.datetime(2020, 11, 18, tzinfo=UTC))