def test_add_users_group(client: FlaskClient, admin_login): from dal.user import User client.post( endpoint('/users'), json={ 'first_name': 'John', 'last_name': 'Smith', 'email': '*****@*****.**', 'roles': [1], # admin 'attributes': {} }, headers=admin_login ) resp = client.post(endpoint('/user/groups')) assert resp.status_code == 401 users = User.query.all() assert len(users) == 2 resp = client.post(endpoint('/user/groups'), headers=admin_login, json={ 'ids': [r.id for r in users], 'name': 'Field Engineers'}) assert resp.status_code == 200 assert 'id' in resp.json
def test_add_installation_financial_info(client: FlaskClient, admin_login): from dal.customer import InstallationFinancing from dal.customer import Installation inst_id = Installation.query.first().id data = { 'installation_id': inst_id, 'financial_entity_id': 1, 'status_id': 1, 'request_date': front_end_date(), 'requested_amount': 1500000, 'assigned_official': 'Pedro Juan', 'official_phone': '8095659869', 'official_email': '*****@*****.**', 'insurance': 120000, 'number_of_payments': 30, 'payments_amount': 50000 } error = client.post(endpoint('/customers/installations/financing'), json=data) assert error.status_code == 401 assert 'error' in error.json resp = client.post(endpoint('/customers/installations/financing'), json=data, headers=admin_login) assert resp.status_code == 200 assert 'id' in resp.json assert InstallationFinancing.query.first() is not None
def test_html_to_pdf(client: FlaskClient, admin_login: dict): from urllib.parse import quote resp = client.post(endpoint('/to-pdf'), json={}) assert resp.status_code == 401 assert resp.json['error'] == 'Token is missing!' resp = client.post(endpoint('/to-pdf'), json={}, headers=admin_login) assert resp.status_code == 400 assert resp.json['error'] == 'Missing necessary arguments' data = { 'html': b64encode(quote('<div><h1>Hello</h1></div>').encode()).decode(), 'styles': b64encode(quote('<style>h1 {color: red;}</style>').encode()).decode(), 'extra_css': [ b64encode( quote( 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' ).encode()).decode() ], 'filename': 'filename' } resp = client.post(endpoint('/to-pdf'), json=data, headers=admin_login) assert resp.status_code == 200 assert isinstance(resp.data, bytes) assert resp.content_type == 'application/pdf' assert resp.headers[ 'Content-Disposition'] == "attachment; filename=filename.pdf"
def test_customer_data(client: FlaskClient, admin_login): from dal.customer import Customer customer_id = Customer.query.first().id error = client.get(endpoint('/customers/%s' % customer_id)) assert error.status_code == 401 assert 'error' in error.json customer = client.get(endpoint('/customers/%s' % customer_id), headers=admin_login) assert customer.status_code == 200 assert customer.json['first_name'] == 'Jon' assert customer.json['primary_phone'] == '1236589785' assert customer.json['source_project']['label'] == 'ENESTAR' assert isinstance(customer.json['customer_projects'], list) assert isinstance(customer.json['customer_projects'][0]['project_type'], dict) assert isinstance(customer.json['customer_projects'][0]['province'], dict) assert isinstance(customer.json['customer_projects'][0]['distributor'], dict) assert isinstance(customer.json['customer_projects'][0]['transformer'], dict) assert isinstance(customer.json['customer_projects'][0]['capacity'], dict) assert isinstance(customer.json['customer_projects'][0]['phase'], dict) assert isinstance(customer.json['customer_projects'][0]['tension'], dict) assert isinstance(customer.json['customer_projects'][0]['installations'], list) assert isinstance(customer.json['customer_projects'][0]['installations'][0]['panels'], list) assert isinstance(customer.json['customer_projects'][0]['installations'][0]['panels'][0], dict)
def test_sending_messages(client: FlaskClient): from dal.user import UserMessage resp = client.post(endpoint('/messages'), json={ 'user_id': user.id, 'subject': 'testing a subject', 'body': '<h1>Hello test</h1><p>This is the body</p>' }, headers={'X-System-Token': 'secret_key'}) assert resp.status_code == 401 resp = client.post(endpoint('/messages'), json={ 'user_id': user.id, 'subject': 'testing a subject', 'body': '<h1>Hello test</h1><p>This is the body</p>' }, headers={'X-System-Token': secret_key}) assert resp.status_code == 200 messages = UserMessage.query.all() assert len(messages) == 1 assert messages[0].user_id == user.id assert messages[0].read == False assert messages[0].subject == 'testing a subject' assert messages[0].message == '<h1>Hello test</h1><p>This is the body</p>'
def test_user_activates_account(client: FlaskClient): resp = client.post(endpoint('/account/activate-pass'), json={ 'token': 'bad-token', 'pw': 'badpassword', 'pw2': 'badpassword', }) assert resp.status_code == 400 assert 'Invalid token' in resp.json['error'] resp = client.post(endpoint('/account/activate-pass'), json={ 'token': user.token, 'pw': 'badpassword', 'pw2': 'badpassword', }) assert resp.status_code == 400 assert 'Invalid password' in resp.json['error'] resp = client.post(endpoint('/account/activate-pass'), json={ 'token': user.token, 'pw': 'mY$P@ssw0rd', 'pw2': 'mY$P@ssw0rd', }) assert resp.status_code == 200
def test_add_follow_up_note(client: FlaskClient, admin_login): from dal.customer import Installation from dal.customer import InstallationFollowUp from dal.user import Commentable inst_id = Installation.query.first().id date = datetime.datetime.utcnow() + relativedelta(days=7) payload = { 'installation_id': inst_id, 'alert_group_id': 1, 'next_follow_up': front_end_date(date), 'comment': 'This is a user note' } resp = client.post(endpoint('/customers/installations/follow-up'), json=payload) assert resp.status_code == 401 resp = client.post(endpoint('/customers/installations/follow-up'), json=payload, headers=admin_login) assert resp.status_code == 200 assert 'id' in resp.json n = Commentable.query.count() assert n == 1 follow_ups = InstallationFollowUp.query.all() assert len(follow_ups) == 1
def test_get_installation_follow_ups_with_comments(client: FlaskClient, admin_login): from dal.customer import Installation inst_id = Installation.query.first().id resp = client.get(endpoint('/customers/installations/follow-up'), headers=admin_login) assert resp.status_code == 400 resp = client.get(endpoint('/customers/installations/follow-up?installation_id=inst_id')) assert resp.status_code == 401 resp = client.get( endpoint('/customers/installations/follow-up?installation_id={}'.format(inst_id)), headers=admin_login ) assert resp.status_code == 200 assert len(resp.json) == 1 assert 'comments' in resp.json[0] assert len(resp.json[0]['comments']) == 2 assert 'user' in resp.json[0]['comments'][0] assert 'comment' in resp.json[0]['comments'][0] assert resp.json[0]['comments'][0]['comment'] == 'This is a user note' assert 'date' in resp.json[0]['comments'][0] assert 'next_follow_up' in resp.json[0] assert 'alert_group' in resp.json[0] assert len(resp.json[0]['alert_group']['users']) == 2 date = datetime.datetime.utcnow() + relativedelta(days=3) payload = { 'installation_id': inst_id, 'alert_group_id': 2, 'next_follow_up': front_end_date(date), 'comment': 'This is a comment in a different follow up' } resp = client.post(endpoint('/customers/installations/follow-up'), json=payload, headers=admin_login) assert resp.status_code == 200 assert 'id' in resp.json resp = client.get( endpoint('/customers/installations/follow-up?installation_id={}'.format(inst_id)), headers=admin_login ) assert len(resp.json[0]['comments']) == 2 assert len(resp.json) == 2 assert 'comments' in resp.json[1] assert len(resp.json[1]['comments']) == 1 assert 'user' in resp.json[1]['comments'][0] assert 'comment' in resp.json[1]['comments'][0] assert resp.json[1]['comments'][0]['comment'] == 'This is a comment in a different follow up' assert 'date' in resp.json[1]['comments'][0] assert 'next_follow_up' in resp.json[1] assert 'alert_group' in resp.json[1] assert len(resp.json[1]['alert_group']['users']) == 1
def test_customer_installation_data(client: FlaskClient, admin_login): from dal.customer import Customer customer_id = Customer.query.first().id error = client.get(endpoint('/customers/%s' % customer_id)) assert error.status_code == 401 assert 'error' in error.json customer = client.get(endpoint('/customers/%s' % customer_id), headers=admin_login) assert customer.json['customer_projects'][0]['installations'][0]['installation_size'] == 'Comercial Grande' assert customer.json['customer_projects'][0]['installations'][0]['total_investment'] == '331250.00' assert customer.json['customer_projects'][0]['installations'][0]['annual_production'] == '178875.00' assert customer.json['customer_projects'][0]['installations'][0]['panels'][0]['quantity'] == 5 assert isinstance(customer.json['customer_projects'][0]['installations'][0]['panels'][0]['serials'], list) assert len(customer.json['customer_projects'][0]['installations'][0]['panels'][0]['serials']) == 5 assert isinstance(customer.json['customer_projects'][0]['installations'][0]['inverters'], list) assert isinstance(customer.json['customer_projects'][0]['installations'][0]['inverters'][0], dict) assert customer.json['customer_projects'][0]['installations'][0]['inverters'][0]['quantity'] == 2 assert isinstance(customer.json['customer_projects'][0]['installations'][0]['inverters'][0]['serials'], list) assert len(customer.json['customer_projects'][0]['installations'][0]['inverters'][0]['serials']) == 2 assert isinstance(customer.json['customer_projects'][0]['installations'][0]['installation_documents'], list) assert len(customer.json['customer_projects'][0]['installations'][0]['installation_documents']) == 1 assert customer.json['customer_projects'][0]['installations'][0]['installation_documents'][0]['name'] == 'SOMETHING' assert customer.json['customer_projects'][0]['installations'][0]['installation_documents'][0]['category'] == 'Legal' assert 'documents/1/' in \ customer.json['customer_projects'][0]['installations'][0]['installation_documents'][0]['object_key'] assert isinstance(customer.json['customer_projects'][0]['installations'][0]['setup_summary'], dict) assert 'historical_consumption' in customer.json['customer_projects'][0]['installations'][0]['setup_summary'] assert isinstance( customer.json['customer_projects'][0]['installations'][0]['setup_summary']['historical_consumption'], list ) assert len(customer.json['customer_projects'][0]['installations'][0]['setup_summary']['historical_consumption']) == 3 assert customer.json['customer_projects'][0]['installations'][0]['setup_summary']['historical_consumption'][1]['value'] == 220 assert 'historical_power' in customer.json['customer_projects'][0]['installations'][0]['setup_summary'] assert isinstance( customer.json['customer_projects'][0]['installations'][0]['setup_summary']['historical_power'], list ) assert customer.json['customer_projects'][0]['installations'][0]['setup_summary']['historical_power'][2]['value'] == 15 assert 'expected_generation' in customer.json['customer_projects'][0]['installations'][0]['setup_summary'] assert isinstance( customer.json['customer_projects'][0]['installations'][0]['setup_summary']['expected_generation'], list ) assert customer.json['customer_projects'][0]['installations'][0]['setup_summary']['expected_generation'][0]['value'] == 210 assert 'status' in customer.json['customer_projects'][0]['installations'][0] assert customer.json['customer_projects'][0]['installations'][0]['status']['status'] == 'Levantamiendo', \ 'Should have initial status as no dates have been input'
def test_mark_notification_read(client: FlaskClient, admin_login): resp = client.get(endpoint('/messages'), headers=admin_login) _id = resp.json['list'][0]['id'] resp = client.put(endpoint('/messages/%s' % _id)) assert resp.status_code == 200 resp = client.get(endpoint('/messages'), headers=admin_login) assert 'read' in resp.json['list'][0] assert resp.json['list'][0]['read'] == True
def test_run_widget(client: FlaskClient, admin_login: dict): resp = client.get(endpoint('/widgets/dont-exist'), headers=admin_login) assert resp.status_code == 404 # resp = client.get(endpoint('/widgets/schema_name'), headers=admin_login) # assert resp.status_code == 200 # assert type(resp.json) == list resp = client.get(endpoint('/widgets/new_users?type=private'), headers=admin_login) assert resp.status_code == 200 assert type(resp.json) == list assert len(resp.json) == 1
def test_project_add_installation(client: FlaskClient, admin_login): customer = client.get(endpoint('/customers'), headers=admin_login) customer_id = customer.json['list'][0]['id'] customer = client.get(endpoint('/customers/%s' % customer_id), headers=admin_login) project_id = customer.json['customer_projects'][0]['id'] data = { 'installed_capacity': 1325, 'egauge_url': 'http://enestar170.egaug.es', 'egauge_serial': 'AC4654S5E6H46455', 'egauge_mac': 'ec:35:86:2e:8c:0c', 'start_date': front_end_date(), 'specific_yield': 135, 'project_id': project_id, 'sale_type_id': 1, 'price_per_kwp': 250, 'responsible_party': 'Juan Pedro', 'panels': [ {'id': 1, 'quantity': 5, 'serials': ['AD2', 'AG3', 'TG4', 'GT5', '5G5']}, {'id': 2, 'quantity': 2, 'serials': ['GT5', '5G5']} ], 'inverters': [{'id': 2, 'quantity': 2, 'serials': ['GF5', '5P5']}, {'id': 2, 'quantity': 1, 'serials': ['JT5', '5GF']}], 'setup_summary': { 'historical_consumption': [ {'year': 2018, 'month': 1, 'value': 200}, {'year': 2018, 'month': 2, 'value': 220}, {'year': 2018, 'month': 3, 'value': 170} ], 'historical_power': [ {'year': 2018, 'month': 1, 'value': 10}, {'year': 2018, 'month': 2, 'value': 9}, {'year': 2018, 'month': 3, 'value': 15} ], 'expected_generation': [ {'year': 2018, 'month': 1, 'value': 210}, {'year': 2018, 'month': 2, 'value': 215}, {'year': 2018, 'month': 3, 'value': 240} ] } } error = client.post(endpoint('/customers/installations'), json=data) assert error.status_code == 401 assert 'error' in error.json resp = client.post(endpoint('/customers/installations'), json=data, headers=admin_login) assert resp.status_code == 200 assert 'id' in resp.json
def test_widgets_return_models(client: FlaskClient, admin_login: dict): resp = client.get(endpoint('/widgets')) assert resp.status_code == 401 assert resp.json['error'] == 'Token is missing!' resp = client.get(endpoint('/widgets'), headers=admin_login) assert resp.status_code == 200 assert isinstance(resp.json, list) assert len(resp.json) == 10 assert resp.json[2]['class'] == 'dal.user.UserMessage' assert len(resp.json[2]['fields']) == 6 assert len(resp.json[2]['relationships']) == 1 assert resp.json[2]['relationships'][0]['class'] == 'dal.user.User' assert resp.json[2]['relationships'][0]['name'] == 'user'
def test_fetch_company(no_db_client): resp = no_db_client.get(endpoint('/company')) assert 'name' in resp.json assert 'logo' in resp.json assert resp.json['logo'] is not None assert isinstance(resp.json['logo'], str) assert isinstance(b64decode(resp.json['logo']), bytes)
def test_new_user_can_login(client: FlaskClient): auth = { 'Authorization': 'Basic ' + b64encode(b'[email protected]:mY$P@ssw0rd').decode() } login_resp = client.post(endpoint('/login'), headers=auth) assert 'token' in login_resp.json, 'token expected' assert login_resp.status_code == 200
def test_customer_installation_financial_info_updated(client: FlaskClient, admin_login): from dal.customer import Customer customer_id = Customer.query.first().id customer = client.get(endpoint('/customers/%s' % customer_id), headers=admin_login) assert customer.json['customer_projects'][0]['installations'][0]['financing']['approved_rate'] == 25.53 assert customer.json['customer_projects'][0]['installations'][0]['financing']['retention_percentage'] == 2 assert customer.json['customer_projects'][0]['installations'][0]['financing']['status']['label'] == 'ESPERANDO RESPUESTA'
def test_user_verifies_account(client: FlaskClient): from dal.user import UserToken verification_token = UserToken.query.first() assert verification_token is not None verification = client.get(endpoint('/user-tokens/badtoken')) assert verification.status_code == 400 assert 'isValid' in verification.json assert verification.json['isValid'] == False verification = client.get( endpoint('/user-tokens/%s' % verification_token.token)) assert verification.status_code == 200 assert 'isValid' in verification.json assert verification.json['isValid'] == True user.token = verification_token.token
def test_update_follow_up_note(client: FlaskClient, admin_login): from dal.customer import Installation fu_id = Installation.query.first().follow_ups[0].id payload = {'comment': 'This is another comment'} resp = client.put( endpoint('/customers/installations/follow-up/{}'.format(fu_id)), json=payload, headers=admin_login ) assert resp.status_code == 201
def test_login(no_db_client): auth = { 'Authorization': 'Basic ' + b64encode(b'*****@*****.**' + b':' + b'master').decode() } rv = no_db_client.post(endpoint('/login'), headers=auth) assert rv.json['user']['email'] == '*****@*****.**' assert 'value' in rv.json['token'] assert rv.status_code == 200
def test_update_installation_financial_info(client: FlaskClient, admin_login): from dal.customer import Installation inst_id = Installation.query.first().id data = { 'installation_id': inst_id, 'status_id': 2, 'approved_rate': 25.53, 'retention_percentage': 2, } error = client.put(endpoint('/customers/installations/financing/{}'.format(inst_id)), json=data) assert error.status_code == 401 assert 'error' in error.json resp = client.put(endpoint('/customers/installations/financing/{}'.format(inst_id)), json=data, headers=admin_login) assert resp.status_code == 201
def test_user_changes_password(client: FlaskClient): from dal.user import UserToken resp = client.put(endpoint('/users/reset-password')) assert resp.status_code == 400 assert 'error' in resp.json assert 'Missing email' in resp.json['error'] resp = client.put(endpoint('/users/reset-password'), json={'email': '*****@*****.**'}) assert resp.status_code == 200 assert len(resources.mails ) == 1, 'no email has been sent because user does not exist' resp = client.put(endpoint('/users/reset-password'), json={'email': '*****@*****.**'}) assert resp.status_code == 200 assert UserToken.query.count() == 2 assert len(resources.mails) == 2, 'an email should have been sent' token = UserToken.query.offset(1).first() assert token is not None resp = client.post(endpoint('/account/activate-pass'), json={ 'token': token.token, 'pw': '@noth3rp@22w04d', 'pw2': '@noth3rp@22w04d', }) assert resp.status_code == 200 auth = { 'Authorization': 'Basic ' + b64encode(b'[email protected]:@noth3rp@22w04d').decode() } login_resp = client.post(endpoint('/login'), headers=auth) assert 'token' in login_resp.json, 'token expected' assert login_resp.status_code == 200
def test_new_customer(client: FlaskClient, admin_login): data = { 'first_name': 'James', 'last_name': 'Smith', 'primary_email': '*****@*****.**', 'identification_number': 423545689, 'primary_phone': '1236589785', 'secondary_phone': '6345642356', 'address': 'Calle 1 #245 Barrio Nuevo Santiago', 'source_project_id': 1, 'province_id': 1, } error = client.post(endpoint('/customers'), json=data) assert error.status_code == 401 assert 'error' in error.json resp = client.post(endpoint('/customers'), json=data, headers=admin_login) assert resp.status_code == 200 assert 'id' in resp.json
def test_add_invalid_installation_documents(client: FlaskClient, admin_login: dict): from dal.customer import Installation data = { 'category': 'Bad', 'name': 'bad_file', 'installation_id': Installation.query.first().id, 'file': (io.BytesIO(b'12345AF3DC13D'), 'file.pdf'), } error = client.post(endpoint('/customers/documents'), data={}, content_type='multipart/form-data') assert error.status_code == 401 assert 'error' in error.json resp1 = client.post( endpoint('/customers/documents'), data=data, content_type='multipart/form-data', headers=admin_login ) assert resp1.status_code == 400 assert 'Invalid Category' in resp1.json['error']
def test_customer_add_project(client: FlaskClient, admin_login): customer = client.get(endpoint('/customers'), headers=admin_login) assert 'list' in customer.json assert 'page' in customer.json assert 'total_pages' in customer.json assert len(customer.json['list']) == 1 _id = customer.json['list'][0]['id'] assert isinstance(_id, int) data = { 'name': 'Solar Panels', 'address': 'C/2 #567 Villa Eliza', 'lat': '19.473475', 'long': '-70.714767', 'nic': 4654, 'nic_title': 'Emmanuel Reinoso', 'circuit': 'Something something', 'ct': 64545, 'province_id': 5, # Distrito Nacional 'project_type_id': 1, # COMERCIAL 'customer_id': _id, 'distributor_id': 2, # EDESUR 'rate_id': 2, # BTS2 'transformer_id': 1, # PROPIO 'tr_capacity_id': 3, # 75 'phase_id': 2, # TRIFASICO 'tension_id': 2, # 240 } error = client.post(endpoint('/customers/projects'), json=data) assert error.status_code == 401 assert 'error' in error.json resp = client.post(endpoint('/customers/projects'), json=data, headers=admin_login) assert resp.status_code == 200 assert 'id' in resp.json
def test_customer_data_has_installation_financial_info(client: FlaskClient, admin_login): from dal.customer import Customer customer_id = Customer.query.first().id customer = client.get(endpoint('/customers/%s' % customer_id), headers=admin_login) assert 'financing' in customer.json['customer_projects'][0]['installations'][0] assert customer.json['customer_projects'][0]['installations'][0]['financing']['response_date'] is None assert customer.json['customer_projects'][0]['installations'][0]['financing']['request_date'] is not None assert customer.json['customer_projects'][0]['installations'][0]['financing']['requested_amount'] == '1500000.00' assert customer.json['customer_projects'][0]['installations'][0]['financing']['payments_amount'] == '50000.00' assert customer.json['customer_projects'][0]['installations'][0]['financing']['status']['label'] == 'INICIADO' assert customer.json['customer_projects'][0]['installations'][0]['financing']['financial_entity']['name'] == 'BANCO MULTIPLE ACTIVO DOMINICANA, S. A.'
def admin_login(client: FlaskClient): admin_resp = seed_admin(client) assert b'Redirecting...' in admin_resp.data, 'Must redirect upon valid admin creation' assert admin_resp.status_code == 302 auth = { 'Authorization': 'Basic ' + b64encode(b'[email protected]:' + b'secured').decode() } # create a session login_resp = client.post(endpoint('/login'), headers=auth) assert 'token' in login_resp.json, 'token expected' assert login_resp.status_code == 200 return {'X-Access-Token': login_resp.json['token']['value']}
def test_update_customer_info(client: FlaskClient, admin_login): from dal.customer import Customer c_id = Customer.query.first().id assert c_id is not None data = { 'id': c_id, 'first_name': 'Jon', 'secondary_email': '*****@*****.**' } resp = client.put(endpoint('/customers/%s' % c_id), json=data, headers=admin_login) assert resp.status_code == 201 customer = Customer.query.first() assert customer.first_name == 'Jon' assert customer.secondary_email == '*****@*****.**'
def test_get_user_group(client: FlaskClient, admin_login): from dal.user import UserGroup up_id = UserGroup.query.first().id resp = client.get(endpoint('/user/groups/{}'.format(up_id)), headers=admin_login) assert resp.status_code == 200 assert resp.json['name'] == 'FIELD ENGINEERS' assert len(resp.json['users']) == 2 assert resp.json['users'][0]['name'] == 'Test User' assert resp.json['users'][1]['name'] == 'John Smith' # test proper group returns user = client.post( endpoint('/users'), json={ 'first_name': 'Peter', 'last_name': 'Gabriel', 'email': '*****@*****.**', 'roles': [1], # admin 'attributes': {} }, headers=admin_login ) user_id = user.json['id'] resp = client.post(endpoint('/user/groups'), headers=admin_login, json={ 'ids': [user_id], 'name': 'Second Group'}) group_id = resp.json['id'] resp = client.get(endpoint('/user/groups/{}'.format(group_id)), headers=admin_login) assert resp.status_code == 200 assert resp.json['name'] == 'SECOND GROUP' assert len(resp.json['users']) == 1 assert resp.json['users'][0]['name'] == 'Peter Gabriel' # test getting all groups resp = client.get(endpoint('/user/groups')) assert resp.status_code == 401 resp = client.get(endpoint('/user/groups'), headers=admin_login) assert resp.status_code == 200 assert len(resp.json) == 2 assert resp.json['FIELD ENGINEERS']['name'] == 'FIELD ENGINEERS' assert len(resp.json['FIELD ENGINEERS']['users']) == 2 assert resp.json['FIELD ENGINEERS']['users'][0]['name'] == 'Test User' assert resp.json['FIELD ENGINEERS']['users'][1]['name'] == 'John Smith' assert resp.json['SECOND GROUP']['name'] == 'SECOND GROUP' assert len(resp.json['SECOND GROUP']['users']) == 1 assert resp.json['SECOND GROUP']['users'][0]['name'] == 'Peter Gabriel'
def test_admin_create_user(client: FlaskClient, admin_login: dict): resp = client.post( endpoint('/users'), json={ 'first_name': 'John', 'last_name': 'Smith', 'email': '*****@*****.**', 'roles': [1], # admin 'attributes': {} }, headers=admin_login) assert 'id' in resp.json assert resp.status_code == 200 assert len(resources.mails) == 1 user.id = resp.json['id']
def test_countries(client: FlaskClient, admin_login): resp = client.get(endpoint('/meta/countries'), headers=admin_login) assert resp.status_code == 200 assert len(resp.json) == 2 for country in resp.json: if country['name'] == 'Republica Dominicana': assert len(country['provinces']) == 32 else: assert len(country['provinces']) == 59 from dal.customer import Country countries = Country.query.all() assert len(countries) == 2 for country in countries: assert len(country.provinces) > 30