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])
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])
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 })
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), {})
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')
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'
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])
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]
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')
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'))
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])
def test_get_on_singular_list(self): manager = make_manager() inst = ManagerMock(manager, 'foo') self.assertEquals(inst.get(), 'foo')
def test_returns_self(self): manager = make_manager() inst = ManagerMock(manager, 'foo') self.assertEquals(inst.all(), inst)
def test_getitem(self): manager = make_manager() inst = ManagerMock(manager, 'foo') self.assertEquals(inst.all()[0], 'foo')
def test_iter_exception(self): manager = make_manager() inst = ManagerMock(manager, Exception()) self.assertRaises(Exception, list, inst.all())
def test_iter(self): manager = make_manager() inst = ManagerMock(manager, 'foo') self.assertEquals(list(inst.all()), ['foo'])
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)
def test_getitem_get(self): manager = make_manager() inst = ManagerMock(manager, 'foo') self.assertEquals(inst[0:1].get(), 'foo')
def test_get_raises_doesnotexist(self): manager = make_manager() inst = ManagerMock(manager) inst.model.DoesNotExist = Exception self.assertRaises(inst.model.DoesNotExist, inst.get)
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')
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)