def test_registering_user_twice_cause_error_msg(self, save_mock):
        # create the request used to test the view
        self.request.session = {}
        self.request.method = 'POST'
        self.request.POST = {}

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

        # mock out stripe so we don't hit their server
        with mock.patch('payments.views.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.assertEqual(resp.content, html.content)
            self.assertEqual(resp.status_code, 200)
            self.assertEqual(self.request.session, {})

            # assert there is no records in the database.
            users = User.objects.filter(email="*****@*****.**")
            self.assertEqual(len(users), 0)
Beispiel #2
0
    def test_registering_user_twice_cause_error_msg(self, save_mock):
        # request used to test the view
        my_request = RequestFactory()
        my_request.method = 'POST'
        my_request.POST = {}
        my_request.session = {}

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

        # mock out stripe to avoid 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(my_request)

            # verify things are okay
            # self.assertEquals(resp.content, html.content)
            # self.assertEqual(resp.status_code, 200)
            # self.assertEqual(my_request.session, {})

            # assert there is no records in the DB
            users = User.objects.filter(email='*****@*****.**')
            self.assertEqual(len(users), 0)
Beispiel #3
0
    def test_registering_user_twice_cause_error_msg(self, save_mock):

        #create the request used to test the view
        self.request.session = {}
        self.request.method = 'POST'
        self.request.POST = {}

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

        #mock out stripe so we don't hit their server
        with mock.patch('payments.views.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.assertEqual(resp.content, html.content)
            self.assertEqual(resp.status_code, 200)
            self.assertEqual(self.request.session, {})

            #assert there is no records in the database.
            users = User.objects.filter(email="*****@*****.**")
            self.assertEqual(len(users), 0)
Beispiel #4
0
    def test_registering_user_twice_cause_error_msg(self, save_mock):

        #create the request used to test the view
        self.request.session = {}
        self.request.method = 'POST'
        self.request.POST = {}

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

        #mock out stripe so we don't hit their server
        with mock.patch('payments.views.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.assertEqual(resp.content, html.content)
            self.assertEqual(resp.status_code, 200)
            self.assertEqual(self.request.session, {})

            #assert there is no records in the database.
            users = User.objects.filter(email="*****@*****.**")
            self.assertEqual(len(users), 0)


# class CustomerTests(TestCase):

#     def test_create_subscription(self):
#         with mock.patch('stripe.Customer.create') as create_mock:
#             cust_data = {'description': 'test user', 'email': '*****@*****.**',
#                          'card': '4242', 'plan': 'gold'}
#             Customer.create("subscription", **cust_data)

#             create_mock.assert_called_with(**cust_data)

#     def test_create_one_time_bill(self):
#         with mock.patch('stripe.Charge.create') as charge_mock:
#             cust_data = {'description': 'email',
#                          'card': '1234',
#                          'amount': '5000',
#                          'currency': 'usd'}
#             Customer.create("one_time", **cust_data)

#             charge_mock.assert_called_with(**cust_data)
Beispiel #5
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)
Beispiel #6
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
	def setUpClass(cls):
		html = render_to_response(
			'payments/register.html',
			{
				'form':UserForm(),
				'months': range(1,13),
				'publishable' : settings.STRIPE_PUBLISHABLE,
				'soon':views.soon(),
				'user':None,
				'years':range(2014, 2036),
			},
		)
		TestViewsMixin.setupClass('/register', html, views.register)
Beispiel #8
0
 def setUpClass(cls):
     html = render_to_response('payments/register.html',
     {
       'form': UserForm(),
       'months': list(range(1, 12)),
       'publishable': settings.STRIPE_PUBLISHABLE,
       'soon': soon(),
       'user': None,
       'years': list(range(2011, 2036)),
     })
     ViewTesterMixin.setupViewTester('/register',
                                     register,
                                     html.content,
                                    )
Beispiel #9
0
 def setUpClass(cls):
     super().setUpClass()
     html = render_to_response(
         "register.html",
         {
             "form": UserForm(),
             "months": list(range(1, 12)),
             "publishable": settings.STRIPE_PUBLISHABLE,
             "soon": soon(),
             "user": None,
             "years": list(range(2011, 2036)),
         },
     )
     ViewTesterMixin.setupViewTester("/register", register, html.content)
Beispiel #10
0
    def setUpTestData(cls):
        cls.url = '/register'
        cls.request = RequestFactory().get(cls.url)

        cls.html = render_to_response(
            'register.html',
            {
                'form': UserForm(),
                'months': range(1, 12),
                'publishable': settings.STRIPE_PUBLISHABLE,
                'soon': soon(),
                'user': None,
                'years': range(2011, 2036),
            }
        )
Beispiel #11
0
 def setUpClass(cls):
     html = render_to_response(
         'register.html', {
             'form': UserForm(),
             'months': range(1, 12),
             'publishable': settings.STRIPE_PUBLISHABLE,
             'soon': soon(),
             'user': None,
             'years': range(2011, 2036),
         })
     ViewTesterMixin.setupViewTester(
         '/register',
         register,
         html.content,
     )
Beispiel #12
0
    def setUpClass(cls):
        super().setUpClass()
        html = render_to_response(
            'register.html',
            {
                 'form':UserForm(),
                 'months':list(range(1,12)),
                 'publishable':settings.STRIPE_PUBLISH,
                 'soon':soon(),
                 'user': None,
                 'years':list(range(2011,2036)),
            },
            )

        ViewTestMixins.setupViewTestr('/register', register, html.content)
Beispiel #13
0
 def setUpClass(cls):
     super(RegisterPageTests,cls).setUpClass()
     html=render_to_response(
     'payments/register.html',
     {
     'form':UserForm(),
     'months':list(range(1,13)),
     'publishable':settings.STRIPE_PUBLISHABLE,
     'soon':soon(),
     'years':list(range(2015,2041))
     }
     )
     ViewTesterMixin.setupViewTester(
     '/register',
     register,
     html.content,
     )
	def test_registering_user_twice_cause_error_msg(self, create_mock):
		
		# create expected html
		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')
		expected_html = render_to_response(
			'payments/register.html',
			{
				'form':expected_form,
				'months': range(1,13),
				'publishable' : settings.STRIPE_PUBLISHABLE,
				'soon':views.soon(),
				'user':None,
				'years':range(2014, 2036),
			},
			#context_instance=RequestContext(self.request)
		)

		# create tested html
		with mock.patch('stripe.Customer') as stripe_mock:
			config = {'create.return_value':mock.Mock()}
			stripe_mock.config_mock(**config)

			response = views.register(self.request)
			

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


		
		# check both htmls are equal
		self.assertEquals(expected_html.content, response.content)