def setUp(self):
        self.set_default_test_password(testUtils.random_password_generator())
        self.set_default_test_name("~~~" + testUtils.random_name_generator() + "~~~")
        self.set_default_test_username(testUtils.random_email_generator())
        self.set_default_test_date(datetime.utcnow())

        application.debug = False
        application.config['TESTING'] = True
        self.app = application.test_client()
        init_db()
        newUser = self.createNewUser(email=self.get_default_test_username(), new_password=self.get_default_test_password(), first_name=self.get_default_test_name(), last_name=self.get_default_test_name(), active=True, confirmed_at=True, next_pay_date=True)
        self.set_user_id(newUser.id)
    def apiCreateNewUser(self, **kwargs):
        password = kwargs.get('new_password')
        confirm_password = kwargs.get('confirm_new_password')
        email = kwargs.get('email')
        next_pay_date = kwargs.get('next_pay_date')
        pay_recurrance_flag = kwargs.get('pay_recurrance_flag')
        confirmed_at = kwargs.get('confirmed_at')

        if email is None:
            email = testUtils.random_name_generator()

        if password is None and confirm_password is None:
            val = testUtils.random_password_generator()
            password = val
            confirm_password = val

        if password == self.get_default_test_password() and confirm_password is None:
            confirm_password = self.get_default_test_password()

        if isinstance(next_pay_date, datetime):
            next_pay_date = next_pay_date
        elif next_pay_date is True:
            next_pay_date = self.get_default_test_date()
        elif next_pay_date is False:
            next_pay_date = None
        else:
            next_pay_date = self.get_default_test_date()

        if pay_recurrance_flag is None:
            pay_recurrance_flag = "B"

        if isinstance(confirmed_at, datetime):
            confirmed_at = confirmed_at
        if confirmed_at:
            confirmed_at = self.get_default_test_date()
        else:
            confirmed_at = None

        return self.app.post('api/me/', data=json.dumps(
            {'email':email,
             'confirm_email':email,
             'new_password':password,
             'confirm_new_password':confirm_password,
             'first_name': self.get_default_test_name(),
             'last_name': self.get_default_test_name(),
             'confirmed_at': testUtils.dump_date(confirmed_at),
             'pay_recurrance_flag': pay_recurrance_flag,
             'next_pay_date': testUtils.dump_date(next_pay_date)}), content_type='application/json')
    def createNewUser(self, **kwargs):
        password = kwargs.get('new_password')
        email = kwargs.get('email')
        next_pay_date = kwargs.get('next_pay_date')
        pay_recurrance_flag = kwargs.get('pay_recurrance_flag')
        confirmed_at = kwargs.get('confirmed_at')
        active = kwargs.get('active')

        if email is None:
            email = testUtils.random_email_generator()

        if password is None:
            password = testUtils.random_password_generator()

        if isinstance(next_pay_date, datetime):
            next_pay_date = next_pay_date
        elif next_pay_date is True:
            next_pay_date = self.get_default_test_date()
        elif next_pay_date is False:
            next_pay_date = None
        else:
            next_pay_date = self.get_default_test_date()

        if pay_recurrance_flag is None:
            pay_recurrance_flag = "B"

        if isinstance(confirmed_at, datetime):
            confirmed_at = confirmed_at
        elif confirmed_at is True:
            confirmed_at = self.get_default_test_date()
        elif confirmed_at is False:
            confirmed_at = None
        else:
            confirmed_at = None

        newUser = User(username=email, password=password, email=email, first_name=self.get_default_test_name(), last_name=self.get_default_test_name(), next_pay_date=next_pay_date, pay_recurrance_flag = pay_recurrance_flag,  confirmed_at=confirmed_at, active=active)
        db_session.add(newUser)
        db_session.commit()
        return newUser