|
198 | 198 | 'links': base_url + 'services/' + service_id, |
199 | 199 | } |
200 | 200 |
|
201 | | -credential_id = 'c-123' |
202 | | - |
203 | 201 | endpoint_id = 'e-123' |
204 | 202 | endpoint_url = 'http://127.0.0.1:35357' |
205 | 203 | endpoint_region = 'RegionOne' |
@@ -639,3 +637,104 @@ def create_one_domain(attrs=None): |
639 | 637 | domain = fakes.FakeResource(info=copy.deepcopy(domain_info), |
640 | 638 | loaded=True) |
641 | 639 | return domain |
| 640 | + |
| 641 | + |
| 642 | +class FakeCredential(object): |
| 643 | + """Fake one or more credential.""" |
| 644 | + |
| 645 | + @staticmethod |
| 646 | + def create_one_credential(attrs=None): |
| 647 | + """Create a fake credential. |
| 648 | +
|
| 649 | + :param Dictionary attrs: |
| 650 | + A dictionary with all attributes |
| 651 | + :return: |
| 652 | + A FakeResource object, with id, type, and so on |
| 653 | + """ |
| 654 | + |
| 655 | + attrs = attrs or {} |
| 656 | + |
| 657 | + # set default attributes. |
| 658 | + credential_info = { |
| 659 | + 'id': 'credential-id-' + uuid.uuid4().hex, |
| 660 | + 'type': 'cert', |
| 661 | + 'user_id': 'user-id-' + uuid.uuid4().hex, |
| 662 | + 'blob': 'credential-data-' + uuid.uuid4().hex, |
| 663 | + 'project_id': 'project-id-' + uuid.uuid4().hex, |
| 664 | + 'links': 'links-' + uuid.uuid4().hex, |
| 665 | + } |
| 666 | + credential_info.update(attrs) |
| 667 | + |
| 668 | + credential = fakes.FakeResource( |
| 669 | + info=copy.deepcopy(credential_info), loaded=True) |
| 670 | + return credential |
| 671 | + |
| 672 | + @staticmethod |
| 673 | + def create_credentials(attrs=None, count=2): |
| 674 | + """Create multiple fake credentials. |
| 675 | +
|
| 676 | + :param Dictionary attrs: |
| 677 | + A dictionary with all attributes |
| 678 | + :param int count: |
| 679 | + The number of credentials to fake |
| 680 | + :return: |
| 681 | + A list of FakeResource objects faking the credentials |
| 682 | + """ |
| 683 | + credentials = [] |
| 684 | + for i in range(0, count): |
| 685 | + credential = FakeCredential.create_one_credential(attrs) |
| 686 | + credentials.append(credential) |
| 687 | + |
| 688 | + return credentials |
| 689 | + |
| 690 | + @staticmethod |
| 691 | + def get_credentials(credentials=None, count=2): |
| 692 | + """Get an iterable MagicMock object with a list of faked credentials. |
| 693 | +
|
| 694 | + If credentials list is provided, then initialize the Mock object with |
| 695 | + the list. Otherwise create one. |
| 696 | +
|
| 697 | + :param List credentials: |
| 698 | + A list of FakeResource objects faking credentials |
| 699 | + :param Integer count: |
| 700 | + The number of credentials to be faked |
| 701 | + :return |
| 702 | + An iterable Mock object with side_effect set to a list of faked |
| 703 | + credentials |
| 704 | + """ |
| 705 | + if credentials is None: |
| 706 | + credentials = FakeCredential.create_credentials(count) |
| 707 | + |
| 708 | + return mock.MagicMock(side_effect=credentials) |
| 709 | + |
| 710 | + |
| 711 | +class FakeUser(object): |
| 712 | + """Fake one or more user.""" |
| 713 | + |
| 714 | + @staticmethod |
| 715 | + def create_one_user(attrs=None): |
| 716 | + """Create a fake user. |
| 717 | +
|
| 718 | + :param Dictionary attrs: |
| 719 | + A dictionary with all attributes |
| 720 | + :return: |
| 721 | + A FakeResource object, with id, name, and so on |
| 722 | + """ |
| 723 | + |
| 724 | + attrs = attrs or {} |
| 725 | + |
| 726 | + # set default attributes. |
| 727 | + user_info = { |
| 728 | + 'id': 'user-id-' + uuid.uuid4().hex, |
| 729 | + 'name': 'user-name-' + uuid.uuid4().hex, |
| 730 | + 'default_project_id': 'project-' + uuid.uuid4().hex, |
| 731 | + 'email': 'user-email-' + uuid.uuid4().hex, |
| 732 | + 'enabled': True, |
| 733 | + 'domain_id': 'domain-id' + uuid.uuid4().hex, |
| 734 | + 'links': 'links-' + uuid.uuid4().hex, |
| 735 | + } |
| 736 | + user_info.update(attrs) |
| 737 | + |
| 738 | + user = fakes.FakeResource(info=copy.deepcopy(user_info), |
| 739 | + loaded=True) |
| 740 | + return user |
0 commit comments