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'*****@*****.**', 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'*****@*****.**', 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'*****@*****.**', 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'ABCDEFG3', password=u'arandompassword', date_of_submission=date.today(), membership_type=u'normal', member_of_colsoc=False, name_of_colsoc=u"", num_shares=u'42', ) # English legal entity member4 = C3sMember( firstname=u'Incredible Records', lastname=u'XXXSomeLastnäme', email=u'*****@*****.**', 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'ABCDEFG4', password=u'arandompassword', date_of_submission=date.today(), membership_type=u'normal', member_of_colsoc=False, name_of_colsoc=u"", num_shares=u'2', ) member1.membership_accepted = True member1.membership_number = u'11' DBSession.add(member1) member2.membership_accepted = True member2.membership_number = u'22' DBSession.add(member2) member3.membership_accepted = True member3.membership_number = u'33' DBSession.add(member3) member4.membership_accepted = True member4.membership_number = u'44' DBSession.add(member4) DBSession.flush() return DBSession
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. members = C3sMember.get_all() for member in members: DBSession.delete(member) DBSession.flush() member1 = C3sMember( # german person firstname=u'SomeFirstnäme', lastname=u'SomeLastnäme', email=u'*****@*****.**', 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', ) member2 = C3sMember( # english person firstname=u'AAASomeFirstnäme', lastname=u'XXXSomeLastnäme', email=u'*****@*****.**', 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', ) member3 = C3sMember( # german legalentity firstname=u'Cooles PlattenLabel', lastname=u'SomeLastnäme', email=u'*****@*****.**', 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'ABCDEFG3', password=u'arandompassword', date_of_submission=date.today(), membership_type=u'normal', member_of_colsoc=False, name_of_colsoc=u"", num_shares=u'42', ) member4 = C3sMember( # english legalentity firstname=u'Incredible Records', lastname=u'XXXSomeLastnäme', email=u'*****@*****.**', 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'ABCDEFG4', password=u'arandompassword', date_of_submission=date.today(), membership_type=u'normal', member_of_colsoc=False, name_of_colsoc=u"", num_shares=u'2', ) member1.membership_accepted = True DBSession.add(member1) member2.membership_accepted = True DBSession.add(member2) member3.membership_accepted = True DBSession.add(member3) member4.membership_accepted = True DBSession.add(member4) DBSession.flush() return DBSession
def merge_member_view(request): """ Merges member duplicates into one member record. Some people have more than one entry in our C3SMember table, e.g. because they used the application form more than once to acquire more shares. They shall not, however, become members twice and get more than one membership number. So we try and merge them: If a person is already a member and acquires a second package of shares, this package of shares is added to the former membership entry. The second entry in the C3sMember table is given the 'is_duplicate' flag and also the 'duplicate_of' is given the *id* of the original entry. """ _id = request.matchdict['afm_id'] _mid = request.matchdict['mid'] if DEBUG: # pragma: no cover print "shall merge {} to {}".format(_id, _mid) orig = C3sMember.get_by_id(_mid) merg = C3sMember.get_by_id(_id) if not orig.membership_accepted: request.session.flash( 'you can only merge to accepted members!', 'merge_message') HTTPFound(request.route_url('make_member', afm_id=_id)) exceeds_60 = int(orig.num_shares) + int(merg.num_shares) > 60 if exceeds_60: request.session.flash( 'merger would exceed 60 shares!', 'merge_message') return HTTPFound(request.route_url('make_member', afm_id=_id)) # TODO: this needs fixing!!! # date must be set manually according to date of approval of the board _date_for_shares = merg.signature_received_date if ( merg.signature_received_date > merg.payment_received_date ) else merg.payment_received_date # print "the date for the shares: {} (s: {}; p: {})".format( # _date_for_shares, # merg.signature_received_date, # merg.payment_received_date # ) shares = Shares( number=merg.num_shares, date_of_acquisition=_date_for_shares, reference_code=merg.email_confirm_code, signature_received=merg.signature_received, signature_received_date=merg.signature_received_date, payment_received=merg.payment_received, payment_received_date=merg.payment_received_date, ) DBSession.add(shares) # persist orig.shares.append(shares) orig.num_shares += merg.num_shares DBSession.delete(merg) return HTTPFound(request.route_url('detail', memberid=_mid))
def merge_member_view(request): """ Merges member duplicates into one member record. Some people have more than one entry in our C3SMember table, e.g. because they used the application form more than once to acquire more shares. They shall not, however, become members twice and get more than one membership number. So we try and merge them: If a person is already a member and acquires a second package of shares, this package of shares is added to the former membership entry. The second entry in the C3sMember table is given the 'is_duplicate' flag and also the 'duplicate_of' is given the *id* of the original entry. """ afm_id = request.matchdict['afm_id'] member_id = request.matchdict['mid'] if DEBUG: # pragma: no cover print "shall merge {} to {}".format(afm_id, member_id) orig = C3sMember.get_by_id(member_id) merg = C3sMember.get_by_id(afm_id) if not orig.membership_accepted: request.session.flash( 'you can only merge to accepted members!', 'merge_message') HTTPFound(request.route_url('make_member', afm_id=afm_id)) exceeds_60 = int(orig.num_shares) + int(merg.num_shares) > 60 if exceeds_60: request.session.flash( 'merger would exceed 60 shares!', 'merge_message') return HTTPFound(request.route_url('make_member', afm_id=afm_id)) # TODO: this needs fixing!!! # date must be set manually according to date of approval of the board shares_date_of_acquisition = merg.signature_received_date if ( merg.signature_received_date > merg.payment_received_date ) else merg.payment_received_date share_acquisition = request.registry.share_acquisition share_id = share_acquisition.create( orig.membership_number, merg.num_shares, shares_date_of_acquisition) share_acquisition.set_signature_reception( share_id, date( merg.signature_received_date.year, merg.signature_received_date.month, merg.signature_received_date.day)) share_acquisition.set_signature_confirmation( share_id, date( merg.signature_confirmed_date.year, merg.signature_confirmed_date.month, merg.signature_confirmed_date.day)) share_acquisition.set_payment_reception( share_id, date( merg.payment_received_date.year, merg.payment_received_date.month, merg.payment_received_date.day)) share_acquisition.set_payment_confirmation( share_id, date( merg.payment_confirmed_date.year, merg.payment_confirmed_date.month, merg.payment_confirmed_date.day)) share_acquisition.set_reference_code( share_id, merg.email_confirm_code) DBSession.delete(merg) return HTTPFound(request.route_url('detail', memberid=member_id))
def merge_member_view(request): """ Merges member duplicates into one member record. Some people have more than one entry in our C3SMember table, e.g. because they used the application form more than once to acquire more shares. They shall not, however, become members twice and get more than one membership number. So we try and merge them: If a person is already a member and acquires a second package of shares, this package of shares is added to the former membership entry. The second entry in the C3sMember table is given the 'is_duplicate' flag and also the 'duplicate_of' is given the *id* of the original entry. """ afm_id = request.matchdict['afm_id'] member_id = request.matchdict['mid'] if DEBUG: # pragma: no cover print "shall merge {} to {}".format(afm_id, member_id) orig = C3sMember.get_by_id(member_id) merg = C3sMember.get_by_id(afm_id) if not orig.membership_accepted: request.session.flash( 'you can only merge to accepted members!', 'danger') HTTPFound(request.route_url('make_member', afm_id=afm_id)) exceeds_60 = int(orig.num_shares) + int(merg.num_shares) > 60 if exceeds_60: request.session.flash( 'merger would exceed 60 shares!', 'danger') return HTTPFound(request.route_url('make_member', afm_id=afm_id)) # TODO: this needs fixing!!! # date must be set manually according to date of approval of the board shares_date_of_acquisition = merg.signature_received_date if ( merg.signature_received_date > merg.payment_received_date ) else merg.payment_received_date share_acquisition = request.registry.share_acquisition share_id = share_acquisition.create( orig.membership_number, merg.num_shares, shares_date_of_acquisition) share_acquisition.set_signature_reception( share_id, date( merg.signature_received_date.year, merg.signature_received_date.month, merg.signature_received_date.day)) share_acquisition.set_signature_confirmation( share_id, date( merg.signature_confirmed_date.year, merg.signature_confirmed_date.month, merg.signature_confirmed_date.day)) share_acquisition.set_payment_reception( share_id, date( merg.payment_received_date.year, merg.payment_received_date.month, merg.payment_received_date.day)) share_acquisition.set_payment_confirmation( share_id, date( merg.payment_confirmed_date.year, merg.payment_confirmed_date.month, merg.payment_confirmed_date.day)) share_acquisition.set_reference_code( share_id, merg.email_confirm_code) DBSession.delete(merg) return HTTPFound(request.route_url('detail', member_id=member_id))
def _initTestingDB(): 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. members = C3sMember.get_all() for member in members: DBSession.delete(member) DBSession.flush() member1 = C3sMember( # german person firstname=u'SomeFirstnäme', lastname=u'SomeLastnäme', email=u'*****@*****.**', 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', ) member2 = C3sMember( # english person firstname=u'AAASomeFirstnäme', lastname=u'XXXSomeLastnäme', email=u'*****@*****.**', 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', ) member3 = C3sMember( # german legalentity firstname=u'Cooles PlattenLabel', lastname=u'SomeLastnäme', email=u'*****@*****.**', 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'ABCDEFG3', password=u'arandompassword', date_of_submission=date.today(), membership_type=u'normal', member_of_colsoc=False, name_of_colsoc=u"", num_shares=u'42', ) member4 = C3sMember( # english legalentity firstname=u'Incredible Records', lastname=u'XXXSomeLastnäme', email=u'*****@*****.**', 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'ABCDEFG4', password=u'arandompassword', date_of_submission=date.today(), membership_type=u'normal', member_of_colsoc=False, name_of_colsoc=u"", num_shares=u'2', ) member1.membership_accepted = True DBSession.add(member1) member2.membership_accepted = True DBSession.add(member2) member3.membership_accepted = True DBSession.add(member3) member4.membership_accepted = True DBSession.add(member4) DBSession.flush() return DBSession