Ejemplo n.º 1
0
 def test_default_authorisation(self):
     SilkyConfig().SILKY_AUTHENTICATION = True
     SilkyConfig().SILKY_AUTHORISATION = True
     SilkyConfig().SILKY_PERMISSIONS = default_permissions
     username_and_password = '******'  # bob is an imbecile and uses the same pass as his username
     user = User.objects.create(username=username_and_password)
     user.set_password(username_and_password)
     user.save()
     self.client.login(username=username_and_password, password=username_and_password)
     response = self.client.get(silky_reverse('requests'))
     self.assertEqual(response.status_code, 403)
     user.is_staff = True
     user.save()
     response = self.client.get(silky_reverse('requests'))
     self.assertEqual(response.status_code, 200)
Ejemplo n.º 2
0
 def test_default_authorisation(self):
     SilkyConfig().SILKY_AUTHENTICATION = True
     SilkyConfig().SILKY_AUTHORISATION = True
     SilkyConfig().SILKY_PERMISSIONS = default_permissions
     username_and_password = '******'  # bob is an imbecile and uses the same pass as his username
     user = User.objects.create(username=username_and_password)
     user.set_password(username_and_password)
     user.save()
     self.client.login(username=username_and_password, password=username_and_password)
     response = self.client.get(silky_reverse('requests'))
     self.assertEqual(response.status_code, 403)
     user.is_staff = True
     user.save()
     response = self.client.get(silky_reverse('requests'))
     self.assertEqual(response.status_code, 200)
Ejemplo n.º 3
0
 def test_request_detail(self):
     request_query_data = random.choice(models.Request.objects.values('id'))
     request_id = request_query_data['id']
     response = self.client.get(silky_reverse('request_detail', kwargs={
         'request_id': request_id
     }))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 4
0
 def test_profile_detail(self):
     profile_query_data = random.choice(models.Profile.objects.values('id'))
     profile_id = profile_query_data['id']
     response = self.client.get(silky_reverse('profile_detail', kwargs={
         'profile_id': profile_id
     }))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 5
0
 def test_request_profile_detail(self):
     kwargs = random.choice(
         models.Profile.objects.annotate(profile_id=F('id')).values(
             'profile_id', 'request_id').filter(request_id__isnull=False))
     response = self.client.get(
         silky_reverse('request_profile_detail', kwargs=kwargs))
     self.assertTrue(response.status_code == 200)
 def test_clear_all(self):
     RequestMinFactory.create()
     self.assertEqual(models.Request.objects.count(), 1)
     response = self.client.post(silky_reverse("cleardb"),
                                 {"clear_all": "on"})
     self.assertTrue(response.status_code == 200)
     self.assertEqual(models.Request.objects.count(), 0)
Ejemplo n.º 7
0
 def test_profile_sql(self):
     profile_id = random.choice(
         models.Profile.objects.annotate(
             num=Count('queries')).values_list('id').filter(num__gt=0))[0]
     response = self.client.get(
         silky_reverse('profile_sql', kwargs={'profile_id': profile_id}))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 8
0
 def test_request_profiling(self):
     request_id = random.choice(
         models.Profile.objects.values('request_id').filter(
             request_id__isnull=False))
     response = self.client.get(
         silky_reverse('request_profiling', kwargs=request_id))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 9
0
 def test_request_profiling(self):
     request_id = random.choice(
         models.Profile.objects
         .values('request_id')
         .filter(request_id__isnull=False)
     )
     response = self.client.get(silky_reverse('request_profiling', kwargs=request_id))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 10
0
 def test_request_profile_detail(self):
     fields = {
         'profile_id': 'silk_profile.id',
         'request_id': 'request_id'
     }
     kwargs = random.choice(models.Profile.objects.extra(select=fields).values(*fields.keys()).filter(request_id__isnull=False))
     response = self.client.get(silky_reverse('request_profile_detail', kwargs=kwargs))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 11
0
 def test_request_sql(self):
     request_query_data = random.choice(
         models.SQLQuery.objects.values('request_id').filter(
             request_id__isnull=False))
     request_id = request_query_data['request_id']
     response = self.client.get(
         silky_reverse('request_sql', kwargs={'request_id': request_id}))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 12
0
 def test_request_profile_detail(self):
     fields = {'profile_id': 'silk_profile.id', 'request_id': 'request_id'}
     kwargs = random.choice(
         models.Profile.objects.extra(select=fields).values(
             *fields.keys()).filter(request_id__isnull=False))
     response = self.client.get(
         silky_reverse('request_profile_detail', kwargs=kwargs))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 13
0
 def test_authentication(self):
     SilkyConfig().SILKY_AUTHENTICATION = True
     response = self.client.get(silky_reverse('requests'))
     self.assertEqual(response.status_code, 302)
     try:
         url = response.url
     except AttributeError:  # Django 1.5
         url = response['location']
     self.assertIn(reverse('login'), url)
Ejemplo n.º 14
0
    def test_custom_authorisation(self):
        SilkyConfig().SILKY_AUTHENTICATION = True
        SilkyConfig().SILKY_AUTHORISATION = True
        def custom_authorisation(user):
            return user.username.startswith('mike')

        SilkyConfig().SILKY_PERMISSIONS = custom_authorisation
        username_and_password = '******'  # bob is an imbecile and uses the same pass as his username
        user = User.objects.create(username=username_and_password)
        user.set_password(username_and_password)
        user.save()
        self.client.login(username=username_and_password, password=username_and_password)
        response = self.client.get(silky_reverse('requests'))
        self.assertEqual(response.status_code, 403)
        user.username = '******'
        user.save()
        response = self.client.get(silky_reverse('requests'))
        self.assertEqual(response.status_code, 200)
Ejemplo n.º 15
0
 def test_request_sql(self):
     request_query_data = random.choice(
         models.SQLQuery.objects
         .values('request_id')
         .filter(request_id__isnull=False)
     )
     request_id = request_query_data['request_id']
     response = self.client.get(silky_reverse('request_sql', kwargs={'request_id': request_id}))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 16
0
 def test_request_and_profile_sql_detail(self):
     fields = {
         'profile_id': 'profile_id',
         'sql_id': 'sqlquery_id',
         'request_id': 'request_id'
     }
     kwargs = random.choice(models.Profile.objects.extra(select=fields).annotate(num=Count('queries')).values(*fields.keys()).filter(request_id__isnull=False, num__gt=0))
     response = self.client.get(silky_reverse('request_and_profile_sql_detail', kwargs=kwargs))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 17
0
 def test_request_and_profile_sql(self):
     kwargs = random.choice(
         models.Profile.objects
         .annotate(num=Count('queries'), profile_id=F('id'))
         .values('profile_id', 'request_id')
         .filter(request_id__isnull=False, num__gt=0)
     )
     response = self.client.get(silky_reverse('request_and_profile_sql', kwargs=kwargs))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 18
0
 def test_request_profile_detail(self):
     kwargs = random.choice(
         models.Profile.objects
         .annotate(profile_id=F('id'))
         .values('profile_id', 'request_id')
         .filter(request_id__isnull=False)
     )
     response = self.client.get(silky_reverse('request_profile_detail', kwargs=kwargs))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 19
0
 def test_authentication(self):
     SilkyConfig().SILKY_AUTHENTICATION = True
     response = self.client.get(silky_reverse('requests'))
     self.assertEqual(response.status_code, 302)
     try:
         url = response.url
     except AttributeError:  # Django 1.5
         url = response['location']
     self.assertIn(reverse('login'), url)
Ejemplo n.º 20
0
 def test_profile_sql(self):
     profile_query_data = random.choice(
         models.Profile.objects
         .annotate(num=Count('queries'))
         .values('id')
         .filter(num__gt=0)
     )
     profile_id = profile_query_data['id']
     response = self.client.get(silky_reverse('profile_sql', kwargs={'profile_id': profile_id}))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 21
0
    def test_custom_authorisation(self):
        SilkyConfig().SILKY_AUTHENTICATION = True
        SilkyConfig().SILKY_AUTHORISATION = True

        def custom_authorisation(user):
            return user.username.startswith('mike')

        SilkyConfig().SILKY_PERMISSIONS = custom_authorisation
        username_and_password = '******'  # bob is an imbecile and uses the same pass as his username
        user = User.objects.create(username=username_and_password)
        user.set_password(username_and_password)
        user.save()
        self.client.login(username=username_and_password, password=username_and_password)
        response = self.client.get(silky_reverse('requests'))
        self.assertEqual(response.status_code, 403)
        user.username = '******'
        user.save()
        response = self.client.get(silky_reverse('requests'))
        self.assertEqual(response.status_code, 200)
Ejemplo n.º 22
0
 def test_allowed_file_paths_nothing_specified(self):
     """by default we dont display any source, and it should return correctly"""
     request = MockSuite().mock_request()
     query = MockSuite().mock_sql_queries(request=request, n=1)[0]
     response = self.client.get(
         silky_reverse('request_sql_detail',
                       kwargs={
                           'sql_id': query.id,
                           'request_id': request.id
                       }))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 23
0
 def test_request_and_profile_sql(self):
     kwargs = random.choice(
         models.Profile.objects.annotate(num=Count('queries'),
                                         profile_id=F('id')).values(
                                             'profile_id',
                                             'request_id').filter(
                                                 request_id__isnull=False,
                                                 num__gt=0))
     response = self.client.get(
         silky_reverse('request_and_profile_sql', kwargs=kwargs))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 24
0
 def test_authentication(self):
     SilkyConfig().SILKY_AUTHENTICATION = True
     response = self.client.get(silky_reverse('requests'))
     self.assertEqual(response.status_code, 302)
     url = response.url
     try:
         # If we run tests within the django_silk project, a login url is available from example_app
         self.assertIn(reverse('login'), url)
     except NoReverseMatch:
         # Otherwise the Django default login url is used, in which case we can test for that instead
         self.assertIn('http://testserver/login/', url)
Ejemplo n.º 25
0
 def test_authentication(self):
     SilkyConfig().SILKY_AUTHENTICATION = True
     response = self.client.get(silky_reverse('requests'))
     self.assertEqual(response.status_code, 302)
     url = response.url
     try:
         # If we run tests within the django_silk project, a login url is available from example_app
         self.assertIn(reverse('login'), url)
     except NoReverseMatch:
         # Otherwise the Django default login url is used, in which case we can test for that instead
         self.assertIn('http://testserver/login/', url)
Ejemplo n.º 26
0
 def test_request_and_profile_sql_detail(self):
     fields = {
         'profile_id': 'profile_id',
         'sql_id': 'sqlquery_id',
         'request_id': 'request_id'
     }
     kwargs = random.choice(
         models.Profile.objects.extra(select=fields).annotate(
             num=Count('queries')).values(*fields.keys()).filter(
                 request_id__isnull=False, num__gt=0))
     response = self.client.get(
         silky_reverse('request_and_profile_sql_detail', kwargs=kwargs))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 27
0
 def test_allowed_file_paths_unavailable_source(self):
     """if we request to view source that is not in the tracebackk we should get a 403"""
     request = MockSuite().mock_request()
     query = MockSuite().mock_sql_queries(request=request, n=1)[0]
     file_path = '/tmp/blah'
     with open(file_path, 'w') as f:
         f.write('test')
     response = self.client.get(silky_reverse('request_sql_detail',
                                        kwargs={'sql_id': query.id, 'request_id': request.id}),
                                data={
                                    'line_num': 0,
                                    'file_path': file_path
                                })
     self.assertTrue(response.status_code == 403)
Ejemplo n.º 28
0
 def test_allowed_file_paths_unavailable_source(self):
     """if we request to view source that is not in the tracebackk we should get a 403"""
     request = MockSuite().mock_request()
     query = MockSuite().mock_sql_queries(request=request, n=1)[0]
     file_path = os.path.realpath(os.path.dirname(os.path.realpath(__file__)) + '/../../django_silky/settings.py')
     with open(file_path, 'r') as f:
         line_num = random.randint(0, len(f.read().split('\n')))
     response = self.client.get(silky_reverse('request_sql_detail',
                                        kwargs={'sql_id': query.id, 'request_id': request.id}),
                                data={
                                    'line_num': line_num,
                                    'file_path': file_path
                                })
     self.assertTrue(response.status_code == 403)
Ejemplo n.º 29
0
 def test_profile_sql_detail(self):
     profile_query_data = random.choice(
         models.Profile.objects.annotate(
             num=Count('queries')).values('id').filter(num__gt=0))
     profile_id = profile_query_data['id']
     sql_id = random.choice(
         models.SQLQuery.objects.filter(profiles=profile_id)).pk
     response = self.client.get(
         silky_reverse('profile_sql_detail',
                       kwargs={
                           'profile_id': profile_id,
                           'sql_id': sql_id
                       }))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 30
0
 def test_allowed_file_paths_unavailable_source(self):
     """if we request to view source that is not in the tracebackk we should get a 403"""
     request = MockSuite().mock_request()
     query = MockSuite().mock_sql_queries(request=request, n=1)[0]
     file_path = '/tmp/blah'
     with open(file_path, 'w') as f:
         f.write('test')
     response = self.client.get(silky_reverse('request_sql_detail',
                                        kwargs={'sql_id': query.id, 'request_id': request.id}),
                                data={
                                    'line_num': 0,
                                    'file_path': file_path
                                })
     self.assertTrue(response.status_code == 403)
Ejemplo n.º 31
0
 def test_allowed_file_paths_available_source(self):
     """if we request to view source that exists in the TB all should be fine"""
     request = MockSuite().mock_request()
     query = MockSuite().mock_sql_queries(request=request, n=1)[0]
     tb = query.traceback_ln_only
     _, files = SQLDetailView()._urlify(tb)
     file_path = random.choice(files)
     with open(file_path, 'r') as f:
         line_num = random.randint(0, len(f.read().split('\n')))
     response = self.client.get(silky_reverse('request_sql_detail',
                                        kwargs={'sql_id': query.id, 'request_id': request.id}),
                                data={
                                    'line_num': line_num,
                                    'file_path': file_path
                                })
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 32
0
 def test_allowed_file_paths_available_source(self):
     """if we request to view source that exists in the TB all should be fine"""
     request = MockSuite().mock_request()
     query = MockSuite().mock_sql_queries(request=request, n=1)[0]
     tb = query.traceback_ln_only
     _, files = SQLDetailView()._urlify(tb)
     file_path = random.choice(files)
     with open(file_path, 'r') as f:
         line_num = random.randint(0, len(f.read().split('\n')))
     response = self.client.get(silky_reverse('request_sql_detail',
                                        kwargs={'sql_id': query.id, 'request_id': request.id}),
                                data={
                                    'line_num': line_num,
                                    'file_path': file_path
                                })
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 33
0
 def test_request_and_profile_sql_detail(self):
     random_profile = random.choice(
         models.Profile.objects.annotate(num=Count('queries'),
                                         profile_id=F('id')).values(
                                             'profile_id',
                                             'request_id').filter(
                                                 request_id__isnull=False,
                                                 num__gt=0))
     random_sql_query = random.choice(
         models.SQLQuery.objects.annotate(
             sql_id=F('id')).values('sql_id').filter(
                 profiles__id=random_profile['profile_id']))
     kwargs = {}
     kwargs.update(random_profile)
     kwargs.update(random_sql_query)
     response = self.client.get(
         silky_reverse('request_and_profile_sql_detail', kwargs=kwargs))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 34
0
 def test_request_and_profile_sql_detail(self):
     random_profile = random.choice(
         models.Profile.objects
         .annotate(num=Count('queries'), profile_id=F('id'))
         .values('profile_id', 'request_id')
         .filter(request_id__isnull=False, num__gt=0)
     )
     random_sql_query = random.choice(
         models.SQLQuery.objects
         .annotate(sql_id=F('id'))
         .values('sql_id')
         .filter(profiles__id=random_profile['profile_id'])
     )
     kwargs = {}
     kwargs.update(random_profile)
     kwargs.update(random_sql_query)
     response = self.client.get(silky_reverse('request_and_profile_sql_detail', kwargs=kwargs))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 35
0
 def test_allowed_file_paths_unavailable_source(self):
     """if we request to view source that is not in the tracebackk we should get a 403"""
     request = MockSuite().mock_request()
     query = MockSuite().mock_sql_queries(request=request, n=1)[0]
     file_path = os.path.realpath(
         os.path.dirname(os.path.realpath(__file__)) +
         '/../../django_silky/settings.py')
     with open(file_path, 'r') as f:
         line_num = random.randint(0, len(f.read().split('\n')))
     response = self.client.get(silky_reverse('request_sql_detail',
                                              kwargs={
                                                  'sql_id': query.id,
                                                  'request_id': request.id
                                              }),
                                data={
                                    'line_num': line_num,
                                    'file_path': file_path
                                })
     self.assertTrue(response.status_code == 403)
Ejemplo n.º 36
0
 def test_profile_detail(self):
     profile_query_data = random.choice(models.Profile.objects.values('id'))
     profile_id = profile_query_data['id']
     response = self.client.get(
         silky_reverse('profile_detail', kwargs={'profile_id': profile_id}))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 37
0
 def test_request_detail(self):
     request_id = random.choice(models.Request.objects.all()).pk
     response = self.client.get(
         silky_reverse('request_detail', kwargs={'request_id': request_id}))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 38
0
 def test_requests(self):
     response = self.client.get(silky_reverse('requests'))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 39
0
 def test_summary(self):
     response = self.client.get(silky_reverse('summary'))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 40
0
 def test_profiling(self):
     response = self.client.get(silky_reverse('profiling'))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 41
0
 def test_profile_detail(self):
     profile_id = random.choice(models.Profile.objects.all()).pk
     response = self.client.get(silky_reverse('profile_detail', kwargs={
         'profile_id': profile_id
     }))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 42
0
 def test_profile_detail(self):
     profile_id = random.choice(models.Profile.objects.all()).pk
     response = self.client.get(
         silky_reverse('profile_detail', kwargs={'profile_id': profile_id}))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 43
0
 def test_request_detail(self):
     request_query_data = random.choice(models.Request.objects.values('id'))
     request_id = request_query_data['id']
     response = self.client.get(
         silky_reverse('request_detail', kwargs={'request_id': request_id}))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 44
0
 def test_profile_sql_detail(self):
     profile_id = random.choice(models.Profile.objects.annotate(num=Count('queries')).values_list('id').filter(num__gt=0))[0]
     sql_id = random.choice(models.SQLQuery.objects.filter(profiles=profile_id)).pk
     response = self.client.get(silky_reverse('profile_sql_detail', kwargs={'profile_id': profile_id,
                                                                           'sql_id': sql_id}))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 45
0
 def test_request_detail(self):
     request_id = random.choice(models.Request.objects.all()).pk
     response = self.client.get(silky_reverse('request_detail', kwargs={
         'request_id': request_id
     }))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 46
0
 def test_profiling(self):
     response = self.client.get(silky_reverse('profiling'))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 47
0
 def test_summary(self):
     response = self.client.get(silky_reverse('summary'))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 48
0
 def test_requests(self):
     response = self.client.get(silky_reverse('requests'))
     self.assertTrue(response.status_code == 200)
Ejemplo n.º 49
0
 def test_allowed_file_paths_nothing_specified(self):
     """by default we dont display any source, and it should return correctly"""
     request = MockSuite().mock_request()
     query = MockSuite().mock_sql_queries(request=request, n=1)[0]
     response = self.client.get(silky_reverse('request_sql_detail', kwargs={'sql_id': query.id, 'request_id': request.id}))
     self.assertTrue(response.status_code == 200)