Ejemplo n.º 1
0
    def test_update_issue(self):
        """
        Tests updating an issue

        Requirements:
            * restricted to logged in
            * must contain a field for attachments

        :return:
        """
        c=Category.objects.get(name="LIDAR sensor")
        u=User.objects.get(username="******")
        loc=Location.objects.get(lid="Other")

        login = self.client.login(username='******', password='******')
        data={'short_desc': 'Test1', 'desc': 'Test 1 desc', 'submitted_by': u.id, 'category': c.id,'location':loc.lid}
        form = IssueForm(data)
        self.assertTrue(form.is_valid(),form.errors.as_json())

        response = self.client.post('/issues/new/', data)
        #must be in engineers group or is_staff or is_superuser

        self.assertRegex(response.url,r"^\/issues\/\d*\/")

        issue=Issue.objects.get(short_desc="Test1")

        response=self.client.get(f"/issues/{issue.id}/")
        self.assertContains(response,"id_attachments",msg_prefix="Must contain HTML input type file with id=id_attachments")
Ejemplo n.º 2
0
def new_issue(request, slug):
    project = Project.objects.get(slug=slug)
    if request.POST.get('milestone_date'):
        # call method that modifies post data for our custom milestone handling
        post_data = append_new_milestone(request.POST.copy(), project, None)
        request.POST = post_data

    request.POST = append_new_tags(request.POST.copy(), None)

    form = IssueForm(request.POST)
    if form.is_valid():
        issue = form.save(commit=False)
        issue.priority = 0
        issue.creator = request.user
        issue.project = project

        if (issue.assigned_to):
            issue.status = 'AS'
        else:
            issue.status = 'UA'

        issue.save()
        form.save_m2m()
        return HttpResponse(json.dumps({'status': 'success', 'url': project.get_absolute_url()}), mimetype='application/json')
    else:
        return HttpResponse(json.dumps({'status': 'error', 'errors': form.errors}), mimetype='application/json')
Ejemplo n.º 3
0
    def update(self, request, project_number, issue_id):
        """ Update the issue """

        log.debug("PUT request from user %s for issue id %s" % ( request.user, issue_id))
        proj = Project.objects.get(project_number=project_number)
        issue = Issue.objects.get(id=issue_id)
        log.debug("Fetched object from database %s" % issue)

        if not check_project_write_acl(proj, request.user):
            log.debug("Refusing PUT request for project %s from user %s" % ( project_number, request.user ))
            return rc.FORBIDDEN

        form = IssueForm(request.POST, instance=issue)
        if form.is_valid():
            t = form.save(commit=False)
            if request.POST['update'] != '':                        
                if not request.user.get_full_name():
                    update_name = request.user.username
                else:
                    update_name = request.user.get_full_name()
                    t.history = '''\n\n------Updated by %s on %s------\n\n%s\n\n%s''' % ( update_name, time.strftime("%Y-%m-%d %H:%M"),
                    form.cleaned_data.get('update'), issue.history )
            log.debug('Saving %s back to database' % t)
            t.save()
            return t
        else:
            resp = rc.BAD_REQUEST
            resp.write(form.errors)
            log.debug('Validation errors with %s' % t)
            t.save()
            return resp
Ejemplo n.º 4
0
    def test_operater_new_issue(self):

        c = Category.objects.get(name="general")
        u = User.objects.get(username="******")
        loc=Location.objects.get(lid="Other")

        #login as oscar
        login = self.client.login(username='******', password='******')

        #new issue
        data = {'short_desc': 'Test1', 'desc': 'Test 1 desc', 'submitted_by': u.id, 'category': c.id, 'location':loc.lid}
        form = IssueForm(data)
        self.assertTrue(form.is_valid(),form.errors.as_json())

        response=self.client.post('/issues/new/',data)

        #print(f'TEST_OPERATOR RESPONSE:{response}')
        self.assertRegex(response.url,r"^\/issues\/\d*\/")
        issue=Issue.objects.get(short_desc="Test1")

        #check mail, addressed to oscar (submitted_by) and all in engineer group
        self.assertEqual(len(mail.outbox), 1)
        mc=[]
        for m in mail.outbox:
            mc.append(f'{m.to}, {m.subject}')
        #print(f'TEST_OPERATOR EMAILS: (Issue ID {issue.id}), (Submitted_by {issue.submitted_by}), {mc}')

        #assign to ernie
        issue.assigned_to=User.objects.get(username="******")
        issue.save()
        issue=Issue.objects.get(short_desc="Test1")
Ejemplo n.º 5
0
def new_issue(request, slug):
    project = Project.objects.get(slug=slug)
    if request.POST.get('milestone_date'):
        # call method that modifies post data for our custom milestone handling
        post_data = append_new_milestone(request.POST.copy(), project, None)
        request.POST = post_data

    request.POST = append_new_tags(request.POST.copy(), None)

    form = IssueForm(request.POST)
    if form.is_valid():
        issue = form.save(commit=False)
        issue.priority = 0
        issue.creator = request.user
        issue.project = project

        if (issue.assigned_to):
            issue.status = 'AS'
        else:
            issue.status = 'UA'

        issue.save()
        form.save_m2m()
        return HttpResponse(json.dumps({
            'status': 'success',
            'url': project.get_absolute_url()
        }),
                            mimetype='application/json')
    else:
        return HttpResponse(json.dumps({
            'status': 'error',
            'errors': form.errors
        }),
                            mimetype='application/json')
Ejemplo n.º 6
0
    def test_instance(self):
        """
        Test for data returned by restframework

        :return:
        """
        u = User.objects.get(username="******")
        c = Category.objects.get(name="general")
        loc = Location.objects.get(lid="Other")

        #Create an issue
        data = {
            'short_desc': 'Test1',
            'desc': 'Test 1 desc',
            'submitted_by': u.id,
            'category': c.id,
            'location': loc.lid
        }
        form = IssueForm(data)
        self.assertTrue(form.is_valid(), form.errors.as_json())
        form.save()

        issue = Issue.objects.get(short_desc="Test1")

        self.assertTrue(issue.created_date)
        self.assertTrue(issue.modified_date)

        self.assertEqual(issue.get_absolute_url(), f'/issues/{issue.id}/')
Ejemplo n.º 7
0
    def test_new_issue_lidar(self):
        """
        Tests entering a new issue with a category of LIDAR

        Requirements:
            * restricted to logged in
            * subset of model fields
            * custom email for LIDAR

        :return:
        """
        c=Category.objects.get(name="LIDAR sensor")
        u=User.objects.get(username="******")
        loc=Location.objects.get(lid="Other")

        login = self.client.login(username='******', password='******')
        data={'short_desc': 'Test1', 'desc': 'Test 1 desc', 'submitted_by': u.id, 'category': c.id,'location':loc.lid}
        form = IssueForm(data)
        self.assertTrue(form.is_valid(),form.errors.as_json())

        response = self.client.post('/issues/new/', data)
        #must be in engineers group or is_staff or is_superuser

        self.assertRegex(response.url,r"^\/issues\/\d*\/")

        issue=Issue.objects.get(short_desc="Test1")

        self.assertEqual(len(mail.outbox), 1)
Ejemplo n.º 8
0
    def test_new_issue(self):
        """
        Tests entering a new issue

        Requirements:
            * restricted to logged in
            * subset of model fields

        :return:
        """
        c=Category.objects.get(name="general")
        u=User.objects.get(username="******")
        loc=Location.objects.get(lid="Other")

        login = self.client.login(username='******', password='******')

        response=self.client.get('/issues/new/')
        #Check for HTML inpyt type file tag, id=id_attachments
        self.assertContains(response, 'id_attachments',msg_prefix="Requires input type file with id=id_attachments")

        data={'short_desc': 'Test1', 'desc': 'Test 1 desc', 'submitted_by': u.id, 'category': c.id, 'location':loc.lid}
        form = IssueForm(data)
        self.assertTrue(form.is_valid(),form.errors.as_json())

        response = self.client.post('/issues/new/', data)
        #must be in engineers group or is_staff or is_superuser

        self.assertRegex(response.url,r"^\/issues\/\d*\/")

        issue=Issue.objects.get(short_desc="Test1")

        self.assertEqual(len(mail.outbox), 1)

        #add a response
        data={'author':u.id,'issue':issue.id,'text':'Test1.1'}
        form=ResponseForm(data)
        self.assertTrue(form.is_valid(),form.errors.as_json())
        response = self.client.post(f'/issues/{issue.id}/', data)
        #print(f'RESPONSE:(IssueID {issue.id}, {response}')
        self.assertEqual(issue.response_set.all().count(),1)
        #print(f'ISSUE RESPONSE: {issue.response_set.all()}')

        self.assertEqual(len(mail.outbox),2)

        mc=[]
        for m in mail.outbox:
            mc.append(f'{m.to}, {m.subject}')
Ejemplo n.º 9
0
def store(request):
	if request.method == "POST":
		form = IssueForm(request.POST)
		if form.is_valid():
			try:
				form.save()
			except Exception as e:
				pass
	return redirect('/issues')
Ejemplo n.º 10
0
def issue_edit(request, pk):
    issue = issue_by_number(pk)
    form = IssueForm(request.POST or None, instance=issue)
    if form.is_valid():
        obj = form.save(commit=False)
        obj.save()
        return HttpResponseRedirect(reverse("issues-view", args=[pk,]))
    return direct_to_template(request, "issue_edit.html", extra_context={
        "form": form,
        "issue": issue,
        "nav": {"selected": "issues",},
    })
Ejemplo n.º 11
0
def create_issue(request, template='issues/create_issue.html'):
    if request.method == 'POST' and request.POST:
        form = IssueForm(request.POST)
        if form.is_valid():
            issue = form.save(commit=False)
            issue.submitter = request.user
            issue.save()
            messages.success(request, u"Issue created, pending approval.")
            return HttpResponseRedirect(reverse('issue-detail', args=[issue.id] ))           
    else:
        form = IssueForm()
    return render_to_response(template, {
        'form': form,
    }, context_instance=RequestContext(request)) 
Ejemplo n.º 12
0
def item(request, issue_id):
	issue = get_object_or_404( Issue, id = issue_id )
	if request.method == 'GET':
		form = IssueForm( instance = issue )
	elif request.method == 'POST':
		form = IssueForm( data = request.POST, instance = issue )
		if form.is_valid():
			form.save()
			return redirect('issue_index')
	
	return render( request, 'issues/item.html', {
		'form': form,
		'issue': issue
	})
Ejemplo n.º 13
0
def item(request, issue_id):
    issue = get_object_or_404(Issue, id = issue_id)
    form = IssueForm(instance = issue)

    if request.method == 'POST':
        form = IssueForm(data = request.POST, instance = issue)
        if form.is_valid():
            form.save()
            return redirect('issues:index')

    return render(request, 'issues/item.html', {
        'form': form,
        'issue': issue
    })
Ejemplo n.º 14
0
    def test_valid_issue_form(self):
        submitter = User.objects.get(username='******')
        assignee = User.objects.get(username='******')
        valid_form = IssueForm(user=submitter,
                               data={
                                   'title': 'New Test Issue',
                                   'description': 'A test issue.',
                                   'assignee': assignee.id,
                                   'project': self.test_project.id,
                                   'priority': 3,
                                   'status': 'open',
                                   'issue_type': 'bug',
                                   'tag': 'test',
                                   'attachment': ''
                               })

        self.assertTrue(valid_form.is_valid())
Ejemplo n.º 15
0
    def test_invalid_form(self):
        milestone1 = Milestone.objects.get(id=self.MILE1_ID)
        user1 = User.objects.get(id=self.USER1_ID)

        form_data = {
            # title is required
            'description': 'My first issue description',
            'time_spent': '0.0',
            'progress': '0%',
            'milestone': str(milestone1.id),
            'type': 'Feature',
            'priority': 'Normal',
            'assignees': str(user1.id),
            'status': 'Open',
        }

        form = IssueForm(data=form_data)
        self.assertFalse(form.is_valid())
Ejemplo n.º 16
0
def issue_edit(request, pk):
    issue = issue_by_number(pk)
    form = IssueForm(request.POST or None, instance=issue)
    if form.is_valid():
        obj = form.save(commit=False)
        obj.save()
        return HttpResponseRedirect(reverse("issues-view", args=[
            pk,
        ]))
    return direct_to_template(request,
                              "issue_edit.html",
                              extra_context={
                                  "form": form,
                                  "issue": issue,
                                  "nav": {
                                      "selected": "issues",
                                  },
                              })
Ejemplo n.º 17
0
def issue_add(request):
    issue_form = IssueForm(request.POST or request.GET or None)
    group_form = GroupForm(request.POST or request.GET or None)
    if issue_form.is_valid() and group_form.is_valid():
        obj = issue_form.save(commit=False)
        obj.creator = request.user
        obj.save()

        if group_form.cleaned_data.get("group"):
            group = Group.get(group_form.cleaned_data["group"])
            IssueGroup(group=group, issue=obj).save()

        return HttpResponseRedirect(reverse("issues-list"))
    return direct_to_template(request, "issue_add.html", extra_context={
        "issue_form": issue_form,
        "group_form": group_form,
        "nav": {"selected": "issues", "subnav": "add"},
    })
Ejemplo n.º 18
0
def issue_add(request):
    issue_form = IssueForm(request.POST or request.GET or None)
    group_form = GroupForm(request.POST or request.GET or None)
    if issue_form.is_valid() and group_form.is_valid():
        obj = issue_form.save(commit=False)
        obj.creator = request.user
        obj.save()

        if group_form.cleaned_data.get("group"):
            group = Group.get(group_form.cleaned_data["group"])
            IssueGroup(group=group, issue=obj).save()

        return HttpResponseRedirect(reverse("issues-list"))
    return direct_to_template(request,
                              "issue_add.html",
                              extra_context={
                                  "issue_form": issue_form,
                                  "group_form": group_form,
                                  "nav": {
                                      "selected": "issues",
                                      "subnav": "add"
                                  },
                              })
Ejemplo n.º 19
0
def index(request):
    if request.method == 'GET':
        if request.GET.get('fixed',False):
            issues = Issue.objects.filter(status__in = [2,4]).order_by('-date_closed','-date_created')
        else:
            issues = Issue.objects.exclude(status__in = [2,4])

        return render(request, 'issues/index.html', {
            'issues': issues,
            'show_fixed': 'fixed' in request.GET.keys()
        })

    elif request.method == 'POST':
        form = IssueForm(data = request.POST)
        if form.is_valid():
            issue = form.save()
            issue.username = request.user.username
            issue.save()
            return redirect('issues:index')
        else:
            return render(request, 'issues/new.html', {
                'form': form
            })
Ejemplo n.º 20
0
def index(request):
	if request.method == 'GET':
		if request.GET.get('fixed',False):
			issues = Issue.objects.filter( status__in = [2,4] ).order_by('-date_closed','-date_created')
		else:
			issues = Issue.objects.exclude( status__in = [2,4] )
		
		return render( request, 'issues/index.html', {
			'issues': issues,
			'show_fixed': 'fixed' in request.GET.keys()
		})
	
	elif request.method == 'POST':
		form = IssueForm( data = request.POST )
		if form.is_valid():
			issue = form.save()
			issue.username = request.user.username
			issue.save()
			return redirect('issue_index')
		else:
			return render( request, 'issues/new.html', {
				'form': form
			})
Ejemplo n.º 21
0
    def test_update_issue_completed(self):
        """
        Tests entering a new issue

        Requirements:
            * restricted to logged in
            * subset of model fields

        :return:
        """
        c=Category.objects.get(name="general")
        u=User.objects.get(username="******")
        loc=Location.objects.get(lid="Other")

        login = self.client.login(username='******', password='******')
        data={'short_desc': 'Test1', 'desc': 'Test 1 desc', 'submitted_by': u.id, 'category': c.id, 'location':loc.lid}
        form = IssueForm(data)
        self.assertTrue(form.is_valid(),form.errors.as_json())

        response = self.client.post('/issues/new/', data)
        #must be in engineers group or is_staff or is_superuser

        self.assertRegex(response.url,r"^\/issues\/\d*\/")

        issue=Issue.objects.get(short_desc="Test1")

        self.assertEqual(len(mail.outbox), 1)

        #mark record completed
        data = {'short_desc': 'Test1', 'desc': 'Test 1 desc', 'submitted_by': u.id, 'category': c.id,'location': loc.lid,'completed':True}
        response = self.client.post(f'/issues/{issue.id}/edit/', data)

        self.assertEqual(len(mail.outbox),2)

        mc=[]
        for m in mail.outbox:
            mc.append(f'{m.to}, {m.subject}')