Ejemplo n.º 1
0
    def test_create_submerchant_fail_duplicate_submerchant(self):
        with app.app_context():
            data = {
                'user_id': self.test_id,
                'individual': {
                    'first_name': 'Ian',
                    'last_name': 'Clark',
                    'email': '*****@*****.**',
                    'phone': '8303437773',
                    'date_of_birth': '06/29/1992',
                    'address': {
                        'street_address': '1024 Road',
                        'locality': 'Madison',
                        'region': 'WI',
                        'postal_code': '78028',
                    }
                },
                'funding': {
                    'descriptor': 'Wells Fargo',
                    'destination': 'My Company Name',
                    'account_number': '1123581321',
                    'routing_number': '071101307',
                },
                'tos_accepted': True,
                'register_as_business': False
            }

            response = self.test_client.post(
                '/braintree/{0}/submerchant'.format(self.test_id),
                content_type='application/json',
                data=json.dumps(data),
                headers={'jwt': create_token(self.test_id, app.config)},
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertIsNotNone(response)

            response = json.loads(str(response.data.decode('utf-8')))
            self.assertTrue(response['success'])

            response = self.test_client.post(
                '/braintree/{0}/submerchant'.format(self.test_id),
                content_type='application/json',
                data=json.dumps(data),
                headers={'jwt': create_token(self.test_id, app.config)},
            )

            self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)
            self.assertIsNotNone(response)

            response = json.loads(str(response.data.decode('utf-8')))
            self.assertTrue(response['msg'],
                            'You already have a submerchant account created.')
Ejemplo n.º 2
0
    def test_create_subscription_no_preixisting_user(self, mock_sub,
                                                     mock_cust):
        mock_sub.return_value = MockSubSuccess()
        mock_cust.return_value = MockSubSuccess()

        with app.app_context():
            data = {
                'nonce': 'test-nonce',
                'first_name': 'test-first',
                'last_name': 'test-last',
            }

            response = self.test_client.post(
                '/braintree/{0}/subscriptions'.format(
                    self.test_id_wo_customer, ),
                headers={
                    'jwt': create_token(self.test_id_wo_customer, app.config)
                },
                data=json.dumps(data),
                content_type='application/json',
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertIsNotNone(response)
            response = json.loads(str(response.data.decode('utf-8')))
    def test_get_events_with_offset(self):
        with app.app_context():
            new_event = Event(
                datetime.utcnow() + timedelta(days=-90, minutes=-60),
                datetime.utcnow() + timedelta(days=-90, minutes=0),
                self.scheduling_uid,
                self.scheduled_uid
            )
            new_event.total_price = 5.00
            db.session.add(new_event)
            db.session.commit()

            response = self.test_client.get(
                '/event/{0}/{1}?time_period_offset=3'.format(
                    self.scheduling_uid,
                    str(new_event.public_id)
                ),
                headers={'jwt': create_token(self.scheduling_uid, app.config)}
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertIsNotNone(response)
            response = json.loads(str(response.data.decode('utf-8')))
            self.assertEqual(
                new_event.public_id,
                response['event']['public_id']
            )
    def test_put_user_preferences(self):
        with app.app_context():
            data = {
                'current_password': '******',
                'plaintext_password': '******',
                'email': '*****@*****.**',
                'five_min_price': 5.0,
                'fifteen_min_price': 5.0,
                'thirty_min_price': 5.0,
                'sixty_min_price': 5.0,
            }

            response = self.test_client.put(
                '/users/{0}/preferences'.format(self.test_uid),
                content_type='application/json',
                data=json.dumps(data),
                headers={'jwt': create_token(self.test_uid, app.config)},
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertIsNotNone(response)

            user_info = db.session.query(User).filter_by(
                public_id=self.test_uid
            ).first()

            self.assertIsNotNone(user_info)

            self.assertEqual(user_info.email, '*****@*****.**')
            self.assertEqual(user_info.five_min_price, 5.0)
            self.assertEqual(user_info.fifteen_min_price, 5.0)
            self.assertEqual(user_info.thirty_min_price, 5.0)
            self.assertEqual(user_info.sixty_min_price, 5.0)
    def test_post(self):
        with app.app_context():
            data = {
                'email': '*****@*****.**',
                'username': '******',
                'plaintext_password': '******',
                'local_tz': 'US/Central'
            }

            response = self.test_client.post(
                '/users/'.format(self.test_uid),
                content_type='application/json',
                data=json.dumps(data),
                headers={'jwt': create_token(self.test_uid, app.config)},
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertIsNotNone(response)

            response = json.loads(str(response.data.decode('utf-8')))
            self.assertEqual(response['email'], data['email'])
            self.assertEqual(response['username'], data['username'])

            found_user = db.session.query(User).filter_by(
                public_id=response['user_id']
            ).first()

            self.assertIsNotNone(found_user)
    def test_get_fail_deleted_account(self):
        with app.app_context():
            response = self.test_client.get(
                '/users/{0}'.format(self.deleted_uid),
                headers={'jwt': create_token(self.deleted_uid, app.config)},
            )

            self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
    def test_get_fail_invalid_user_id(self):
        with app.app_context():
            response = self.test_client.get(
                '/users/{0}'.format(self.test_uid + 'alskdjflaksjd'),
                headers={'jwt': create_token(self.test_uid + 'alskdjflaksjd', app.config)},
            )

            self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
Ejemplo n.º 8
0
    def test_webhook_submerchant_approved(self):
        with app.app_context():
            data = {
                'user_id': self.test_id,
                'individual': {
                    'first_name': 'Ian',
                    'last_name': 'Clark',
                    'email': '*****@*****.**',
                    'phone': '8303437773',
                    'date_of_birth': '06/29/1992',
                    'address': {
                        'street_address': '1024 Road',
                        'locality': 'Madison',
                        'region': 'WI',
                        'postal_code': '78028',
                    }
                },
                'funding': {
                    'descriptor': 'Wells Fargo',
                    'destination': 'My Company Name',
                    'account_number': '1123581321',
                    'routing_number': '071101307',
                },
                'tos_accepted': True,
                'register_as_business': False
            }

            response = self.test_client.post(
                '/braintree/{0}/submerchant'.format(self.test_id),
                content_type='application/json',
                data=json.dumps(data),
                headers={'jwt': create_token(self.test_id, app.config)},
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertIsNotNone(response)

            submerchant = db.session.query(Submerchant).first()

            notify = WebhookTesting.sample_notification(
                WebhookNotification.Kind.SubMerchantAccountApproved,
                submerchant.braintree_account_id,
            )

            response = self.test_client.post(
                '/braintree/submerchant/webhook',
                content_type='application/x-www-form-urlencoded',
                data=dict(notify),
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)

            submerchant = db.session.query(Submerchant).filter_by(
                public_id=submerchant.public_id, ).first()

            self.assertTrue(submerchant.is_approved)
            self.assertFalse(submerchant.is_rejected)
    def test_get(self):
        with app.app_context():
            response = self.test_client.get(
                '/users/{0}'.format(self.test_uid),
                headers={'jwt': create_token(self.test_uid, app.config)},
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertIsNotNone(response)

            response = json.loads(str(response.data.decode('utf-8')))
            self.assertEqual(response['email'], "*****@*****.**")
    def test_delete(self):
        with app.app_context():
            response = self.test_client.delete(
                '/users/{0}'.format(self.to_delete_uid),
                headers={'jwt': create_token(self.to_delete_uid, app.config)},
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)

            deleted_user = db.session.query(User).filter_by(
                public_id=self.to_delete_uid
            ).first()

            self.assertTrue(deleted_user.is_deleted)
Ejemplo n.º 11
0
    def test_get_with_subscription(self):
        with app.app_context():
            self.test_create_subscription_with_preixisting_user()

            response = self.test_client.get(
                '/braintree/{0}/subscriptions'.format(
                    self.test_id_with_customer, ),
                headers={
                    'jwt': create_token(self.test_id_with_customer, app.config)
                },
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertIsNotNone(response)
            response = json.loads(str(response.data.decode('utf-8')))
Ejemplo n.º 12
0
    def test_get_without_subscription(self):
        with app.app_context():
            response = self.test_client.get(
                '/braintree/{0}/subscriptions'.format(
                    self.test_id_wo_customer, ),
                headers={
                    'jwt': create_token(self.test_id_wo_customer, app.config)
                },
            )

            self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)
            self.assertIsNotNone(response)
            response = json.loads(str(response.data.decode('utf-8')))

            self.assertEqual(response['msg'],
                             'Failed to retrieve subscription info.')
    def test_delete_fail_nonexistent_user(self):
        with app.app_context():

            response = self.test_client.delete(
                '/users/{0}'.format('1fe26e77-0c2c-41d3-b6a5-c352a7689131'),
                headers={'jwt': create_token(
                    '1fe26e77-0c2c-41d3-b6a5-c352a7689131',
                    app.config)
                },
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertIsNotNone(response)

            response = json.loads(str(response.data.decode('utf-8')))
            self.assertIsNone(response['email'])
    def test_get_fail_event_by_id(self):
        with app.app_context():
            response = self.test_client.get(
                '/event/{0}/1000000'.format(self.scheduling_uid),
                headers={'jwt': create_token(self.scheduling_uid, app.config)}
            )

            self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)
            self.assertIsNotNone(response)

            response = json.loads(str(response.data.decode('utf-8')))

            self.assertEqual(
                'Requested event not found. Please refresh and try again.',
                response['msg'],
            )
Ejemplo n.º 15
0
    def test_cancel_sub(self, mock_sub):
        mock_sub.return_value = MockSubSuccess()

        with app.app_context():
            self.test_create_subscription_with_preixisting_user()

            response = self.test_client.delete(
                '/braintree/{0}/subscriptions'.format(
                    self.test_id_with_customer, ),
                headers={
                    'jwt': create_token(self.test_id_with_customer, app.config)
                },
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertIsNotNone(response)
            response = json.loads(str(response.data.decode('utf-8')))
Ejemplo n.º 16
0
    def test_cancel_sub_user_has_no_sub(self, mock_sub):
        mock_sub.return_value = MockSubSuccess()

        with app.app_context():
            response = self.test_client.delete(
                '/braintree/{0}/subscriptions'.format(
                    self.test_id_with_customer, ),
                headers={
                    'jwt': create_token(self.test_id_with_customer, app.config)
                },
            )

            self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)
            self.assertIsNotNone(response)
            response = json.loads(str(response.data.decode('utf-8')))

            self.assertEqual(response['msg'],
                             'Failed to retrieve subscription info.')
    def test_post_fail_duplicate_email(self):
        with app.app_context():
            data = {
                'email': '*****@*****.**',
                'username': '******',
                'plaintext_password': '******',
                'local_tz': 'US/Central'
            }

            response = self.test_client.post(
                '/users/'.format(self.test_uid),
                content_type='application/json',
                data=json.dumps(data),
                headers={'jwt': create_token(self.test_uid, app.config)},
            )

            self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)
            self.assertIsNotNone(response)
Ejemplo n.º 18
0
    def post(self):
        arg_fields = {
            'user_challenge': String(required=True),
            'plaintext_password': String(required=True),
        }
        args = parser.parse(arg_fields)

        user_info = AuthDAO().login(**args)

        logging.info('Succesfully validated incoming user {0}'.format(
            args['user_challenge']))

        # type: Response
        response = jsonify({
            'new_jwt':
            create_token(str(user_info.public_id), app.config).decode('utf-8'),
            'user_info':
            UserMarshal().dump(user_info).data,
        })

        return response
    def test_get(self):
        with app.app_context():
            data = {
                'is_scheduling': False
            }

            response = self.test_client.get(
                '/events/{0}'.format(self.scheduled_uid),
                content_type='application/json',
                data=json.dumps(data),
                headers={'jwt': create_token(self.scheduled_uid, app.config)}
            )

            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertIsNotNone(response)

            response = json.loads(str(response.data.decode('utf-8')))['events']

            for event in response:
                for k in event.keys():
                    self.assertIsNone(response[k])
    def test_post_fail_gt_60_not_mod(self, transaction_mock):
        transaction_mock = True
        with app.app_context():
            new_schedule = Schedule(
                datetime.utcnow().replace(hour=1) + timedelta(days=1),
                datetime.utcnow().replace(hour=18) + timedelta(days=1),
                self.scheduled_uid,
                'UTC',
            )

            db.session.add(new_schedule)
            db.session.commit()

            data = {
                'scheduled_user_id': self.scheduled_uid,
                'localized_start_time': (
                    datetime.utcnow().replace(hour=2) + timedelta(days=1)
                ).strftime('%Y-%m-%d %H:%M:%S'),
                'localized_end_time': (
                    datetime.utcnow().replace(hour=4, minute=37) + timedelta(days=1)
                ).strftime('%Y-%m-%d %H:%M:%S'),
                'local_tz': 'US/Central',
                'notes': 'Contact me at [email protected] for info.',
                'is_paid': True,
                'nonce': 'fake-valid-debit-nonce',
            }

            response = self.test_client.post(
                '/events/',
                content_type='application/json',
                data=json.dumps(data),
                headers={'jwt': create_token(self.scheduling_uid, app.config)}
            )

            self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)
            self.assertIsNotNone(response)
            response = json.loads(str(response.data.decode('utf-8')))
            self.assertTrue(
                response['msg'].startswith("Invalid duration.")
            )
    def test_put_user_preferences_fail_bad_current_pw(self):
        with app.app_context():
            data = {
                'current_password': '******',
                'plaintext_password': '******'
            }

            response = self.test_client.put(
                '/users/{0}/preferences'.format(self.test_uid),
                content_type='application/json',
                data=json.dumps(data),
                headers={'jwt': create_token(self.test_uid, app.config)},
            )

            self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)
            self.assertIsNotNone(response)

            response = json.loads(str(response.data.decode('utf-8')))
            self.assertEqual(
                response.get('msg'),
                'Invalid current password.'
            )