def populate_departments_dbs(departments_dbs, ids):
    ids['state'] = {}
    for db_name in departments_dbs:
        if db_name == 'users':
            continue
        else:
            for state in states:
                ids['state'][state] = StateService.add(departments_dbs[db_name], state)
    for idsender in ids['useraddress']:
        for _ in range(50):
            idreceiver = random.randint(0, len(ids['useraddress']) - 1)
            MailService.add(departments_dbs, 0, idsender, ids['useraddress'][idreceiver])        
              'D1': db_d1 }

codes.codes = { "01": "D1" }
codes.rev_codes = { "D1": "01" }


a1 = AddressService.add(db_users, "A1")
a2 = AddressService.add(db_users, "A2")
d1 = DepartmentService.add(db_users, "D1")
s1 = StateService.add(db_users, "S1")
s2 = StateService.add(db_users, "S2")
s3 = StateService.add(db_users, "S3")
u1 = UserService.add(db_users, 2013400576, "U1", "[email protected]", d1)
ua1 = UserAddressService.add(db_users, a1, u1)
ua2 = UserAddressService.add(db_users, a2, u1)
bc = MailService.add(databases, s1, ua1, ua2)

las = UserAddressService.listByUser(db_users, u1)

selectedMail = MailService.selectByBarcode(databases['D1'], bc)

print las

print a1
print d1
print s1
print u1
print ua1
print bc
print selectedMail