예제 #1
0
파일: tests.py 프로젝트: Supy/sentry
    def test_redirects_to_stream_if_has_groups(self):
        self.login_as(self.user)

        manager = ManagerMock(Group.objects, Group())

        with mock.patch('sentry.models.Group.objects', manager):
            resp = self.client.get(self.path)

        manager.assert_chain_calls(mock.call.filter(project=self.project), )
        manager.exists.assert_called_once_with()

        assert resp.status_code == 302
        assert resp['Location'] == 'http://testserver' + reverse(
            'sentry-stream', args=[self.project.slug])
예제 #2
0
파일: tests.py 프로젝트: allanlei/sentry
    def test_redirects_to_stream_if_has_groups(self):
        self.login_as(self.user)

        manager = ManagerMock(Group.objects, Group())

        with mock.patch('sentry.models.Group.objects', manager):
            resp = self.client.get(self.path)

        manager.assert_chain_calls(
            mock.call.filter(project=self.project),
        )
        manager.exists.assert_called_once_with()

        assert resp.status_code == 302
        assert resp['Location'] == 'http://testserver' + reverse('sentry-stream', args=[self.project.slug])
예제 #3
0
    def test_places(self):
        from ..resources import DataSetResource
        from mock_django.managers import ManagerMock
        from ..models import Place
        place1 = mock.Mock()
        place1.id = 123
        place2 = mock.Mock()
        place2.id = 456
        place_mgr = ManagerMock(Place.objects, place1, place2)
        place_mgr.values.annotate = mock.Mock(return_value=[{
            'dataset_id': 1,
            'length': 2
        }])

        with mock.patch.object(Place, 'objects', place_mgr):
            resource = DataSetResource()
            dataset = mock.Mock()
            dataset.owner.username = '******'
            dataset.slug = 'mock-dataset'
            dataset.id = 1
            assert_equal(
                resource.places(dataset), {
                    'url': '/api/v1/datasets/mock-user/mock-dataset/places/',
                    'length': 2
                })
예제 #4
0
 def submission_sets_empty(self):
     from ..resources import models, PlaceResource
     from mock_django.managers import ManagerMock
     mock_manager = ManagerMock(models.SubmissionSet.objects)
     with mock.patch.object(models.SubmissionSet, 'objects', mock_manager):
         assert_equal(PlaceResource().model.cache.get_submission_sets(0),
                      {})
예제 #5
0
    def test_does_not_reidrect_if_missing_project_permission(
            self, can_create_projects):
        self.login_as(self.user)

        can_create_projects.return_value = False

        manager = ManagerMock(Project.objects)

        with mock.patch('sentry.models.Project.objects', manager):
            resp = self.client.get(self.path)

        can_create_projects.assert_called_once_with(self.user, team=self.team)

        manager.assert_chain_calls(mock.call.filter(team=self.team), )

        assert resp.status_code == 200
        self.assertTemplateUsed(resp, 'sentry/dashboard.html')
예제 #6
0
    def test_does_not_redirect_if_has_projects(self, can_create_projects):
        self.login_as(self.user)

        manager = ManagerMock(Project.objects, self.project)

        with mock.patch('sentry.models.Project.objects', manager):
            resp = self.client.get(self.path)

        assert not can_create_projects.called

        manager.assert_chain_calls(mock.call.filter(team=self.team), )

        assert resp.status_code == 200
        self.assertTemplateUsed(resp, 'sentry/dashboard.html')
        assert resp.context['team'] == self.team
        assert resp.context['project_list'] == [self.project]
        assert resp.context['SECTION'] == 'events'
예제 #7
0
파일: tests.py 프로젝트: flyankur/sentry
    def test_redirects_to_create_project_if_none_and_can_create_projects(self, can_create_projects):
        self.login_as(self.user)

        can_create_projects.return_value = True

        manager = ManagerMock(Project.objects)

        with mock.patch('sentry.models.Project.objects', manager):
            resp = self.client.get(self.path)

        can_create_projects.assert_called_once_with(self.user, team=self.team)

        manager.assert_chain_calls(
            mock.call.filter(team=self.team),
        )

        assert resp.status_code == 302
        assert resp['Location'] == 'http://testserver' + reverse('sentry-new-project', args=[self.team.slug])
예제 #8
0
파일: tests.py 프로젝트: flyankur/sentry
    def test_does_not_redirect_if_has_projects(self, can_create_projects):
        self.login_as(self.user)

        manager = ManagerMock(Project.objects, self.project)

        with mock.patch('sentry.models.Project.objects', manager):
            resp = self.client.get(self.path)

        assert not can_create_projects.called

        manager.assert_chain_calls(
            mock.call.filter(team=self.team),
        )

        assert resp.status_code == 200
        self.assertTemplateUsed(resp, 'sentry/dashboard.html')
        assert resp.context['team'] == self.team
        assert resp.context['project_list'] == [self.project]
예제 #9
0
파일: tests.py 프로젝트: flyankur/sentry
    def test_does_not_reidrect_if_missing_project_permission(self, can_create_projects):
        self.login_as(self.user)

        can_create_projects.return_value = False

        manager = ManagerMock(Project.objects)

        with mock.patch('sentry.models.Project.objects', manager):
            resp = self.client.get(self.path)

        can_create_projects.assert_called_once_with(self.user, team=self.team)

        manager.assert_chain_calls(
            mock.call.filter(team=self.team),
        )

        assert resp.status_code == 200
        self.assertTemplateUsed(resp, 'sentry/dashboard.html')
예제 #10
0
파일: tests.py 프로젝트: gelliravi/sentry
    def test_redirects_to_create_project_if_none_and_can_create_projects(self, can_create_projects):
        self.login_as(self.user)

        can_create_projects.return_value = True

        manager = ManagerMock(Project.objects)

        with mock.patch('sentry.models.Project.objects', manager):
            resp = self.client.get(self.path)

        can_create_projects.assert_called_once_with(self.user, team=self.team)

        manager.assert_chain_calls(
            mock.call.filter(team=self.team),
        )

        assert resp.status_code == 302
        assert resp['Location'] == 'http://testserver' + reverse('sentry-new-project', args=[self.team.slug])
예제 #11
0
    def test_call_tracking(self):
        # only works in >= mock 0.8
        manager = make_manager()
        inst = ManagerMock(manager, 'foo')

        inst.filter(foo='bar').select_related('baz')

        calls = inst.mock_calls

        self.assertGreater(len(calls), 1)
        inst.assert_chain_calls(mock.call.filter(foo='bar'))
        inst.assert_chain_calls(mock.call.select_related('baz'))
예제 #12
0
    def test_call_tracking(self):
        # only works in >= mock 0.8
        manager = make_manager()
        inst = ManagerMock(manager, 'foo')

        inst.filter(foo='bar').select_related('baz')

        calls = inst.mock_calls

        self.assertGreater(len(calls), 1)
        inst.assert_chain_calls(mock.call.filter(foo='bar'))
        inst.assert_chain_calls(mock.call.select_related('baz'))
예제 #13
0
파일: tests.py 프로젝트: Supy/sentry
class DashboardTest(TestCase):
    @fixture
    def path(self):
        return reverse('sentry', args=[self.project.id])

    def test_requires_authentication(self):
        self.assertRequiresAuthentication(self.path)

    def test_redirects_to_getting_started_if_no_groups(self):
        self.login_as(self.user)

        manager = ManagerMock(Group.objects)

        with mock.patch('sentry.models.Group.objects', manager):
            resp = self.client.get(self.path)

        manager.assert_chain_calls(mock.call.filter(project=self.project), )
        manager.exists.assert_called_once_with()

        assert resp.status_code == 302
        assert resp['Location'] == 'http://testserver' + reverse(
            'sentry-get-started', args=[self.project.slug])

    @mock.patch('sentry.models.Group.objects',
                ManagerMock(Group.objects, Group()))
    def test_redirects_to_stream_if_has_groups(self):
        self.login_as(self.user)

        manager = ManagerMock(Group.objects, Group())

        with mock.patch('sentry.models.Group.objects', manager):
            resp = self.client.get(self.path)

        manager.assert_chain_calls(mock.call.filter(project=self.project), )
        manager.exists.assert_called_once_with()

        assert resp.status_code == 302
        assert resp['Location'] == 'http://testserver' + reverse(
            'sentry-stream', args=[self.project.slug])
예제 #14
0
    def test_get_on_singular_list(self):
        manager = make_manager()
        inst = ManagerMock(manager, 'foo')

        self.assertEquals(inst.get(), 'foo')
예제 #15
0
    def test_get_on_singular_list(self):
        manager = make_manager()
        inst = ManagerMock(manager, 'foo')

        self.assertEquals(inst.get(), 'foo')
예제 #16
0
 def test_returns_self(self):
     manager = make_manager()
     inst = ManagerMock(manager, 'foo')
     self.assertEquals(inst.all(), inst)
예제 #17
0
 def test_getitem(self):
     manager = make_manager()
     inst = ManagerMock(manager, 'foo')
     self.assertEquals(inst.all()[0], 'foo')
예제 #18
0
 def test_iter_exception(self):
     manager = make_manager()
     inst = ManagerMock(manager, Exception())
     self.assertRaises(Exception, list, inst.all())
예제 #19
0
 def test_iter(self):
     manager = make_manager()
     inst = ManagerMock(manager, 'foo')
     self.assertEquals(list(inst.all()), ['foo'])
예제 #20
0
 def test_get_raises_doesnotexist_with_queryset(self):
     manager = make_manager()
     inst = ManagerMock(manager)
     queryset = inst.using('default.slave')[0:1]
     self.assertRaises(manager.model.DoesNotExist, queryset.get)
예제 #21
0
 def test_getitem_get(self):
     manager = make_manager()
     inst = ManagerMock(manager, 'foo')
     self.assertEquals(inst[0:1].get(), 'foo')
예제 #22
0
    def test_get_raises_doesnotexist(self):
        manager = make_manager()
        inst = ManagerMock(manager)
        inst.model.DoesNotExist = Exception

        self.assertRaises(inst.model.DoesNotExist, inst.get)
예제 #23
0
 def test_get_matching_synonims(self):
     UnitedGeoName.objects = ManagerMock(UnitedGeoName,  UnitedGeoName(country='Lithuania'))
     result = self.plugin.get_matching_synonyms(None, None, None, None, 'Minsk')
     self.assertEquals(result[0].country, 'Lithuania')
예제 #24
0
 def test_get_raises_doesnotexist_with_queryset(self):
     manager = make_manager()
     inst = ManagerMock(manager)
     queryset = inst.using('default.slave')[0:1]
     self.assertRaises(manager.model.DoesNotExist, queryset.get)
예제 #25
0
 def test_iter(self):
     manager = make_manager()
     inst = ManagerMock(manager, 'foo')
     self.assertEquals(list(inst.all()), ['foo'])
예제 #26
0
 def test_getitem(self):
     manager = make_manager()
     inst = ManagerMock(manager, 'foo')
     self.assertEquals(inst.all()[0], 'foo')
예제 #27
0
 def test_iter_exception(self):
     manager = make_manager()
     inst = ManagerMock(manager, Exception())
     self.assertRaises(Exception, list, inst.all())
예제 #28
0
 def test_returns_self(self):
     manager = make_manager()
     inst = ManagerMock(manager, 'foo')
     self.assertEquals(inst.all(), inst)
예제 #29
0
    def test_get_on_multiple_objects(self):
        manager = make_manager()
        inst = ManagerMock(manager, 'foo', 'bar')
        inst.model.MultipleObjectsReturned = Exception

        self.assertRaises(inst.model.MultipleObjectsReturned, inst.get)