| @@ 4606-4671 (lines=66) @@ | ||
| 4603 | res = res.json_body |
|
| 4604 | assert res['email'] == '[email protected]' |
|
| 4605 | ||
| 4606 | def test_api__set_user_email__err_400__admin_string_is_not_email(self): |
|
| 4607 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4608 | admin = dbsession.query(models.User) \ |
|
| 4609 | .filter(models.User.email == '[email protected]') \ |
|
| 4610 | .one() |
|
| 4611 | uapi = UserApi( |
|
| 4612 | current_user=admin, |
|
| 4613 | session=dbsession, |
|
| 4614 | config=self.app_config, |
|
| 4615 | ) |
|
| 4616 | gapi = GroupApi( |
|
| 4617 | current_user=admin, |
|
| 4618 | session=dbsession, |
|
| 4619 | config=self.app_config, |
|
| 4620 | ) |
|
| 4621 | groups = [gapi.get_one_with_name('users')] |
|
| 4622 | test_user = uapi.create_user( |
|
| 4623 | email='[email protected]', |
|
| 4624 | password='pass', |
|
| 4625 | name='bob', |
|
| 4626 | groups=groups, |
|
| 4627 | timezone='Europe/Paris', |
|
| 4628 | lang='fr', |
|
| 4629 | do_save=True, |
|
| 4630 | do_notify=False, |
|
| 4631 | ) |
|
| 4632 | uapi.save(test_user) |
|
| 4633 | transaction.commit() |
|
| 4634 | user_id = int(test_user.user_id) |
|
| 4635 | ||
| 4636 | self.testapp.authorization = ( |
|
| 4637 | 'Basic', |
|
| 4638 | ( |
|
| 4639 | '[email protected]', |
|
| 4640 | '[email protected]' |
|
| 4641 | ) |
|
| 4642 | ) |
|
| 4643 | # check before |
|
| 4644 | res = self.testapp.get( |
|
| 4645 | '/api/v2/users/{}'.format(user_id), |
|
| 4646 | status=200 |
|
| 4647 | ) |
|
| 4648 | res = res.json_body |
|
| 4649 | assert res['email'] == '[email protected]' |
|
| 4650 | ||
| 4651 | # Set password |
|
| 4652 | params = { |
|
| 4653 | 'email': 'thatisnotandemail', |
|
| 4654 | 'loggedin_user_password': '[email protected]', |
|
| 4655 | } |
|
| 4656 | res = self.testapp.put_json( |
|
| 4657 | '/api/v2/users/{}/email'.format(user_id), |
|
| 4658 | params=params, |
|
| 4659 | status=400, |
|
| 4660 | ) |
|
| 4661 | # TODO - G.M - 2018-09-10 - Handled by marshmallow schema |
|
| 4662 | assert res.json_body |
|
| 4663 | assert 'code' in res.json_body |
|
| 4664 | assert res.json_body['code'] == error.GENERIC_SCHEMA_VALIDATION_ERROR # nopep8 |
|
| 4665 | # Check After |
|
| 4666 | res = self.testapp.get( |
|
| 4667 | '/api/v2/users/{}'.format(user_id), |
|
| 4668 | status=200 |
|
| 4669 | ) |
|
| 4670 | res = res.json_body |
|
| 4671 | assert res['email'] == '[email protected]' |
|
| 4672 | ||
| 4673 | def test_api__set_user_email__ok_200__user_itself(self): |
|
| 4674 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 4540-4604 (lines=65) @@ | ||
| 4537 | res = res.json_body |
|
| 4538 | assert res['email'] == '[email protected]' |
|
| 4539 | ||
| 4540 | def test_api__set_user_email__err_403__admin_wrong_password(self): |
|
| 4541 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4542 | admin = dbsession.query(models.User) \ |
|
| 4543 | .filter(models.User.email == '[email protected]') \ |
|
| 4544 | .one() |
|
| 4545 | uapi = UserApi( |
|
| 4546 | current_user=admin, |
|
| 4547 | session=dbsession, |
|
| 4548 | config=self.app_config, |
|
| 4549 | ) |
|
| 4550 | gapi = GroupApi( |
|
| 4551 | current_user=admin, |
|
| 4552 | session=dbsession, |
|
| 4553 | config=self.app_config, |
|
| 4554 | ) |
|
| 4555 | groups = [gapi.get_one_with_name('users')] |
|
| 4556 | test_user = uapi.create_user( |
|
| 4557 | email='[email protected]', |
|
| 4558 | password='pass', |
|
| 4559 | name='bob', |
|
| 4560 | groups=groups, |
|
| 4561 | timezone='Europe/Paris', |
|
| 4562 | lang='fr', |
|
| 4563 | do_save=True, |
|
| 4564 | do_notify=False, |
|
| 4565 | ) |
|
| 4566 | uapi.save(test_user) |
|
| 4567 | transaction.commit() |
|
| 4568 | user_id = int(test_user.user_id) |
|
| 4569 | ||
| 4570 | self.testapp.authorization = ( |
|
| 4571 | 'Basic', |
|
| 4572 | ( |
|
| 4573 | '[email protected]', |
|
| 4574 | '[email protected]' |
|
| 4575 | ) |
|
| 4576 | ) |
|
| 4577 | # check before |
|
| 4578 | res = self.testapp.get( |
|
| 4579 | '/api/v2/users/{}'.format(user_id), |
|
| 4580 | status=200 |
|
| 4581 | ) |
|
| 4582 | res = res.json_body |
|
| 4583 | assert res['email'] == '[email protected]' |
|
| 4584 | ||
| 4585 | # Set password |
|
| 4586 | params = { |
|
| 4587 | 'email': '[email protected]', |
|
| 4588 | 'loggedin_user_password': 'badpassword', |
|
| 4589 | } |
|
| 4590 | res = self.testapp.put_json( |
|
| 4591 | '/api/v2/users/{}/email'.format(user_id), |
|
| 4592 | params=params, |
|
| 4593 | status=403, |
|
| 4594 | ) |
|
| 4595 | assert res.json_body |
|
| 4596 | assert 'code' in res.json_body |
|
| 4597 | assert res.json_body['code'] == error.WRONG_USER_PASSWORD # nopep8 |
|
| 4598 | # Check After |
|
| 4599 | res = self.testapp.get( |
|
| 4600 | '/api/v2/users/{}'.format(user_id), |
|
| 4601 | status=200 |
|
| 4602 | ) |
|
| 4603 | res = res.json_body |
|
| 4604 | assert res['email'] == '[email protected]' |
|
| 4605 | ||
| 4606 | def test_api__set_user_email__err_400__admin_string_is_not_email(self): |
|
| 4607 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 4474-4538 (lines=65) @@ | ||
| 4471 | res = res.json_body |
|
| 4472 | assert res['email'] == '[email protected]' |
|
| 4473 | ||
| 4474 | def test_api__set_user_email__err_400__admin_same_email(self): |
|
| 4475 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4476 | admin = dbsession.query(models.User) \ |
|
| 4477 | .filter(models.User.email == '[email protected]') \ |
|
| 4478 | .one() |
|
| 4479 | uapi = UserApi( |
|
| 4480 | current_user=admin, |
|
| 4481 | session=dbsession, |
|
| 4482 | config=self.app_config, |
|
| 4483 | ) |
|
| 4484 | gapi = GroupApi( |
|
| 4485 | current_user=admin, |
|
| 4486 | session=dbsession, |
|
| 4487 | config=self.app_config, |
|
| 4488 | ) |
|
| 4489 | groups = [gapi.get_one_with_name('users')] |
|
| 4490 | test_user = uapi.create_user( |
|
| 4491 | email='[email protected]', |
|
| 4492 | password='pass', |
|
| 4493 | name='bob', |
|
| 4494 | groups=groups, |
|
| 4495 | timezone='Europe/Paris', |
|
| 4496 | lang='fr', |
|
| 4497 | do_save=True, |
|
| 4498 | do_notify=False, |
|
| 4499 | ) |
|
| 4500 | uapi.save(test_user) |
|
| 4501 | transaction.commit() |
|
| 4502 | user_id = int(test_user.user_id) |
|
| 4503 | ||
| 4504 | self.testapp.authorization = ( |
|
| 4505 | 'Basic', |
|
| 4506 | ( |
|
| 4507 | '[email protected]', |
|
| 4508 | '[email protected]' |
|
| 4509 | ) |
|
| 4510 | ) |
|
| 4511 | # check before |
|
| 4512 | res = self.testapp.get( |
|
| 4513 | '/api/v2/users/{}'.format(user_id), |
|
| 4514 | status=200 |
|
| 4515 | ) |
|
| 4516 | res = res.json_body |
|
| 4517 | assert res['email'] == '[email protected]' |
|
| 4518 | ||
| 4519 | # Set password |
|
| 4520 | params = { |
|
| 4521 | 'email': '[email protected]', |
|
| 4522 | 'loggedin_user_password': '[email protected]', |
|
| 4523 | } |
|
| 4524 | res = self.testapp.put_json( |
|
| 4525 | '/api/v2/users/{}/email'.format(user_id), |
|
| 4526 | params=params, |
|
| 4527 | status=400, |
|
| 4528 | ) |
|
| 4529 | assert res.json_body |
|
| 4530 | assert 'code' in res.json_body |
|
| 4531 | assert res.json_body['code'] == error.EMAIL_ALREADY_EXIST_IN_DB |
|
| 4532 | # Check After |
|
| 4533 | res = self.testapp.get( |
|
| 4534 | '/api/v2/users/{}'.format(user_id), |
|
| 4535 | status=200 |
|
| 4536 | ) |
|
| 4537 | res = res.json_body |
|
| 4538 | assert res['email'] == '[email protected]' |
|
| 4539 | ||
| 4540 | def test_api__set_user_email__err_403__admin_wrong_password(self): |
|
| 4541 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 5352-5413 (lines=62) @@ | ||
| 5349 | """ |
|
| 5350 | fixtures = [BaseFixture] |
|
| 5351 | ||
| 5352 | def test_api__set_user_profile__ok_200__admin(self): |
|
| 5353 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 5354 | admin = dbsession.query(models.User) \ |
|
| 5355 | .filter(models.User.email == '[email protected]') \ |
|
| 5356 | .one() |
|
| 5357 | uapi = UserApi( |
|
| 5358 | current_user=admin, |
|
| 5359 | session=dbsession, |
|
| 5360 | config=self.app_config, |
|
| 5361 | ) |
|
| 5362 | gapi = GroupApi( |
|
| 5363 | current_user=admin, |
|
| 5364 | session=dbsession, |
|
| 5365 | config=self.app_config, |
|
| 5366 | ) |
|
| 5367 | groups = [gapi.get_one_with_name('users')] |
|
| 5368 | test_user = uapi.create_user( |
|
| 5369 | email='[email protected]', |
|
| 5370 | password='pass', |
|
| 5371 | name='bob', |
|
| 5372 | groups=groups, |
|
| 5373 | timezone='Europe/Paris', |
|
| 5374 | lang='fr', |
|
| 5375 | do_save=True, |
|
| 5376 | do_notify=False, |
|
| 5377 | ) |
|
| 5378 | uapi.save(test_user) |
|
| 5379 | transaction.commit() |
|
| 5380 | user_id = int(test_user.user_id) |
|
| 5381 | ||
| 5382 | self.testapp.authorization = ( |
|
| 5383 | 'Basic', |
|
| 5384 | ( |
|
| 5385 | '[email protected]', |
|
| 5386 | '[email protected]' |
|
| 5387 | ) |
|
| 5388 | ) |
|
| 5389 | # check before |
|
| 5390 | res = self.testapp.get( |
|
| 5391 | '/api/v2/users/{}'.format(user_id), |
|
| 5392 | status=200 |
|
| 5393 | ) |
|
| 5394 | res = res.json_body |
|
| 5395 | assert res['user_id'] == user_id |
|
| 5396 | assert res['profile'] == 'users' |
|
| 5397 | # Set params |
|
| 5398 | params = { |
|
| 5399 | 'profile': 'administrators', |
|
| 5400 | } |
|
| 5401 | self.testapp.put_json( |
|
| 5402 | '/api/v2/users/{}/profile'.format(user_id), |
|
| 5403 | params=params, |
|
| 5404 | status=204, |
|
| 5405 | ) |
|
| 5406 | # Check After |
|
| 5407 | res = self.testapp.get( |
|
| 5408 | '/api/v2/users/{}'.format(user_id), |
|
| 5409 | status=200 |
|
| 5410 | ) |
|
| 5411 | res = res.json_body |
|
| 5412 | assert res['user_id'] == user_id |
|
| 5413 | assert res['profile'] == 'administrators' |
|
| 5414 | ||
| 5415 | def test_api__set_user_profile__err_400__admin_itself(self): |
|
| 5416 | """ |
|