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)
Exemple #2
0
    def setUp(self):
        with app.app_context():
            test_user1 = User(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'sub_user1',
            )

            test_user2 = User(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'sub_user2',
            )

            db.session.add(test_user1)
            db.session.add(test_user2)
            db.session.commit()

            test_customer = Customer(
                'test_id',
                'test_cc',
                'first_name',
                'last_name',
                test_user2.public_id,
            )

            db.session.add(test_customer)
            db.session.commit()

            self.test_id_wo_customer = test_user1.public_id
            self.test_id_with_customer = test_user2.public_id
Exemple #3
0
 def test_delete_fail_schedule_not_exist(self):
     with app.app_context():
         with self.assertRaises(DAOException):
             self.test_dao.delete(
                 self.test_uid,
                 "10000000"
             )
    def test_create_user_mail_queue_failure(self, mail_queue):
        mail_queue.side_effect = SQLException('Test')

        with app.app_context():
            try:
                new_user = self.test_facade.create_user(
                    "*****@*****.**",
                    "testpw",
                    'US/Central',
                    'test12341234',
                )
            except Exception as e:
                pass

            found_user = db.session.query(User).filter_by(
                email='*****@*****.**'
            ).first()

            self.assertIsNone(found_user)

            found_mail_queue = db.session.query(
                EmailQueue
            ).filter_by(
                email_to='*****@*****.**'
            ).first()

            self.assertIsNone(found_mail_queue)
    def test_create_user_adds_to_mail_queue(self):
        with app.app_context():
            new_user = self.test_facade.create_user(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'test4',
            )

            found_user = db.session.query(User).filter_by(
                email=new_user.email
            ).first()

            self.assertIsNotNone(found_user)

            found_mail_queue = db.session.query(
                EmailQueue
            ).filter_by(
                email_to=new_user.email
            ).first()

            self.assertIsNotNone(found_mail_queue)
            self.assertTrue(
                found_user.verify_token in found_mail_queue.body
            )
    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_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)
Exemple #8
0
    def test_create_customer(self, _mock):
        class __test:
            @property
            def is_success(self): return True

            @property
            def customer(self): return {}

        _mock.return_value = __test()
        with app.app_context():
            new_customer = self.test_facade.create_customer(
                'test-nonce',
                'first_name',
                'last_name',
                self.test_uid,
                make_default=True,
                skip_commit=False
            )

            self.assertIsNotNone(new_customer)

            retval = db.session.query(
                Customer
            ).filter_by(
                public_id=new_customer.public_id,
            ).first()

            self.assertIsNotNone(retval)
Exemple #9
0
    def test_put(self):
        with app.app_context():
            new_schedule = Schedule(
                datetime.utcnow(),
                datetime.utcnow() + timedelta(minutes=5),
                self.test_uid,
                'US/Central'
            )

            new_schedule.public_id = 'ed311073-076e-485e-a226-801c2254a173'
            db.session.add(new_schedule)
            db.session.commit()

            start = datetime.utcnow() + timedelta(minutes=2)
            end = datetime.utcnow() + timedelta(minutes=7)
            response = self.test_dao.put(
                new_schedule.public_id,
                start,
                end,
                self.test_uid
            )

            self.assertIsNotNone(response)
            self.assertEqual(start.hour, response.utc_open.hour)
            self.assertEqual(start.minute, response.utc_open.minute)
            self.assertEqual(end.hour, response.utc_end.hour)
            self.assertEqual(end.minute, response.utc_end.minute)
    def test_calculate_service_fee(self):
        with app.app_context():
            User.query.filter_by(public_id=self.scheduled_user).update({
                'is_premium':
                True,
                'five_min_price':
                100.0
            })

            db.session.commit()

            new_event = Event(
                datetime.utcnow(),
                datetime.utcnow() + timedelta(minutes=5),
                self.scheduling_user,
                self.scheduled_user,
            )

            db.session.add(new_event)
            db.session.commit()

            self.assertAlmostEqual(float(new_event.total_price),
                                   102.7,
                                   delta=0.2)
            self.assertAlmostEqual(float(new_event.service_fee),
                                   2.5,
                                   delta=0.2)
    def test_get_for_scheduled_user(self):
        with app.app_context():
            response = self.test_dao.get_for_scheduled_user(
                self.scheduled_user)

            self.assertNotEqual([], response)
            self.assertEqual(len(response), 3)
    def test_get_by_event_id(self):
        with app.app_context():
            response = self.test_dao.get_by_event_id(self.scheduled_user,
                                                     self.eids[1])

            self.assertIsNotNone(response)
            self.assertEqual(response.EventTable.public_id, self.eids[1])
    def test_rollback_on_failure(self, transaction_mock):
        with app.app_context():
            with self.assertRaises(FacadeException) as e:
                new_schedule = Schedule(
                    datetime.utcnow().replace(hour=1) + timedelta(days=1),
                    datetime.utcnow().replace(hour=5) + timedelta(days=1),
                    self.scheduled_user,
                    'UTC',
                )

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

                transaction_mock.side_effect = DAOException('test')

                new_event = EventFacade().create_new_event(
                    self.scheduling_user,
                    self.scheduled_user,
                    (datetime.utcnow().replace(hour=2) +
                     timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S'),
                    (datetime.utcnow().replace(hour=3) +
                     timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S'),
                    'UTC',
                    'test3-1234ko1234',
                    'fake-nonce',
                )

                self.assertEqual(e.msg, 'test')

                found_event = db.session.query(Event).filter_by(
                    notes='test3-1234ko1234', ).first()

                self.assertIsNone(found_event)
Exemple #14
0
    def test_put_fail_invalid_duration(self):
        with app.app_context():
            new_schedule = Schedule(
                datetime.utcnow(),
                datetime.utcnow() + timedelta(minutes=5),
                self.test_uid,
                'US/Central'
            )
            db.session.add(new_schedule)
            db.session.commit()

            try:
                start = datetime.utcnow() + timedelta(minutes=2)
                end = datetime.utcnow() + timedelta(minutes=7)
                self.test_dao.put(
                    new_schedule.public_id,
                    start,
                    end,
                    self.test_uid
                )
            except DAOException as e:
                self.assertEqual(
                    e.msg,
                    "Invalid start time. Start must be before the end."
                )
Exemple #15
0
    def setUpClass(cls):
        with app.app_context():
            db.drop_all()
            db.create_all()

            cls.test_dao = ScheduleDAO()

            test_user = User(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'scheduleputfactest',
            )

            test2_user = User(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'scheduleputotheruser',
            )

            cls.test_uid = test_user.public_id
            cls.other_uid = test2_user.public_id

            db.session.add(test_user)
            db.session.add(test2_user)
            db.session.commit()
Exemple #16
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 setUpClass(cls):
        with app.app_context():
            db.drop_all()
            db.create_all()

            cls.test_client = app.test_client()
            cls.test_dao = UserDAO()

            scheduling = User(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'scheduling_user',
            )

            scheduled = User(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'scheduled_user',
            )

            cls.scheduling_uid = scheduling.public_id
            cls.scheduled_uid = scheduled.public_id

            db.session.add(scheduling)
            db.session.add(scheduled)
            db.session.commit()

            User.query.filter_by(
                public_id=cls.scheduled_uid
            ).update({
                'sixty_min_price': 15
            })

            db.session.add(Submerchant(
                cls.scheduled_uid,
                'testaccountid',
                'firstName',
                'LastName',
                'email',
                datetime.utcnow() + timedelta(days=-365*20),
                'address_street',
                'address_locality',
                'address_region',
                'address_zip',
            ))

            new_schedule = Schedule(
                datetime.utcnow(),
                datetime.utcnow() + timedelta(minutes=60),
                cls.scheduled_uid,
                'US/Central'
            )

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

            cls.new_schedule_id = new_schedule.id
    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)
Exemple #19
0
    def test_password_works_after_hash(self):
        with app.app_context():
            found_user = db.session.query(User).filter_by(
                public_id=self.test_uid).first()

            self.assertIsNotNone(found_user)
            self.assertTrue(found_user.compare_password('testpw'))
            self.assertFalse(found_user.compare_password('incorrectpassword'))
    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 setUpClass(cls):
        with app.app_context():
            db.drop_all()
            db.create_all()

            cls.test_dao = EventDAO()

            cls.scheduling_user = User(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'scheduling_user',
            )

            cls.scheduled_user = User(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'scheduled_user',
            )

            db.session.add(cls.scheduling_user)
            db.session.add(cls.scheduled_user)

            db.session.commit()

            cls.scheduled_user = User.query.filter_by(
                public_id=cls.scheduled_user.public_id).first().public_id

            cls.scheduling_user = User.query.filter_by(
                public_id=cls.scheduling_user.public_id).first().public_id

            User.query.filter_by(public_id=cls.scheduled_user).update(
                {'sixty_min_price': 15})

            db.session.add(
                Submerchant(
                    cls.scheduled_user,
                    'testaccountid',
                    'firstName',
                    'LastName',
                    'email',
                    datetime.utcnow() + timedelta(days=-365 * 20),
                    'address_street',
                    'address_locality',
                    'address_region',
                    'address_zip',
                ))

            db.session.commit()

            new_schedule = Schedule(
                datetime.utcnow().replace(hour=0) + timedelta(days=1),
                datetime.utcnow().replace(hour=12) + timedelta(days=1),
                cls.scheduled_user, 'US/Central')

            db.session.add(new_schedule)
            db.session.commit()
Exemple #22
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)
Exemple #23
0
    def setUpClass(cls):
        with app.app_context():
            app.config['TESTING'] = True

            db.drop_all()
            db.create_all()

            cls.test_client = app.test_client()
            cls.test_dao = UserDAO()
Exemple #24
0
    def tearDown(self):
        with app.app_context():
            db.session.query(Subscription).delete()

            db.session.query(Customer).delete()

            db.session.query(User).delete()

            db.session.commit()
    def test_get_by_event_fail_no_eid(self):
        with app.app_context():
            with self.assertRaises(DAOException) as e:
                self.test_dao.get_by_event_id(
                    self.scheduled_user,
                    '1000000',
                )

                self.assertTrue(e.msg.startswith('Failed to retrieve event ('))
Exemple #26
0
    def test_password_correctly_hashes(self):
        with app.app_context():
            found_user = db.session.query(User).filter_by(
                public_id=self.test_uid).first()

            self.assertIsNotNone(found_user)
            self.assertEqual(found_user.email, "*****@*****.**")
            self.assertNotEqual(found_user.password, "testpw")
            self.assertTrue(found_user.password.startswith(b'$2b'))
 def test_post_fail_duplicate_email(self):
     with self.assertRaises(SQLException):
         with app.app_context():
             self.test_dao.create_new_user(
                 "*****@*****.**",
                 "testpw",
                 'US/Central',
                 'testalskdjf',
             )
    def test_delete(self):
        with app.app_context():
            response = self.test_dao.delete(self.to_delete_uid)

            self.assertTrue(response)

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

            self.assertTrue(deleted_user.is_deleted)
Exemple #29
0
    def setUpClass(cls):
        with app.app_context():
            db.drop_all()
            db.create_all()

            cls.test_client = app.test_client()
            cls.test_dao = MerchantDAO()

            db.session.add(MasterMerchant('clarksoftware'))
            db.session.commit()
    def test_post(self):
        with app.app_context():
            new_user = self.test_dao.create_new_user(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'test10',
            )

            self.assertIsNotNone(new_user)
            self.assertEqual(new_user.email, "*****@*****.**")