Пример #1
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")
Пример #2
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")
Пример #3
0
def test_index_handles_logged_in_user(self):

	# create user for lookup and index

	from payments.models import User
	user = User(
		name = 'jj',
		email = '*****@*****.**',
		)

	user.save()

	# code snippet

	# verify that the response returns the page for the logged in user
	request_factory = RequestFactory()
	request = request_factory('/')

	# create session that appears to have user logged in
	request.session = {"user" : "1"}

	#request the index page
	resp = index(request)

	# verify it returns the page for the logged in user
	self.assertEquals(
		resp.content, render_to_response('user.html'), {"user" : user}).content



	self.assertTemplateUsed(resp, 'user.htlm')
Пример #4
0
def register(request):
    user = None
    # checks if the http request is POST
    if request.method == 'POST':
        form = UserForm(request.POST)
        # form validation
        if form.is_valid():
            #Uses stripe API to create a customer in stripe
            # update based on your billing method (subscription vs one time)
            # pdb.set_trace()
            customer = stripe.Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                # card=form.cleaned_data['stripe_token'],
                card={
                    'number': '4242424242424242',
                    'exp_month': 10,
                    'exp_year': 2018,
                },
                plan="gold",
            )

            # customer = stripe.Charge.create(
                # description = form.cleaned_data['email'],
                # card = form.cleand_data['stripe_token'],
                # amount = "5000"
                # currency = "usd"
            # )
            user = User(
                name=form.cleaned_data['name'],
                email=form.cleaned_data['email'],
                last_4_digits=form.cleaned_data['last_4_digits'],
                stripe_id=customer.id,
            )
            # set_password takes care of password hasing
            # ensure encrypted password
            user.set_password(form.cleaned_data['password'])

            try:
                user.save()
            except IntegrityError:
                form.addError(user.email + ' is already a member')
            else:
                request.session['user'] = user.pk
                return HttpResponseRedirect('/')
    else:
        form = UserForm()

    return render_to_response(
        'register.html',
        {
            'form': form,
            'months': range(1, 13),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': range(2011, 2037),
        },
        context_instance=RequestContext(request)
    )
Пример #5
0
def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        print("@@@@@@@@@@@@@@@@@@@@@@@@@@@")
        print(request)
        print("@@@@@@@@@@@@@@@@@@@@@@@@@@@")
        print(form)
        if form.is_valid():
            #update based on your billing method (subscription vs one time)
            customer = stripe.Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",

            )
            # customer = stripe.Charge.create(
            #     description = form.cleaned_data['email'],
            #     card = form.cleaned_data['stripe_token'],
            #     amount="5000",
            #     currency="usd"
            # )

            user = User(
                name=form.cleaned_data['name'],
                email=form.cleaned_data['email'],
                last_4_digits=form.cleaned_data['last_4_digits'],
                stripe_id=customer.id,
            )

            #ensure encrypted password
            user.set_password(form.cleaned_data['password'])

            try:
                user.save()
            except IntegrityError:
                form.addError(user.email + ' is already a member')
            else:
                request.session['user'] = user.pk
                return redirect('/')

    else:
        form = UserForm()


    return render(
        request,
        'register.html',
        {
            'form': form,
            'months': range(1, 12),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': range(2011, 2036),
        },
    )
Пример #6
0
def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        print("@@@@@@@@@@@@@@@@@@@@@@@@@@@")
        print(request)
        print("@@@@@@@@@@@@@@@@@@@@@@@@@@@")
        print(form)
        if form.is_valid():
            #update based on your billing method (subscription vs one time)
            customer = stripe.Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",

            )
            # customer = stripe.Charge.create(
            #     description = form.cleaned_data['email'],
            #     card = form.cleaned_data['stripe_token'],
            #     amount="5000",
            #     currency="usd"
            # )

            user = User(
                name=form.cleaned_data['name'],
                email=form.cleaned_data['email'],
                last_4_digits=form.cleaned_data['last_4_digits'],
                stripe_id=customer.id,
            )

            #ensure encrypted password
            user.set_password(form.cleaned_data['password'])

            try:
                user.save()
            except IntegrityError:
                form.addError(user.email + ' is already a member')
            else:
                request.session['user'] = user.pk
                return redirect('/')

    else:
        form = UserForm()


    return render(
        request,
        'register.html',
        {
            'form': form,
            'months': range(1, 12),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': range(2011, 2036),
        },
    )
Пример #7
0
  def test_registering_user_twice_cause_error_msg(self):

    # create a user with same email so we get an integrity error
    user = User(name='test_user', email='*****@*****.**')
    user.save()

    # now create the request used to test the view
    self.request.session = {}
    self.request.method = 'POST'
    self.request.POST = {
        'email': '*****@*****.**',
        'name': 'test_user',
        'stripe_token': '4242424242424242',
        'last_4_digits': '4242',
        'password': '******',
        'ver_password': '******',
    }

    # create our expected form
    expected_form = UserForm(self.request.POST)
    expected_form.is_valid()

    expected_form.addError('[email protected] is already a member')

    # create the expected html
    html = render_to_response(
        'register.html',
        {
          'form': expected_form,
          'months': range(1, 12),
          'publishable': settings.STRIPE_PUBLISHABLE,
          'soon': soon(),
          'user': None,
          'years': range(2011, 2036),
        }
    )

    # mock out stripe so we don't hit their server
    with mock.patch('stripe.Customer') as stripe_mock:
      config = {'create.return_value': mock.Mock()}
      stripe_mock.configure_mock(**config)

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

      # verify that we did things correctly
      self.assertEquals(resp.status_code, 200)
      self.assertEquals(self.request.session, {})

      # assert there is only one record in the database.
      users = User.objects.filter(email='*****@*****.**')
      #self.assertEquals(len(users), 1)

      # check actual return
      self.assertEquals(resp.content, html.content)
Пример #8
0
	def test_registering_user_twice_cause_error_msg(self):

		try:
			with transaction.atomic():

				user = User(name = 'pyRock', email = '*****@*****.**')
				user.save()

				self.request.session = {}
				self.request.method = 'POST'
				self.request.POST = {
					'email': '*****@*****.**',
					'name': 'pyRock',
					'stripe_token': '...',
					'last_4_digits': '4242',
					'password': '******',
					'ver_password': '******',
				}

				expected_form = UserForm(self.request.POST)
				expected_form.is_valid()
				expected_form.addError('[email protected] is already a member')

				html = render_to_response(
					'register.html',
					{
						'form': expected_form,
						'months': list(range(1, 12)),
						'publishable': settings.STRIPE_PUBLISHABLE,
						'soon': soon(),
						'user': None,
						'years': list(range(2011, 2036)),
					}
				)

				with mock.patch('stripe.Customer') as stripe_mock:


					config = {'create.return_value': mock.Mock()}
					stripe_mock.configure_mock(**config)

					resp = register(self.request)
					users = User.objects.filter(email = '*****@*****.**')
					#self.assertEquals(len(users), 1)
					self.assertEqual(resp.status_code, 200)
					self.assertEqual(self.request.session, {})
					


					
					
		except IntegrityError:
			pass
Пример #9
0
def register(request):
    user = None
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():

            # update based on your billing method (subscription vs one time)
            customer = stripe.Customer.create(
                email=form.cleaned_data["email"],
                description=form.cleaned_data["name"],
                card=form.cleaned_data["stripe_token"],
                plan="gold",
            )

            # customer = stripe.Charge.create(
            #   description=form.cleaned_data['email'],
            #  card=form.cleaned_data['stripe_token'],
            # amount="5000",
            # currency="usd"
            # )
            user = User(
                name=form.cleaned_data["name"],
                email=form.cleaned_data["email"],
                last_4_digits=form.cleaned_data["last_4_digits"],
                stripe_id=customer.id,
            )

            # ensure encrypted password
            user.set_password(form.cleaned_data["password"])

            try:
                user.save()
            except IntegrityError:
                form.addError(user.email + " is already a member")
            else:
                request.session["user"] = user.pk
                return HttpResponseRedirect("/")

    else:
        form = UserForm()

    return render_to_response(
        "register.html",
        {
            "form": form,
            "months": range(1, 13),
            "publishable": settings.STRIPE_PUBLISHABLE,
            "soon": soon(),
            "user": user,
            "years": range(2015, 2041),
        },
        context_instance=RequestContext(request),
    )
Пример #10
0
def register(request):
    print "USERFORM = " + str(UserForm)
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():

            # subscription billing

            print "YO!"
            print "STRIPE_PUBLISHABLE = " + str(settings.STRIPE_PUBLISHABLE)
            print "stripe_token = " + form.cleaned_data['stripe_token']
            customer = stripe.Customer.create(
                email=form.cleaned_data['email'],
                description=form.cleaned_data['name'],
                card=form.cleaned_data['stripe_token'],
                plan="gold",
            )

            user = User(
                name=form.cleaned_data['name'],
                email=form.cleaned_data['email'],
                last_4_digits=form.cleaned_data['last_4_digits'],
                stripe_id=customer.id,
            )

            user.set_password(form.cleaned_data['password'])

            try:
                user.save()
            except IntegrityError:
                print "Already a member bro!"
                form.addError(user.email + ' is already a member')
            else:
                print "Save user payment profile"
                request.session['user'] = user.pk
                print request.session['user']
                return HttpResponseRedirect('/')
    else:
        form = UserForm()

    return render_to_response(
        'register.html',
        {
            'form': form,
            'months': range(1, 12),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': range(2011, 2036),
        },
        context_instance=RequestContext(request)
    )
Пример #11
0
 def test_index_handles_logged_in_user(self):
     user = User(
         name='jj',
         email='*****@*****.**',
     )
     user.save()
     self.request.session = {'user': "******"}
     resp = index(self.request)
     self.request.session = {}
     expected_html = render_to_response('user.html',
                                       {'user': user}).content
     self.assertEqual(resp.content, expected_html)
Пример #12
0
 def test_index_handles_logged_in_user(self):
     user = User(
         name='jj',
         email='*****@*****.**',
     )
     user.save()
     self.request.session = {'user': '******'}
     response = index(self.request)
     self.request.session = {}
     expected_html = render(self.request, 'user.html', {
         'user': user
     }).content
     self.assertEquals(response.content, expected_html)
Пример #13
0
	def test_index_handles_logged_in_user(self):
		user=User(name='jj', email = '*****@*****.**',)
		user.save()
		self.request.session={"user":"******"}

		with mock.patch('main.views.User') as user_mock:
			config = {'get.return_value': user}
			user_mock.objects.configure_mock(**config)
			resp = index(self.request)
			self.request.session = {}

			expectedHtml = render_to_response('user.html',{'user':user}).content
			self.assertEquals(resp.content,expectedHtml)
Пример #14
0
def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            
            # Update based on billing method
            customer = stripe.Customer.create(
                            email=form.cleaned_data['email'],
                            description=form.cleaned_data['name'],
                            card=form.cleaned_data['stripe_token'],
                            plan="gold",
                        )
#            customer = stripe.Charge.create(
#                            description=form.cleaned_data['email'],
#                            card=form.cleaned_data['stripe_token']
#                            amount="5000",
#                            currency="usd",
#                        )
            user = User(
                        name=form.cleaned_data['name'],
                        email=form.cleaned_data['email'],
                        last_4_digits=form.cleaned_data['last_4_digits'],
                        stripe_id=customer.id,
                        password=form.cleaned_data['password'],
                    )
            
#            user.set_password(form.cleaned_data['password'])
            
            try:
                user.save()
            except IntegrityError:
                form.addError(user.email + 'is already a member')
            else:
                request.session['user'] = user.pk
                return HttpResponseRedirect('/')
    else:
        form = UserForm()
    
    return render_to_response(
                'register.html',
                {
                    'form': form,
                    'months': range(1, 12),
                    'publishable': settings.STRIPE_PUBLISHABLE,
                    'soon': soon(),
                    'user': user,
                    'years': range(2014, 2039),
                },
                context_instance=RequestContext(request),
            )
Пример #15
0
    def test_index_handles_logged_in_user(self):
	# create the user needed for user lookup from index page
	from payments.models import User
	user = User(
		name = 'jj',
		email='*****@*****.**',
)
	user.save()
	
	#create a Mock request object, so we can manipulate the session
	request_factory  = RequestFactory()
	request = request_factory.get('/')
	request.session= {'user': '******'}
	rep = index(request)
	# verify the response returns the page for the logged in user
	self.assertEqual(rep.content,render_to_response('user.html', {'user': user}).content)
Пример #16
0
    def test_index_handles_logged_in_user(self):
        """
        Verifies the right template is used with a logged user
        """
        # create the user needed for user lookup from index page
        user = User(name='test', email='*****@*****.**')

        # saves user on DB
        user.save()

        # sets session value equals to user ID on DB
        self.request.session = {'user': '******'}

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

        # verify it return the page for the logged in user
        self.assertEquals(resp.content, render_to_response(
            'user.html', {'user': user}).content)
    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")
Пример #18
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")
Пример #19
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}# 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")
Пример #20
0
def register(request):
    user = None
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():

            #update based on your billing method (subscription vs one time)
            customer = stripe.Charge.create(
                description=form.cleaned_data['email'],
                card={
                    'number': '4242424242424242',
                    'exp_month': 10,
                    'exp_year': 2016
                    },
                amount="5000",
                currency="usd"
            )

            # customer = stripe.Charge.create(
            #     description=form.cleaned_data['email'],
            #     card=form.cleaned_data['stripe_token'],
            #     amount="5000",
            #     currency="usd",
            # )

            user = User(
                name=form.cleaned_data['name'],
                email=form.cleaned_data['email'],
                last_4_digits=form.cleaned_data['last_4_digits'],
                stripe_id=customer.id,
            )

            #ensure encrypted password
            user.set_password(form.cleaned_data['password'])

            try:
                user.save()
            except IntegrityError:
                form.addError(user.email + ' is already a member')
            else:
                request.session['user'] = user.pk
                return HttpResponseRedirect('/')

    else:
        form = UserForm()

    c = {
            'form': form,
            'months': range(1, 12),
            'publishable': settings.STRIPE_PUBLISHABLE,
            'soon': soon(),
            'user': user,
            'years': range(2011, 2036),
        }
    c.update(csrf(request))

    return render_to_response(
        'register.html',
        c,
        context_instance=RequestContext(request)
    )