This function will create mock data for a project and all the necessary context for any unit testing to be performed. context_data will be a dictionary with all the context for creating the project. The idea is that you'll be able to specify users, labels, tasks, etc... and the func
(context_data, session)
| 794 | |
| 795 | |
| 796 | def create_project_with_context(context_data, session): |
| 797 | """ |
| 798 | This function will create mock data for a project and all the necessary context for any unit testing |
| 799 | to be performed. |
| 800 | context_data will be a dictionary with all the context for creating the project. |
| 801 | The idea is that you'll be able to specify users, labels, tasks, etc... and the function will make sure all the |
| 802 | data is mocked properly. |
| 803 | |
| 804 | Example: For my test I need a project with 2 users, 1 admin and another with view permissions. I also need 3 labels. |
| 805 | The context_data should look something like this: |
| 806 | { |
| 807 | 'project_name': 'My test project', |
| 808 | 'users': [ |
| 809 | {'name': 'john', permissions: 'admin'} |
| 810 | {'name': 'maria', permissions: 'view'} |
| 811 | }, |
| 812 | 'labels': [ |
| 813 | {'name': 'catlabel', 'type': 'box'} |
| 814 | {'name': 'dogabel2', 'type': 'box'} |
| 815 | ] |
| 816 | |
| 817 | The function will return a similar data structure with the ID's on the test database for further querying |
| 818 | inside the test cases. |
| 819 | |
| 820 | :param context_data: |
| 821 | :return: |
| 822 | """ |
| 823 | |
| 824 | random_name = get_random_string(8) |
| 825 | project_string_id = context_data.get('project_string_id', random_name) |
| 826 | project_name = context_data.get('project_name', random_name) |
| 827 | |
| 828 | default_project_limit = 10 |
| 829 | user = register_user( |
| 830 | {'username': f"project_owner_{project_string_id}", |
| 831 | 'email': f"test{project_string_id}@test.com", |
| 832 | 'project_roles': ['admin'], |
| 833 | 'password': 'diffgram123'}, |
| 834 | session |
| 835 | ) |
| 836 | member = Member(kind = 'human') |
| 837 | session.add(member) |
| 838 | session.flush() |
| 839 | user.member = member |
| 840 | |
| 841 | project = Project.new( |
| 842 | session = session, |
| 843 | name = project_name, |
| 844 | project_string_id = project_string_id, |
| 845 | goal = 'Test stuff', |
| 846 | member_created = member, |
| 847 | user = user |
| 848 | ) |
| 849 | user_list = [] |
| 850 | for user in context_data['users']: |
| 851 | if user.get('project_string_id') is None: |
| 852 | user['project_string_id'] = random_name |
| 853 | new_user = register_user(user, session) |
no test coverage detected