def handle(self, *args, **options): data = json.loads(open(args[0], 'r').read()) try: with transaction.atomic(): if options["overwrite"]: receivers_back = signals.post_delete.receivers signals.post_delete.receivers = [] try: proj = Project.objects.get(slug=data.get("slug", "not a slug")) proj.tasks.all().delete() proj.user_stories.all().delete() proj.issues.all().delete() proj.memberships.all().delete() proj.roles.all().delete() proj.delete() except Project.DoesNotExist: pass signals.post_delete.receivers = receivers_back user = User.objects.get(email=args[1]) dict_to_project(data, user) except TaigaImportError as e: print("ERROR:", end=" ") print(e.message) print(get_errors())
def test_dict_to_project_with_no_members_public_project_slots_available(client): user = f.UserFactory.create(max_members_public_projects=2) data = { "slug": "valid-project", "name": "Valid project", "description": "Valid project desc", "is_private": False, "roles": [{"name": "Role"}], "memberships": [ { "email": "*****@*****.**", "role": "Role", }, { "email": "*****@*****.**", "role": "Role", }, { "email": "*****@*****.**", "role": "Role", }, { "email": "*****@*****.**", "role": "Role", } ] } with pytest.raises(TaigaImportError) as excinfo: project = dict_to_project(data, owner=user) assert "reached the limit of memberships for public" in str(excinfo.value)
def create(self, request): _response = services.get_resource(request.DATA.get('path')) data = json.loads(_response.text) slug = data.get('slug') if Project.objects.get(slug=slug): del data['slug'] data['owner'] = data.get('owner', request.user.email) project = dict_to_project(data) serializer = serializers.ProjectSerializer(project) return response.Ok(data=serializer.data)
def test_dict_to_project_with_no_projects_slots_available(client): user = f.UserFactory.create(max_private_projects=0) data = { "slug": "valid-project", "name": "Valid project", "description": "Valid project desc", "is_private": True } with pytest.raises(TaigaImportError) as excinfo: project = dict_to_project(data, owner=user) assert "can't have more private projects" in str(excinfo.value)
def handle(self, *args, **options): data = json.loads(open(args[0], 'r').read()) try: with transaction.atomic(): if options["overwrite"]: receivers_back = signals.post_delete.receivers signals.post_delete.receivers = [] try: proj = Project.objects.get( slug=data.get("slug", "not a slug")) proj.tasks.all().delete() proj.user_stories.all().delete() proj.issues.all().delete() proj.memberships.all().delete() proj.roles.all().delete() proj.delete() except Project.DoesNotExist: pass signals.post_delete.receivers = receivers_back dict_to_project(data, args[1]) except TaigaImportError as e: print("ERROR:", end=" ") print(e.message) print(get_errors())