def setUp(self):
     try:
         self.user = User.objects.get_by_natural_key(USER_NAME)
     except:
         self.user = User.objects.create_user(USER_NAME, USER_MAIL, USER_PASS)
     self.project = Project.newProject(PROJECT_NAME, self.user, PROJECT_URL, PROJECT_BUGTRACKER)
     self.issue = Issue.newIssue(self.project, ISSUE_KEY, ISSUE_TITLE, ISSUE_DESCRIPTION, self.project.createdByUser, self.project.trackerURL)
Ejemplo n.º 2
0
def _buildIssueFromDictionary(dict, user):
    check_noProject = dict.has_key('noProject')
    issue_trackerURL = dict['trackerURL']
    issue_projectId = dict['project_id']
    issue_projectName = dict.get('project_name', '')
    check_createProject = dict.has_key('createProject')
    newProject_name = dict.get('newProjectName', '')
    newProject_homeURL = dict.get('newProjectHomeURL', '')
    newProject_trackerURL = dict.get('newProjectTrackerURL', '')
    issue_key = dict.get('key', '')
    issue_title = dict.get('title', '')
    issue_description = dict.get('description', '')
    _throwIfIssueExists(issue_trackerURL, user)
    issue = None
    if (check_noProject):
        if (not issue_title or not issue_description):
            raise BaseException('title and description are required')

        issue = Issue.newIssueOrphan(issue_title, issue_description, user)
    else:
        project = None
        if (check_createProject):
            if (not newProject_name or not newProject_homeURL
                    or not newProject_trackerURL):
                raise BaseException(
                    'all parameters for new project are required')

            projectHomeURLValidationError = validateURL(newProject_homeURL)
            if (projectHomeURLValidationError):
                raise BaseException('invalid project URL (' +
                                    newProject_homeURL + ') - ' +
                                    projectHomeURLValidationError)

            projectTrackerURLValidationError = validateURL(
                newProject_trackerURL)
            if (projectTrackerURLValidationError):
                raise BaseException('invalid project tracker URL (' +
                                    newProject_trackerURL + ') - ' +
                                    projectTrackerURLValidationError)

            project = Project.newProject(newProject_name, user,
                                         newProject_homeURL,
                                         newProject_trackerURL)
        else:
            project = Project.objects.get(pk=int(issue_projectId))
            if (newProject_homeURL != project.homeURL):
                project.homeURL = newProject_homeURL

        if (not issue_key or not issue_title):
            raise BaseException('key and title are required')

        issueURLValidationError = validateIssueURL(issue_trackerURL)
        if (issueURLValidationError):
            raise BaseException('invalid issue URL (' + issue_trackerURL +
                                ') - ' + issueURLValidationError)

        issue = Issue.newIssue(project, issue_key, issue_title, user,
                               issue_trackerURL)
    return issue
def _buildOfferFromDictionary(dict, user):
    check_noProject = dict.has_key('noProject')
    issue_trackerURL = dict['trackerURL']
    issue_projectId = dict['project_id']
    issue_projectName = dictOrEmpty(dict, 'project_name')
    check_createProject = dict.has_key('createProject')
    newProject_name = dictOrEmpty(dict, 'newProjectName')
    newProject_homeURL = dictOrEmpty(dict, 'newProjectHomeURL')
    newProject_trackerURL = dictOrEmpty(dict, 'newProjectTrackerURL')
    issue_key = dictOrEmpty(dict, 'key');
    issue_title = dictOrEmpty(dict, 'title');
    issue_description = dictOrEmpty(dict, 'description');

    _throwIfIssueExists(issue_trackerURL, user)

    issue = None
    if(check_noProject):
        if(not issue_title or not issue_description):
            raise BaseException('title and description are required')

        issue = Issue.newIssueOrphan(issue_title, issue_description, user)
    else:
        project = None
        if(check_createProject):
            if(not newProject_name or not newProject_homeURL or not newProject_trackerURL):
                raise BaseException('all parameters for new project are required')

            projectHomeURLValidationError = validateURL(newProject_homeURL)
            if(projectHomeURLValidationError):
                raise BaseException('invalid project URL ('+newProject_homeURL+') - '+projectHomeURLValidationError)

            projectTrackerURLValidationError = validateURL(newProject_trackerURL)
            if(projectTrackerURLValidationError):
                raise BaseException('invalid project tracker URL ('+newProject_trackerURL+') - '+projectTrackerURLValidationError)

            project = Project.newProject(newProject_name, user, newProject_homeURL, newProject_trackerURL)
        else:
            project = Project.objects.get(pk=int(issue_projectId))
            if(newProject_homeURL != project.homeURL):
                project.homeURL = newProject_homeURL

        if(not issue_key or not issue_title):
            raise BaseException('key and title are required')

        issueURLValidationError = validateIssueURL(issue_trackerURL)
        if(issueURLValidationError):
            raise BaseException('invalid issue URL ('+issue_trackerURL+') - '+issueURLValidationError)

        issue = Issue.newIssue(project, issue_key, issue_title, user, issue_trackerURL)

    return _buildOfferFromDictionary_and_issue(dict, user, issue);