from django.test import RequestFactory
from nose.tools import *  # flake8: noqa

from tests.base import AdminTestCase
from tests.factories import UserFactory
from admin_tests.utilities import setup_view

from admin.users.views import UserView


class TestUserView(AdminTestCase):

    def test_no_guid(self):
        request = RequestFactory().get('/fake_path')
        view = UserView()
        view = setup_view(view, request)
        with assert_raises(AttributeError):
            view.get_object()

    def test_load_data(self):
        user = UserFactory()
        guid = user._id
        request = RequestFactory().get('/fake_path')
        view = UserView()
        view = setup_view(view, request, guid=guid)
        res = view.get_object()
        assert_is_instance(res, dict)

    def test_name_data(self):
        user = UserFactory()
        guid = user._id
        request = RequestFactory().get('/fake_path')
        view = UserView()
        view = setup_view(view, request, guid=guid)
        temp_object = view.get_object()
        view.object = temp_object
        res = view.get_context_data()
        assert_equal(res[UserView.context_object_name], temp_object)

@@ -72,16 +72,28 @@
 e8: noqa
+%0Aimport mock
 %0A%0Afrom t
@@ -158,24 +158,41 @@
  UserFactory
+, AuthUserFactory
 %0Afrom admin_
@@ -264,16 +264,33 @@
 UserView
+, remove_2_factor
 %0A%0A%0Aclass
@@ -1219,12 +1219,1467 @@
 emp_object)%0A
+%0A    @mock.patch('admin.users.views.User.delete_addon')%0A    def test_remove_two_factor_get(self, mock_delete_addon):%0A        user = UserFactory()%0A        guid = user._id%0A        request = RequestFactory().get('/fake_path')%0A        remove_2_factor(request, guid)%0A        assert_equal(mock_delete_addon.call_args_list, %5B%5D)%0A%0A    @mock.patch('admin.users.views.User.delete_addon')%0A    def test_remove_two_factor_post(self, mock_delete_addon):%0A        user = UserFactory()%0A        guid = user._id%0A        request = RequestFactory().post('/fake_path')%0A        remove_2_factor(request, guid)%0A        mock_delete_addon.assert_called_with('twofactor')%0A%0A    @mock.patch('admin.users.views.User.delete_addon')%0A    def test_remove_two_factor_delete(self, mock_delete_addon):%0A        user = UserFactory()%0A        guid = user._id%0A        request = RequestFactory().delete('/fake_path')%0A        remove_2_factor(request, guid)%0A        mock_delete_addon.assert_called_with('twofactor')%0A%0A    def test_integration_delete_two_factor(self):%0A        user = AuthUserFactory()%0A        guid = user._id%0A        user_addon = user.get_or_add_addon('twofactor')%0A        assert_not_equal(user_addon, None)%0A        user_settings = user.get_addon('twofactor')%0A        assert_not_equal(user_settings, None)%0A        request = RequestFactory().post('/fake_path')%0A        remove_2_factor(request, guid)%0A        post_addon = user.get_addon('twofactor')%0A        assert_equal(post_addon, None)%0A

Add tests