def test_returns_appropriate_html_response_code(self):
            """TODO: Docstring for test_returns_appropriate_html_response_code.
            :returns: TODO

            """
            resp = index(self.request)
            self.assertEqual(resp.status_code, 200)
 def test_returns_exact_html(self):
     resp=index(self.request)
     self.assertEquals(
     resp.content,
     render_to_response('main/index.html',
     {'markerting_items': market_items}).content
     )
Exemple #3
0
    def test_index_handles_logged_in_user(self):
        #create a session that appears to have a logged in user
        self.request.session = {"user": "******"}

        #setup dummy user
        #we need to save user so user -> badges relationship is created
        u = User(email="*****@*****.**")
        u.save()

        with mock.patch('main.views.User') as user_mock:

            #tell the mock what to do when called
            config = {'get_by_id.return_value': u}
            user_mock.configure_mock(**config)

            #run the test
            resp = index(self.request)

            #ensure we return the state of the session back to normal
            self.request.session = {}
            u.delete()

            #we are now sending a lot of state for logged in users, rather than
            #recreating that all here, let's just check for some text
            #that should only be present when we are logged in.
            self.assertContains(resp, "Report back to base")
    def test_index_handles_logged_in_user(self):
        #create a session that appears to have a logged in user
        self.request.session = {"user": "******"}

        #setup dummy user
        #we need to save user so user -> badges relationship is created
        u = User(email="*****@*****.**")
        u.save()

        with mock.patch('main.views.User') as user_mock:

            #tell the mock what to do when called
            config = {'get_by_id.return_value': u}
            user_mock.configure_mock(**config)

            #run the test
            resp = index(self.request)

            #ensure we return the state of the session back to normal
            self.request.session = {}
            u.delete()

            #we are now sending a lot of state for logged in users, rather than
            #recreating that all here, let's just check for some text
            #that should only be present when we are logged in.
            self.assertContains(resp, "Report back to base")
Exemple #5
0
 def test_index_view_has_correct_html(self):
     request = HttpRequest()
     response = index(request)
     html = response.content.decode('utf8')
     self.assertIn('A:', html)
     self.assertIn('B:', html)
     self.assertIn('A + B =', html)
 def test_returns_exact_html (self):
     market_items = MarketingItem.objects.all()
     resp = index(self.request)
     self.assertEqual(resp.content,
                      render_to_response("main/index.html",
                                         {"marketing_items":market_items})
                      .content)
 def test_returns_exact_html(self):
     resp = index(self.request)
     self.assertEqual(
         resp.content,
         render_to_response("main/index.html", {
             "marketing_items": market_items
         }).content)
 def test_returns_exact_html(self):
     data = [MarketingItem(**d) for d in init_marketing_data]
     resp = index(self.request)
     self.assertEqual(
         resp.content,
         render_to_response("main/index.html", {
             "marketing_items": data
         }).content)
 def test_returns_exact_html(self):
     #market_items = MarketingItem.objects.all()
     data = [MarketingItem(**d) for d in init_marketing_data]
     resp= index(self.request)
     self.assertEqual(
         resp.content,
         render_to_response('main/index.html',
             {'marketing_items': data}).content
             )
Exemple #10
0
 def test_returns_exact_html(self):
     data = [MarketingItem(**d) for d in init_marketing_data]
     resp = index(self.request)
     self.assertEqual(
         resp.content,
         render_to_response(
             "main/index.html",
             {"marketing_items": data}
         ).content
     )
        def test_returns_exact_html(self):
            """TODO: Docstring for test_returns_exact_html.
            :returns: TODO

            """
            resp = index(self.request)
            self.assertEqual(
                resp.content,
                render_to_response('index.html').content
            )
 def test_signout_user_mock(self):
     self.request.session = {"user": "******"}
     
     with mock.patch("main.views.User") as user_mock:
         config = {'get_by_id.return_value': mock.Mock()}
         user_mock.configure_mock(**config)
         resp = index(self.request)
         #self.request.session = {}
         resp.session = {'user': '******'}
         del resp.session['user']
         main_page = resolve('/')
         self.assertEqual(main_page.func, index)
    def test_index_handles_logged_in_user(self):
        # Create a session that appears to have a logged in user
        self.request.session = {"user": "******"}

        with mock.patch("main.views.User") as user_mock:
            # Tell the mock what to do when called
            config = {"get_by_id.return_value": mock.Mock()}
            user_mock.configure_mock(**config)
            # Run the test
            resp = index(self.request)
            # ensure we return the state of the session back to normal so
            # we don't affect other test
            self.request.session = {}
            # verify it returns the page for the logged in user
            expectedHtml = render_to_response("main/user.html", {"user": user_mock.get_by_id(1)})
            self.assertEquals(resp.content, expectedHtml.content)
Exemple #14
0
def register(request):
    if request.method == 'POST':
        user_form = FXCreateUserForm(request.POST)
        logging.info(user_form)
        logging.info(user_form.is_valid())

        if user_form.is_valid():
            user_form.save()
            username = user_form.cleaned_data['username']
            password = user_form.cleaned_data['password1']
            new_user = authenticate(username=username, password=password)
            login(request, new_user)
            return HttpResponseRedirect('/accounts/home')
        else:
            return render(request, 'main/index.html', dict(form=user_form))

    return index(request)
Exemple #15
0
 def test_user_can_log_in(self):
     from payments.models import User
     
     user = User(name='jj',
                 email='*****@*****.**',
                 )
     
     self.request.session = {"user":"******"}
     
     with mock.patch('main.views.User') as user_mock:
         config={'get_user_by_id.return_value':user}
         user_mock.objects.configure_mock(**config)
     
         resp= index(self.request)
     
         self.request.session = {}
         
         self.assertTemplateUsed(resp, 'user.html')
Exemple #16
0
    def  test_index_handles_logged_in_user(self):
        #create a session that appears to have a logged in user
        self.request.session = {"user" : "1"}
        
        import mock
        with mock.patch('main.views.User') as user_mock:
            
            #tell the mock what to do when called
            config = {'get_by_id.return_value':mock.Mock()}
            user_mock.configure_mock(**config)

            #run the test
            resp = index(self.request)

            #ensure we return the state of the session back to normal 
            self.request.session = {}
           
            expected_html = render_to_response('user.html',{'user': user_mock.get_by_id(1)})
            self.assertEquals(resp.content, expected_html.content)
    def test_index_handles_logged_in_user(self):
        #create a session that appears to have a logged in user
        self.request.session = {"user": "******"}		
		
        with mock.patch('main.views.User') as user_mock:

            # Tell the mock what to do when called
            config = {'get_by_id.return_value': mock.Mock()}
            user_mock.objects.configure_mock(**config)
			
		    # Run the test as normal
            resp = index(self.request)
		
            self.request.session = {}		
		
            #verify it returns the page for the logged in user
            expected_html = render_to_response('user.html', {'user': user_mock.get_by_id(1)})
            self.assertEqual(resp.content, expected_html.content)
			
    def test_index_handles_logged_in_user(self):
        # Create a session that appears to have a logged in user
        self.request.session = {"user": "******"}

        with mock.patch('main.views.User') as user_mock:

            # Tell the mock what to do when called
            config = {'get_by_id.return_value': mock.Mock()}
            user_mock.configure_mock(**config)

            # Run the test
            resp = index(self.request)

            # Ensure we return the state of the session back to normal
            self.request.session = {}

            expected_html = render_to_response(
                'main/user.html', {'user': user_mock.get_by_id(1)})
            self.assertEquals(resp.content, expected_html.content)
Exemple #19
0
def process_view(request, **kwargs):
    """
    process each app view
    :param request:
    :param kwargs:
    :return:
    """
    app = kwargs.get('app', None)
    if app is None:
        return index(request)
    try:
        viewObj = importlib.import_module("%s.views" % app)
        funcObj = getattr(viewObj, 'index')
        return funcObj(request)
    except (ImportError, AttributeError) as e:
        return HttpResponse(e)
        # return HttpResponseNotFound()
    except Exception as e:
        return HttpResponse(e)
Exemple #20
0
    def test_index_handles_logged_in_user(self):
        # Create a session that appears to have a logged in user
        self.request.session = {"user": "******"}
        u = User(email="*****@*****.**")
        u.save()

        with mock.patch('main.views.User') as user_mock:

            # Tell the mock what to do when called
            config = {'get_by_id.return_value': u}
            user_mock.configure_mock(**config)

            # Run the test
            resp = index(self.request)

            # Ensure we return the state of the session back to normal
            self.request.session = {}
            u.delete()

            self.assertContains(resp, "Report back to base")
    def test_index_handles_logged_in_user(self):
        # Create a session that appears to have a logged in user
        self.request.session = {"user": "******"}
        u = User(email="*****@*****.**")
        u.save()

        with mock.patch('main.views.User') as user_mock:

            # Tell the mock what to do when called
            config = {'get_by_id.return_value': u}
            user_mock.configure_mock(**config)

            # Run the test
            resp = index(self.request)

            # Ensure we return the state of the session back to normal
            self.request.session = {}
            u.delete()

            self.assertContains(resp, "Report back to base")
Exemple #22
0
def process_logic(request, **kwargs):
    """
    process business logic
    :param request:
    :param kwargs:
    :return:
    """
    app = kwargs.get('app', None)
    path = kwargs.get('path', None)
    module = kwargs.get('module', None)
    try:
        fullPath = "%s.%s.%s" % (app, path, module)
        moduleObj = importlib.import_module(fullPath)
        funcObj = getattr(moduleObj, 'index')
        return funcObj(request)
    except (ImportError, AttributeError) as e:
        print(e)
        return HttpResponseNotFound()
    except Exception as e:
        print(e)
        return index(request)
    def test_index_handles_logged_in_user(self):
        # create a session that appears to have a logged in user
        self.request.session = {'user': "******"}

        with mock.patch('main.views.User') as user_mock:

            # Tell the mock what to do when called
            config = {'get_by_id.return_value': mock.Mock()}
            user_mock.configure_mock(**config)

            # request the index page
            resp = index(self.request)

            # ensure we return the state of the session back to normal so we
            # don't affect other tests
            self.request.session = {}

            # verify it returns the page for the logged-in user
            expectedHtml = render_to_response(
                'user.html', {'user': user_mock.get_by_id(1)})
            self.assertEqual(resp.content, expectedHtml.content)
        def test_index_handlers_logged_in_user(self):
            """TODO: Docstring for test_index_handlers_logged_in_user.
            :returns: TODO

            """
            self.request.session = {'user': '******'}

            with mock.patch('main.views.User') as user_mock:
                # Tell the mock what to do when called
                config = {'get_by_id.return_value': mock.Mock()}
                user_mock.configure_mock(**config)

                # Run the test
                resp = index(self.request)

                # Enshure we return the state of the session back to normal
                self.request.session = {}
                expected_html = render_to_response(
                    'user.html', {'user': user_mock.get_by_id(1)}
                )
                self.assertEqual(resp.contetn, expected_html.content)
Exemple #25
0
	def test_index_handles_logged_in_user(self):
		#user.save() #commit to db, if using mock we don't need to save to db
		self.request.session = {"user": "******"}

		with mock.patch('main.views.User') as user_mock:
			#When we come across the User obj in main.views, 
			#call our mock_object instead of the real one

			#Tell mock what to do when called:
			#When get is called on our User.objects mock, just return our dummy user
			config = {'get_by_id.return_value': mock.Mock()}
			user_mock.objects.configure_mock(**config)

			#request the index page----> call the index func
			resp = index(self.request)
			self.request.session = {} #return the session back to normal so it won't affect other tests

			#verify the return of the user.html page
			expected_html = render_to_response('user.html', 
				{'user': user_mock.get_by_id(1)}
			)
			self.assertEqual(resp.content, expected_html.content)
Exemple #26
0
def submit_spotted(request):
    """Submit Spotted

    User submitted a spotted
    """

    if request.method == 'POST':
        form = PendingSpottedForm(request.POST)

        if form.is_valid():
            instance = form.save(request.user)

            # Send to API
            if api_process_new_post(instance):
                messages.add_message(request, messages.SUCCESS,
                                     'Spotted enviado para moderação!')
                form = PendingSpottedForm()
            else:
                messages.add_message(request, messages.ERROR,
                                     'Oops! Erro na comunicação com a API!')
    else:
        form = PendingSpottedForm()
    return index(request, spottedform=form)
    def test_index_handles_logged_in_user(self):
         # Create a session that appears to have a logged in user
        self.request.session={'user':'******'}
        #setup dummy user
        #we need to save user so user -> badges relationship is created
        u=User(email="*****@*****.**")
        u.save()

        with mock.patch('main.views.User') as user_mock:
        # Tell the mock what to do when called
            config = {'get_by_id.return_value': u}# mock.Mock()}
            user_mock.configure_mock(**config)
             #Run the test
            resp=index(self.request)
            #ensure we return the state of the session back to normal so
           #we don't affect other test
            self.request.session={}
           #verify it returns the page for the logged in user
            # expectedHtml = render_to_response(
            # 'main/user.html', {'user': user_mock.get_by_id(1)})
            u.delete()

            #self.assertEquals(resp.content, expectedHtml.content)
            self.assertContains(resp,"Report back to base")
	def test_index_handles_logged_in_user(self):
		# create user needed for user lookup index page
		 
		
		#create a session that  appears to have a logged in user
		self.request.session = {'user':'******'}

		with mock.patch('main.views.User') as user_mock:

			# Tell mock what to do when get called
			config = {'get_by_id.return_value': mock.Mock()}
			user_mock.objects.configure_mock(**config)
			
			#request the index page
			resp = index(self.request)

			#drop the session so we not compromise
			#other tests
			self.request.session = {}

			#verify it returns the  page for logged in user
			expectedHtml = render_to_response('main/user.html', 
				{'user':user_mock.get_by_id(1)}).content
			self.assertEquals(resp.content, expectedHtml)
Exemple #29
0
    def test_index_handles_logged_in_user(self):
        # # Create the user needed for user lookup from index page
        # # Note that we are not saving to the database
        # user = User(
        # name='jj',
        # email='*****@*****.**',
        # )
        # # Create a session that appears to have a logged in user
        self.request.session={'user':'******'}

        with mock.patch('main.views.User') as user_mock:
        # Tell the mock what to do when called
            #config = {'get.return_value': user}
            config = {'get_by_id.return_value': mock.Mock()}
            user_mock.configure_mock(**config)
             #Run the test
            resp=index(self.request)
            #ensure we return the state of the session back to normal so
           #we don't affect other test
            self.request.session={}
           #verify it returns the page for the logged in user
            expectedHtml = render_to_response(
            'user.html', {'user': user_mock.get_by_id(1)})
            self.assertEquals(resp.content, expectedHtml.content)
 def test_returns_exact_html(self):
     resp=index(self.request)
     self.assertEquals(
     resp.content,
     render_to_response('index.html').content
     )
 def test_returns_appropriate_html_response_code(self):
     resp=index(self.request)
     self.assertEquals(resp.status_code,200)
Exemple #32
0
	def test_returns_appropiate_html(self):
		resp = index(self.request) #get() return  the appropiate html
		self.assertEqual(resp.status_code, 200) #check only the status_code
Exemple #33
0
def user_logout(request):
    logout(request)
    return main_views.index(request)
    def test_root_resolves_to_main_view(self ):
        main_page = resolve('/')
        self.assertEqual(main_page.func, index)

    def test_returns_appropriate_html_respos_code(self):
        resp = index(self.request)
        self.assertEqual(resp.status_code,200)

    def test_returns_exact_html (self):
<<<<<<< HEAD
        market_items = Marketing_items.objects.all()
=======
        market_items = MarketingItem.objects.all()
>>>>>>> abe8bb86f1cf84d3b030cc1e77193d2909d60e28
        resp = index(self.request)
        self.assertEqual(resp.content,
                         render_to_response("main/index.html",
                                            {"marketing_items":market_items})
                         .content)

    def  test_index_handles_logged_in_user(self):
        #create a session that appears to have a logged in user
        self.request.session = {"user" : "1"}
        
        #setup dummy user
        #we need to save user so user -> badges relationship is created
        u = User(email="*****@*****.**")
        u.save()

        import mock
Exemple #35
0
	def test_returns_exact_html(self):
		resp = index(self.request)
		self.assertEqual(
			resp.content, #html of index 
			render_to_response("index.html").content #html of index.html template
		)
Exemple #36
0
 def test_returns_exact_html(self):
     resp = index(self.request)
     self.assertEqual(resp.content,
                      render_to_response("index.html").content)
 def test_returns_appropriate_html_response_code(self):
     resp = index(self.request)
     self.assertEquals(resp.status_code, 200)
Exemple #38
0
 def test_return_right_html(self):
     main_page = index(self.request)
     self.assertEqual(main_page.content,
                      render_to_response("index.html").content)
Exemple #39
0
 def test_user_html_template(self):
     main_page = index(self.request)
     self.assertTemplateUsed(main_page, 'index.html')
Exemple #40
0
 def test_return_appririate_html(self):
     main_page = index(self.request)
     self.assertEqual(main_page.status_code, 200)