def test__set_django_attributes_no_user(self): from opencensus.ext.django.middleware import \ _set_django_attributes span = self.Span() request = mock.Mock() request.user = None _set_django_attributes(span, request) expected_attributes = {} self.assertEqual(span.attributes, expected_attributes)
def test__set_django_attributes_no_user_info(self): from opencensus.ext.django.middleware import \ _set_django_attributes span = self.Span() request = mock.Mock() django_user = mock.Mock() request.user = django_user django_user.pk = None django_user.get_username.return_value = None _set_django_attributes(span, request) expected_attributes = {} self.assertEqual(span.attributes, expected_attributes)
def test__set_django_attributes_with_user_info(self): from opencensus.ext.django.middleware import \ _set_django_attributes span = self.Span() request = mock.Mock() django_user = mock.Mock() request.user = django_user test_id = 123 test_name = 'test_name' django_user.pk = test_id django_user.get_username.return_value = test_name _set_django_attributes(span, request) expected_attributes = { 'django.user.id': '123', 'django.user.name': test_name} self.assertEqual(span.attributes, expected_attributes)