本文整理汇总了Python中c3smembership.data.model.base.DBSession.flush方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.flush方法的具体用法?Python DBSession.flush怎么用?Python DBSession.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c3smembership.data.model.base.DBSession
的用法示例。
在下文中一共展示了DBSession.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def setUp(self):
my_settings = {"sqlalchemy.url": "sqlite:///:memory:", "api_auth_token": u"SECRETAUTHTOKEN"}
self.config = testing.setUp()
app = main({}, **my_settings)
# set up the database
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
member1 = C3sMember( # german
firstname=u"SomeFirstnäme",
lastname=u"SomeLastnäme",
email=u"[email protected]",
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"de",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u"ABCDEFGFOO",
password=u"arandompassword",
date_of_submission=date.today(),
membership_type=u"normal",
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u"23",
)
DBSession.add(member1)
member1.email_invite_token_bcgv16 = u"MEMBERS_TOKEN"
DBSession.flush()
self.testapp = TestApp(app)
示例2: create
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def create(cls, membership_number, shares_quantity,
board_confirmation=None):
"""
Create a shares package.
Args:
membership_number: The membership number of the member for which
the shares package is created.
shares_quantity: The number of shares of the package to be created.
board_confirmation: Optional. The date on which the board of
directors confirmed the acquisition of the shares package.
Returns:
The technical primary key of the created shares package.
"""
shares = Shares(
number=shares_quantity,
date_of_acquisition=board_confirmation,
)
# pylint: disable=no-member
member = DBSession.query(C3sMember).filter(
C3sMember.membership_number == membership_number).first()
# pylint: disable=no-member
DBSession.add(shares)
member.shares.append(shares)
member.num_shares += shares_quantity
DBSession.flush()
return shares.id
示例3: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def setUp(self):
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
try:
DBSession.close()
DBSession.remove()
# print("removed old DBSession ==============================")
except:
# print("no DBSession to remove =============================")
pass
# try:
# os.remove('test_webtest_functional.db')
# #print "deleted old test database"
# except:
# pass
# #print "never mind"
my_settings = {
# 'sqlalchemy.url': 'sqlite:///test_webtest_functional.db',
'sqlalchemy.url': 'sqlite:///:memory:',
'available_languages': 'da de en es fr',
'c3smembership.notification_sender': '[email protected]',
'testing.mail_to_console': 'false'}
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
self.session = DBSession # ()
Base.metadata.create_all(engine)
# dummy database entries for testing
with transaction.manager:
member1 = C3sMember( # german
firstname=u'SomeFirstnäme',
lastname=u'SomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"DE",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGFOO',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'23',
)
DBSession.add(member1)
DBSession.flush()
from c3smembership import main
app = main({}, **my_settings)
app.registry.get_mailer = get_mailer
from webtest import TestApp
self.testapp = TestApp(app)
示例4: create_general_assembly
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def create_general_assembly(cls, number, name, date):
"""
Create a general assembly
Args:
number: Integer. The number of the general assembly as a unique
identifier.
name: String. The name of the general assembly.
date: `datetime.date`. The date at which the general assembly takes
place.
"""
assembly = GeneralAssembly(number, name, date)
# pylint: disable=no-member
DBSession.add(assembly)
DBSession.flush()
示例5: invite_member
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def invite_member(cls, membership_number, general_assembly_number, token):
"""
Store the member invitation for the general assembly
Args:
membership_number: Integer. The membership number of the member for
which the general assembly invitation is stored.
general_assembly_number: Integer. The number of the general
assembly for which the invitation is stored for the member.
token: String. The token set to verify the member for API access by
the ticketing application.
"""
# pylint: disable=no-member
member = MemberRepository.get_member(membership_number)
assembly = cls.get_general_assembly(general_assembly_number)
invitation = GeneralAssemblyInvitation(
assembly, member, cls.datetime.now(), token)
DBSession.add(invitation)
DBSession.flush()
示例6: edit_general_assembly
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def edit_general_assembly(cls, number, name, date):
"""
Edit a general assembly
Args:
number: Integer. The number of the general assembly to be edited.
name: String. The edited name of the general assembly.
date: `datetime.date`. The edited date at which the general
assembly takes place.
Raises:
ValueError: In case the a general assembly with the number given
does not exist.
"""
assembly = cls.get_general_assembly(number)
if assembly is None:
raise ValueError(
'A general assembly with this number does not exist.')
assembly.name = name
assembly.date = date
# pylint: disable=no-member
DBSession.flush()
示例7: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def setUp(self):
"""
Set up database and engine
"""
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
DBSession().close()
DBSession.remove()
from sqlalchemy import create_engine
engine = create_engine('sqlite:///:memory:')
DBSession.configure(bind=engine)
self.session = DBSession
Base.metadata.create_all(engine)
with transaction.manager:
# German member
member1 = C3sMember(
firstname=u'SomeFirstnäme',
lastname=u'SomeLastnäme',
email=u'[email protected]',
address1=u'addr one',
address2=u'addr two',
postcode=u'12345',
city=u'Footown Mäh',
country=u'Foocountry',
locale=u'DE',
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGBAR',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u'GEMA',
num_shares=u'23',
)
db_session = DBSession()
db_session.add(member1)
db_session.flush()
示例8: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def setUp(self):
my_settings = {
'sqlalchemy.url': 'sqlite:///:memory:',
'api_auth_token': u"SECRETAUTHTOKEN",
'c3smembership.url': u'localhost',
'c3smembership.notification_sender': u'[email protected]',
'c3smembership.status_receiver': u'[email protected]',
'testing.mail_to_console': u'false',
}
self.config = testing.setUp()
app = main({}, **my_settings)
self.get_mailer = GetMailerDummy()
app.registry.get_mailer = self.get_mailer
app.registry.membership_application.datetime = DateTimeDummy(
datetime.datetime(2018, 4, 26, 12, 23, 34))
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
# a group for accountants/staff
accountants_group = Group(name=u"staff")
DBSession.add(accountants_group)
DBSession.flush()
# staff personnel
staffer1 = Staff(
login=u"rut",
password=u"berries",
email=u"[email protected]",
)
staffer1.groups = [accountants_group]
DBSession.add(accountants_group)
DBSession.add(staffer1)
DBSession.flush()
self.testapp = TestApp(app)
示例9: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def setUp(self):
"""
Setup test cases
"""
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
DBSession.close()
DBSession.remove()
my_settings = {
'sqlalchemy.url': 'sqlite:///:memory:',
'available_languages': 'da de en es fr',
'c3smembership.dashboard_number': '30'}
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
# self._insert_members()
with transaction.manager:
# a group for accountants/staff
accountants_group = Group(name=u"staff")
DBSession.add(accountants_group)
DBSession.flush()
# staff personnel
staffer1 = Staff(
login=u"rut",
password=u"berries",
email=u"[email protected]",
)
staffer1.groups = [accountants_group]
DBSession.add(accountants_group)
DBSession.add(staffer1)
DBSession.flush()
app = main({}, **my_settings)
self.testapp = TestApp(app)
示例10: send_dues18_invoice_email
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def send_dues18_invoice_email(request, m_id=None):
"""
Send email to a member to prompt her to pay the membership dues.
- For normal members, also send link to invoice.
- For investing members that are legal entities,
ask for additional support depending on yearly turnover.
This view function works both if called via URL, e.g. /dues_invoice/123
and if called as a function with a member id as parameter.
The latter is useful for batch processing.
When this function is used for the first time for one member,
some database fields are filled:
- Invoice number
- Invoice amount (calculated from date of membership approval by the board)
- Invoice token
Also, the database table of invoices (and cancellations) is appended.
If this function gets called the second time for a member,
no new invoice is produced, but the same mail sent again.
"""
# either we are given a member id via url or function parameter
try: # view was called via http/s
member_id = request.matchdict['member_id']
batch = False
except KeyError: # ...or was called as function with parameter (see batch)
member_id = m_id
batch = True
try: # get member from DB
member = C3sMember.get_by_id(member_id)
assert(member is not None)
except AssertionError:
if not batch:
request.session.flash(
"member with id {} not found in DB!".format(member_id),
'warning')
return HTTPFound(request.route_url('dues'))
# sanity check:is this a member?
try:
assert(member.membership_accepted) # must be accepted member!
except AssertionError:
request.session.flash(
"member {} not accepted by the board!".format(member_id),
'warning')
return HTTPFound(request.route_url('dues'))
if 'normal' not in member.membership_type and \
'investing' not in member.membership_type:
request.session.flash(
'The membership type of member {0} is not specified! The '
'membership type must either be "normal" or "investing" in order '
'to be able to send an invoice email.'.format(member.id),
'warning')
return get_memberhip_listing_redirect(request)
if member.membership_date >= date(2019, 1, 1) or (
member.membership_loss_date is not None
and member.membership_loss_date < date(2018, 1, 1)
):
request.session.flash(
'Member {0} was not a member in 2018. Therefore, you cannot send '
'an invoice for 2018.'.format(member.id),
'warning')
return get_memberhip_listing_redirect(request)
# check if invoice no already exists.
# if yes: just send that email again!
# also: offer staffers to cancel this invoice
if member.dues18_invoice is True:
invoice = DuesInvoiceRepository.get_by_number(
member.dues18_invoice_no, 2018)
member.dues18_invoice_date = datetime.now()
else: # if no invoice already exists:
# make dues token and ...
randomstring = make_random_string()
# check if dues token is already used
while DuesInvoiceRepository.token_exists(randomstring, 2018):
# create a new one, if the new one already exists in the database
randomstring = make_random_string() # pragma: no cover
# prepare invoice number
try:
# either we already have an invoice number for that client...
invoice_no = member.dues18_invoice_no
assert invoice_no is not None
except AssertionError:
# ... or we create a new one and save it
# get max invoice no from db
max_invoice_no = DuesInvoiceRepository.get_max_invoice_number(2018)
# use the next free number, save it to db
new_invoice_no = int(max_invoice_no) + 1
DBSession.flush() # save dataset to DB
# calculate dues amount (maybe partial, depending on quarter)
dues_start, dues_amount = calculate_partial_dues18(member)
# now we have enough info to update the member info
#.........这里部分代码省略.........
示例11: init_testing_db
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def init_testing_db():
"""
Initializes the memory database with test samples.
"""
my_settings = {
'sqlalchemy.url': 'sqlite:///:memory:', }
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
# There is a side effect of test_initialization.py after which there
# are still records in the database although it is setup from scratch.
# Therefore, remove all members to have an empty table.
# pylint: disable=no-member
members = C3sMember.get_all()
for member in members:
DBSession.delete(member)
DBSession.flush()
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2014,
u'1. ordentliche Generalversammlung',
date(2014, 8, 23)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2015,
u'2. ordentliche Generalversammlung',
date(2015, 6, 13)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2015_2,
u'Außerordentliche Generalversammlung',
date(2015, 7, 16)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2016,
u'3. ordentliche Generalversammlung',
date(2016, 4, 17)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2017,
u'4. ordentliche Generalversammlung',
date(2017, 4, 2)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2018,
u'5. ordentliche Generalversammlung',
date(2018, 6, 3)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2018_2,
u'Außerordentliche Generalversammlung',
date(2018, 12, 1)))
# German person
member1 = C3sMember(
firstname=u'SomeFirstnäme',
lastname=u'SomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"de",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFG1',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=False,
name_of_colsoc=u"",
num_shares=u'23',
)
# English person
member2 = C3sMember(
firstname=u'AAASomeFirstnäme',
lastname=u'XXXSomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"en",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFG2',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=False,
name_of_colsoc=u"",
num_shares=u'23',
)
# German legal entity
member3 = C3sMember(
firstname=u'Cooles PlattenLabel',
lastname=u'SomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
#.........这里部分代码省略.........
示例12: test_join_c3s
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def test_join_c3s(self):
"""
Test the join form
"""
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
DBSession().close()
DBSession.remove()
my_settings = {
'sqlalchemy.url': 'sqlite:///:memory:',
'available_languages': 'da de en es fr',
'c3smembership.dashboard_number': '30'}
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
accountants_group = Group(name=u"staff")
db_session = DBSession()
db_session.add(accountants_group)
db_session.flush()
staffer1 = Staff(
login=u"rut",
password=u"berries",
email=u"[email protected]",
)
staffer1.groups = [accountants_group]
db_session.add(accountants_group)
db_session.add(staffer1)
db_session.flush()
app = main({}, **my_settings)
testapp = TestApp(app)
# sucess for valid entry
res = testapp.get('/', status=200)
form = self._fill_form_valid_natural(res.form)
res = form.submit(u'submit', status=302)
res = res.follow()
self.assertTrue('information below to be correct' in res.body)
# success for 18th birthday
res = testapp.get('/', status=200)
form = self._fill_form_valid_natural(res.form)
join.date = DummyDate(date(2018, 4, 29))
form['year'] = u'2000'
form['month'] = u'04'
form['day'] = u'29'
res = form.submit(u'submit', status=302)
res = res.follow()
self.assertTrue('information below to be correct' in res.body)
# failure on test one day before 18th birthday
res = testapp.get('/', status=200)
form = self._fill_form_valid_natural(res.form)
join.date = DummyDate(date(2018, 4, 29))
form['year'] = u'2000'
form['month'] = u'04'
form['day'] = u'30'
res = form.submit(u'submit', status=200)
self.assertTrue('underaged person is currently not' in res.body)
# failure for statute not checked
res = testapp.get('/', status=200)
form = self._fill_form_valid_natural(res.form)
form['got_dues_regulations'].value__set(False)
res = form.submit(u'submit', status=200)
# failure for dues regulations not checked
res = testapp.get('/', status=200)
form = self._fill_form_valid_natural(res.form)
form['got_dues_regulations'].value__set(False)
res = form.submit(u'submit', status=200)
# teardown
DBSession().close()
DBSession.remove()
testing.tearDown()
示例13: new_member
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
#.........这里部分代码省略.........
except ValidationFailure as exception:
request.session.flash(
_(u"Please note: There were errors, "
"please check the form below."),
'danger',
allow_duplicate=False)
return{'form': exception.render()}
def make_random_string():
"""
used as email confirmation code
"""
return u''.join(
random.choice(
string.ascii_uppercase + string.digits
) for x in range(10))
randomstring = make_random_string()
while C3sMember.check_for_existing_confirm_code(randomstring):
randomstring = make_random_string()
# to store the data in the DB, an objet is created
member = C3sMember(
firstname=appstruct['person']['firstname'],
lastname=appstruct['person']['lastname'],
email=appstruct['person']['email'],
password='UNSET',
address1=appstruct['person']['address1'],
address2=appstruct['person']['address2'],
postcode=appstruct['person']['postcode'],
city=appstruct['person']['city'],
country=appstruct['person']['country'],
locale=appstruct['person']['locale'],
date_of_birth=appstruct['person']['date_of_birth'],
email_is_confirmed=False,
email_confirm_code=randomstring,
date_of_submission=datetime.now(),
membership_type=appstruct['membership_info']['membership_type'],
member_of_colsoc=(
appstruct['membership_info']['member_of_colsoc'] == u'yes'),
name_of_colsoc=appstruct['membership_info']['name_of_colsoc'],
num_shares=appstruct['shares']['num_shares'],
)
if 'legalentity' in appstruct['membership_info']['entity_type']:
member.membership_type = u'investing'
member.is_legalentity = True
dbsession = DBSession()
try:
_temp = request.url.split('?')[1].split('=')
if 'id' in _temp[0]:
_id = _temp[1]
# add a member with a DB id that had seen its entry deleted
# before
_mem = C3sMember.get_by_id(_id)
if isinstance(_mem, NoneType):
member.id = _id
except:
pass
# add member at next free DB id (default if member.id not set)
try:
dbsession.add(member)
dbsession.flush()
the_new_id = member.id
except InvalidRequestError as exception:
print("InvalidRequestError! %s") % exception
except IntegrityError as exception:
print("IntegrityError! %s") % exception
# redirect to success page, then return the PDF
# first, store appstruct in session
request.session['appstruct'] = appstruct
request.session[
'appstruct']['locale'] = appstruct['person']['locale']
# empty the messages queue (as validation worked anyways)
request.session.pop_flash()
return HTTPFound( # redirect to success page
location=request.route_url(
'detail',
member_id=the_new_id),
)
# if the form was submitted and gathered info shown on the success page,
# BUT the user wants to correct their information:
else:
# remove annoying message from other session
request.session.pop_flash()
if 'appstruct' in request.session:
appstruct = request.session['appstruct']
# pre-fill the form with the values from last time
form.set_appstruct(appstruct)
html = form.render()
return {'form': html}
示例14: setUp
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def setUp(self):
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
engine = create_engine(u'sqlite://')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
member1 = C3sMember(
firstname=u'firsie',
lastname=u'lastie',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"de",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGFOO',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'23',
)
member2 = C3sMember( # german
firstname=u'AAASomeFirstnäme',
lastname=u'XXXSomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"de",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGBAR',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'23',
)
member3 = C3sMember( # german
firstname=u'BBBSomeFirstnäme',
lastname=u'AAASomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"de",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFGBAZ',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'investing',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=23,
)
DBSession.add(member1)
DBSession.add(member2)
DBSession.add(member3)
accountants_group = Group(name=u"staff")
try:
DBSession.add(accountants_group)
DBSession.flush()
# print("adding group staff")
except:
print("could not add group staff.")
# pass
# staff personnel
staffer1 = Staff(
login=u"rut",
password=u"berries",
email=u"[email protected]",
)
staffer1.groups = [accountants_group]
try:
DBSession.add(accountants_group)
DBSession.add(staffer1)
DBSession.flush()
except:
print("it borked! (rut)")
示例15: test_membership_loss
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import flush [as 别名]
def test_membership_loss(self):
'''
Test the loss of membership.
Test cases for:
1 Editing non members
1.1 Loss inputs must be hidden
1.1 Hidden loss inputs should not make any problem and therefore
submit without changes should work
1.2 Try setting hidden values -> error
2 Editing members
2.1 Loss inputs must not be hidden
2.2 Loss date and loss type must both be either set or unset
2.2.1 Set only loss date -> error, set both
2.2.2 Set only loss type -> error, set both
2.2.3 Set neither loss date nor type -> success
2.2.4 Set loss date and type to valid values -> success
2.3 Loss date must be larger than acceptance date
2.3.1 Set loss date prior to membership acceptance date -> error,
set date larger membership acceptance
2.3.2 Set loss date after membership acceptance date -> success
2.4 Loss date for resignation must be 31st of December
2.4.1 Set loss type to resignation and loss date other than 31st
of December -> fail
2.4.2 Set loss type to resignation and loss date to 31st but not
December -> fail
2.4.3 Set loss type to resignation and loss date to December but
not 31st -> fail
2.4.4 Set loss type to resignation and loss date to 31st of
December succeed
2.5 Only natural persons can be set to loss type death
2.5.1 Set loss type to death and entity type to legal entity ->
error
2.5.2 Set loss type to death and entity type to natural person ->
success
2.6 Only legal entites can be set to loss type winding-up
2.6.1 Set loss type to winding-up and entity type to natural
person error
2.6.2 Set loss type to winding-up and entity type to legal entity
-> success
'''
# setup
res = self.testapp.reset()
self.__login()
member = EditMemberTests.__create_membership_applicant()
DBSession.add(member)
DBSession.flush()
# 1 Editing non members
res = self.__get_edit_member(member.id)
self.assertFalse(res.form['membership_accepted'].checked)
# 1.1 Loss inputs must be hidden
res = self.__get_edit_member(member.id)
self.assertTrue(
type(res.form['membership_loss_date']) == webtest.forms.Hidden)
self.assertTrue(res.form['membership_loss_date'].value == '')
self.assertTrue(
type(res.form['membership_loss_type']) == webtest.forms.Hidden)
self.assertTrue(res.form['membership_loss_type'].value == '')
# 1.2 Hidden loss inputs should not make any problem and therefore
# submit without changes should work
res = self.__get_edit_member(member.id)
self.__validate_successful_submit(res)
# 1.3 Try setting hidden values -> error
self.__validate_abortive_edit(
member.id,
{
'membership_loss_date': date.today(),
'membership_loss_type': u'resignation',
},
[u'Please note: There were errors, please check the form below.'])
# 2 Editing members
member = EditMemberTests.__create_accepted_member_full()
DBSession.add(member)
DBSession.flush()
res = self.__get_edit_member(member.id)
# make sure default values are valid
self.__validate_successful_submit(res)
# 2.1 Loss inputs must not be hidden
res = self.__get_edit_member(member.id)
self.assertTrue(res.form['membership_accepted'].checked)
#.........这里部分代码省略.........