Exemplo n.º 1
0
def project_detail(request, project_key):
    try:
        project = git_repo().get_project(project_key)
    except LookupError:
        raise Http404('Project does not exist')
    context = {'project': project, 'tickets': project.tickets_as_list()}
    return render(request, 'urid/project_detail.html', context)
Exemplo n.º 2
0
def api_follow_ticket(request, ticket_id):
    try:
        ticket = git_repo().get_ticket(ticket_id)
    except LookupError:
        return HttpResponse('{ "ticket_id": %s }' % (ticket_id,),
                            status=404, content_type='application/json')

    response = HttpResponse(ticket.as_json(), status=303, content_type='application/json')
    response['Location'] = ticket.url
    return response
Exemplo n.º 3
0
    def test_get_projects_prefix_project(self):
        os.mkdir(os.path.join(self._repo_path, 'DIR'))
        open(os.path.join(self._repo_path, 'FILE'), 'w').close()

        self._create_base_file()

        expected_project = PrefixProject('WELC', self._project_file_path())
        expected_project.url_prefix = 'https://github.com/welc/welc-201507'
        expected_project.tickets[1] = self._ticket1
        expected_project.tickets[2] = self._ticket2

        self.assertListEqual(git_repo().get_projects(), [expected_project])
Exemplo n.º 4
0
    def test_create_ticket_prefix_project(self):
        self._create_base_file()

        expected_ticket = Ticket(
            'WELC-3', 'https://github.com/welc/welc-201507/blob/master/items/chapter03_sensing-and-separation.md')

        actual_ticket = git_repo().create_ticket(expected_ticket.url)
        self.assertEqual(expected_ticket, actual_ticket)

        f = open(self._project_file_path())
        lines = f.readlines()
        f.close()

        self.assertEqual(
            lines[-1],
            '* [WELC-3](https://github.com/welc/welc-201507/blob/master/items/chapter03_sensing-and-separation.md)\r\n')
Exemplo n.º 5
0
def api_create_ticket(request):
    if request.method == 'POST':
        request_data = json.loads(request.body.strip())
        url = str(request_data['url'])

        try:
            ticket = git_repo().create_ticket(url)
            response = HttpResponse('{ "ticket": %s }' % (ticket.as_json(),),
                                    status=201, content_type='application/json')
            response['Location'] = reverse('urid:api_follow_ticket', args=(ticket.ticket_id,))
            return response
        except DuplicatedTicketException as ex:
            return HttpResponse('{ "message": "existing ticket", "ticket": %s }' % (ex.ticket.as_json(),),
                                status=409, content_type='application/json')
        except NoProjectException as ex:
            return HttpResponse('{ "message": "no corresponding project", "url": "%s" }' % (ex.url,),
                                status=409, content_type='application/json')
    else:
        return HttpResponseRedirect(reverse('urid:project_list'))
Exemplo n.º 6
0
    def test_get_ticket(self):
        self._create_base_file()

        self.assertEqual(git_repo().get_ticket(self._ticket2.ticket_id), self._ticket2)
        self.assertRaises(LookupError, git_repo().get_ticket, 'WELC-3')
Exemplo n.º 7
0
    def test_create_ticket_duplicated(self):
        self._create_base_file()

        self.assertRaises(DuplicatedTicketException,
                          git_repo().create_ticket,
                          'https://github.com/welc/welc-201507/blob/master/items/chapter01_changing-software.md')
Exemplo n.º 8
0
 def test_create_ticket_no_project(self):
     self.assertRaises(NoProjectException, git_repo().create_ticket, "https://github.com/anvatar/URID/abc")
Exemplo n.º 9
0
 def test_get_projects_no_project(self):
     self.assertListEqual(git_repo().get_projects(), [])
Exemplo n.º 10
0
def project_list(request):
    context = {'projects': git_repo().get_projects()}
    return render(request, 'urid/project_list.html', context)