示例#1
0
    def test_correct_choices(self):
        grant = Grant.objects.create(full_name='g', short_name='g', slug='g')
        t_closed = Topic(name='t1', open_for_tickets=False, grant=grant)
        t_closed.save()
        t_open = Topic(name='t2', open_for_tickets=True, grant=grant)
        t_open.save()
        t_assigned = Topic(name='t3', open_for_tickets=False, grant=grant)
        t_assigned.save()
        ticket = Ticket(name='ticket', topic=t_assigned)
        ticket.save()

        from tracker.views import get_edit_ticket_form_class
        EditForm = get_edit_ticket_form_class(ticket)
        choices = {t.id for t in EditForm().fields['topic'].queryset.all()}
        wanted_choices = {t_open.id, t_assigned.id}
        self.assertEqual(wanted_choices, choices)
示例#2
0
    def setUp(self):
        self.open_topic = Topic(name='test_topic', open_for_tickets=True, ticket_media=True, grant=Grant.objects.create(full_name='g', short_name='g', slug='g'))
        self.open_topic.save()

        self.statutory_declaration_topic = Topic(name='statutory_topic', open_for_tickets=True, ticket_media=True, ticket_statutory_declaration=True, grant=Grant.objects.get(short_name='g'))
        self.statutory_declaration_topic.save()

        self.subtopic = Subtopic(name='Test', topic=self.open_topic)
        self.subtopic2 = Subtopic(name='Test2', topic=self.statutory_declaration_topic)
        self.subtopic.save()
        self.subtopic2.save()

        self.password = '******'
        self.user = User(username='******')
        self.user.set_password(self.password)
        self.user.save()
示例#3
0
    def setUp(self):
        self.topic = Topic(name='test_topic', open_for_tickets=True, ticket_media=True, grant=Grant.objects.create(full_name='g', short_name='g', slug='g'))
        self.topic.save()

        self.user = User(username='******')
        self.user.save()

        self.ticket = Ticket(name='foo', requested_user=self.user, topic=self.topic, description='foo foo')
        self.ticket.save()
示例#4
0
    def setUp(self):
        self.topic = Topic(name='topic1', grant=Grant.objects.create(full_name='g', short_name='g', slug='g'))
        self.topic.save()

        self.ticket1 = Ticket(name='foo', requested_text='req1', topic=self.topic, description='foo foo')
        self.ticket1.save()

        self.ticket2 = Ticket(name='bar', requested_text='req2', topic=self.topic, description='bar bar')
        self.ticket2.save()
示例#5
0
    def setUp(self):
        self.topic = Topic(name='topic', grant=Grant.objects.create(full_name='g', short_name='g', slug='g'))
        self.topic.save()

        self.password = '******'
        self.user = User(username='******')
        self.user.set_password(self.password)
        self.user.save()

        self.ticket = Ticket(name='ticket', topic=self.topic, requested_user=None, requested_text='foo')
        self.ticket.save()
示例#6
0
    def test_closed_topic(self):
        closed_topic = Topic(name='closed topic', open_for_tickets=False, grant=Grant.objects.create(full_name='g', short_name='g', slug='g'))
        closed_topic.save()

        c = self.get_client()
        response = c.post(reverse('create_ticket'), {
            'name': 'ticket',
            'topic': closed_topic.id,
            'description': 'some desc',
            'deposit': '0',
            'expediture-INITIAL_FORMS': '0',
            'expediture-TOTAL_FORMS': '0',
            'preexpediture-INITIAL_FORMS': '0',
            'preexpediture-TOTAL_FORMS': '0',
        })
        self.assertEqual(200, response.status_code)
        self.assertFormError(response, 'ticketform', 'topic', 'Select a valid choice. That choice is not one of the available choices.')
示例#7
0
    def generate_and_add_topics(self, amount=12):
        name_prefix = "Topic number "
        try:
            last_example_topic = Topic.objects.filter(name__startswith=name_prefix).order_by('pk').reverse()[0]
        except IndexError:
            start_num = 1
        else:
            start_num = int(search(r'(\d+)$', last_example_topic.name).group(0)) + 1

        grant_objects = Grant.objects.all()
        topic_query_list = []
        admins = User.objects.filter(username__startswith=ADMINNAME_PREFIX)
        for n in range(start_num, start_num + amount):
            topic = Topic(
                name="{}{}".format(name_prefix, n),
                # This should be fine for selecting grants,
                # since the DB is small if/when you run this command
                grant=choice(grant_objects),
                description=("Detailed topic description. "
                             "Allows for HTML. "
                             "Line breaks are auto parsed."),
                form_description=("This description is"
                                  "shown to users who enter"
                                  "tickets for this topic."),
                open_for_tickets=True,
                ticket_media=True,
                ticket_expenses=True,
                ticket_preexpenses=True,
            )
            if admins.exists():
                topic.save()
                topic.admin.add(choice(admins))
            else:
                topic_query_list.append(topic)

        Topic.objects.bulk_create(topic_query_list)
示例#8
0
    def setUp(self):
        self.user = User(username='******')
        self.user.save()

        self.topic = Topic(name='test_topic', ticket_expenses=True, grant=Grant.objects.create(full_name='g', short_name='g', slug='g'))
        self.topic.save()

        self.ticket = Ticket(name='foo', requested_user=self.user, topic=self.topic, rating_percentage=50)
        self.ticket.save()
        self.ticket.add_acks('content', 'docs', 'archive')
        self.ticket.expediture_set.create(description='foo', amount=200)
        self.ticket.expediture_set.create(description='foo', amount=100)
        self.ticket.mediainfoold_set.create(description='foo', count=5)
        self.ticket.mediainfo_set.create(name='test.jpg')
        self.ticket.mediainfo_set.create(name='test2.jpg')

        self.ticket2 = Ticket(name='foo', requested_user=self.user, topic=self.topic, rating_percentage=100)
        self.ticket2.save()
        self.ticket2.add_acks('content', 'docs', 'archive')
        self.ticket2.expediture_set.create(description='foo', amount=600)
        self.ticket2.expediture_set.create(description='foo', amount=10)
        self.ticket2.mediainfoold_set.create(description='foo', count=5)
        self.ticket2.mediainfoold_set.create(description='foo', count=3)
        self.ticket2.mediainfo_set.create(name='test.jpg')
示例#9
0
    def test_ticket_edit(self):
        topic = Topic(name='topic', grant=Grant.objects.create(full_name='g', short_name='g', slug='g'))
        topic.save()

        statutory_topic = Topic(name='statutory_topic', ticket_statutory_declaration=True, grant=Grant.objects.get(short_name='g'))
        statutory_topic.save()

        subtopic = Subtopic(name='subtopic', topic=topic)
        subtopic2 = Subtopic(name='subtopic2', topic=statutory_topic)
        subtopic.save()
        subtopic2.save()

        password = '******'
        user = User(username='******')
        user.set_password(password)
        user.save()

        ticket = Ticket(name='ticket', topic=topic, requested_user=None, requested_text='foo')
        ticket.save()
        ticket.add_acks('close')

        c = Client()
        response = c.get(reverse('edit_ticket', kwargs={'pk': ticket.id}))
        self.assertEqual(302, response.status_code)  # should be redirect to login page

        c.login(username=user.username, password=password)
        response = c.get(reverse('edit_ticket', kwargs={'pk': ticket.id}))
        self.assertEqual(403, response.status_code)  # denies edit of non-own ticket

        ticket.requested_user = user
        ticket.requested_text = ''
        ticket.save()
        response = c.get(reverse('edit_ticket', kwargs={'pk': ticket.id}))
        self.assertEqual(403, response.status_code)  # still deny edit, ticket locked

        ticket.ticketack_set.filter(ack_type='close').delete()
        response = c.get(reverse('edit_ticket', kwargs={'pk': ticket.id}))
        self.assertEqual(200, response.status_code)  # now it should pass

        # try to submit the form
        response = c.post(reverse('edit_ticket', kwargs={'pk': ticket.id}), {
            'name': 'new name',
            'topic': ticket.topic.id,
            'description': 'new desc',
            'deposit': '0',
            'expediture-INITIAL_FORMS': '0',
            'expediture-TOTAL_FORMS': '0',
            'preexpediture-INITIAL_FORMS': '0',
            'preexpediture-TOTAL_FORMS': '0',
        })
        self.assertRedirects(response, reverse('ticket_detail', kwargs={'pk': ticket.id}))

        # check changed ticket data
        ticket = Ticket.objects.get(id=ticket.id)
        self.assertEqual(user, ticket.requested_user)
        self.assertEqual('new name', ticket.name)
        self.assertEqual('new desc', ticket.description)

        # b0rked expediture items aborts the submit
        response = c.post(reverse('edit_ticket', kwargs={'pk': ticket.id}), {
            'name': 'ticket',
            'topic': ticket.topic.id,
            'description': 'some desc',
            'deposit': '0',
            'expediture-INITIAL_FORMS': '0',
            'expediture-TOTAL_FORMS': '1',
            'expediture-0-description': 'foo',
            'expediture-0-amount': '',
            'preexpediture-INITIAL_FORMS': '0',
            'preexpediture-TOTAL_FORMS': '0',
        })
        self.assertEqual(200, response.status_code)
        self.assertEqual('This field is required.', response.context['expeditures'].forms[0].errors['amount'][0])

        # add some inline items
        response = c.post(reverse('edit_ticket', kwargs={'pk': ticket.id}), {
            'name': 'new name',
            'topic': ticket.topic.id,
            'description': 'new desc',
            'deposit': '0',
            'expediture-INITIAL_FORMS': '0',
            'expediture-TOTAL_FORMS': '2',
            'expediture-0-description': 'ten fifty',
            'expediture-0-amount': '10.50',
            'expediture-1-description': 'hundred',
            'expediture-1-amount': '100',
            'preexpediture-INITIAL_FORMS': '0',
            'preexpediture-TOTAL_FORMS': '0',
        })
        self.assertRedirects(response, reverse('ticket_detail', kwargs={'pk': ticket.id}))
        expeditures = ticket.expediture_set.order_by('amount')
        self.assertEqual(2, len(expeditures))
        self.assertEqual('ten fifty', expeditures[0].description)
        self.assertEqual(10.5, expeditures[0].amount)
        self.assertEqual('hundred', expeditures[1].description)
        self.assertEqual(100, expeditures[1].amount)

        # edit inline items
        response = c.post(reverse('edit_ticket', kwargs={'pk': ticket.id}), {
            'name': 'new name',
            'topic': ticket.topic.id,
            'description': 'new desc',
            'deposit': '0',
            'expediture-INITIAL_FORMS': '2',
            'expediture-TOTAL_FORMS': '3',
            'expediture-0-id': expeditures[0].id,
            'expediture-0-description': 'ten fifty',
            'expediture-0-amount': '10.50',
            'expediture-0-DELETE': 'on',
            'expediture-1-id': expeditures[1].id,
            'expediture-1-description': 'hundred+1',
            'expediture-1-amount': '101',
            'expediture-2-description': '',
            'expediture-2-amount': '',
            'preexpediture-INITIAL_FORMS': '0',
            'preexpediture-TOTAL_FORMS': '0',
        })
        self.assertRedirects(response, reverse('ticket_detail', kwargs={'pk': ticket.id}))
        expeditures = ticket.expediture_set.order_by('amount')
        self.assertEqual(1, len(expeditures))
        self.assertEqual('hundred+1', expeditures[0].description)
        self.assertEqual(101, expeditures[0].amount)

        # add preexpeditures, and amount flag preack
        deposit_amount = Decimal('12324.37')
        ticket = Ticket.objects.get(id=ticket.id)
        ticket.deposit = deposit_amount
        ticket.preexpediture_set.create(description='some preexp', amount=15)
        ticket.save()
        ticket.add_acks('precontent')

        # edit should work and ignore new data
        response = c.post(reverse('edit_ticket', kwargs={'pk': ticket.id}), {
            'name': 'new name',
            'topic': ticket.topic.id,
            'description': 'new desc',
            'deposit': '333',
            'expediture-INITIAL_FORMS': '0',
            'expediture-TOTAL_FORMS': '0',
            'preexpediture-INITIAL_FORMS': '0',
            'preexpediture-TOTAL_FORMS': '0',
        })
        self.assertRedirects(response, reverse('ticket_detail', kwargs={'pk': ticket.id}))
        ticket = Ticket.objects.get(id=ticket.id)
        self.assertEqual(deposit_amount, ticket.deposit)
        self.assertEqual(1, ticket.preexpediture_set.count())

        # also, edit should work and not fail on missing preack-ignored fields
        response = c.post(reverse('edit_ticket', kwargs={'pk': ticket.id}), {
            'name': 'new name',
            'topic': ticket.topic.id,
            'description': 'new desc',
            'expediture-INITIAL_FORMS': '0',
            'expediture-TOTAL_FORMS': '0',
        })
        self.assertRedirects(response, reverse('ticket_detail', kwargs={'pk': ticket.id}))
        ticket = Ticket.objects.get(id=ticket.id)
        self.assertEqual(deposit_amount, ticket.deposit)
        self.assertEqual(1, ticket.preexpediture_set.count())
示例#10
0
 def setUp(self):
     self.topic = Topic(name='topic', grant=Grant.objects.create(full_name='g', short_name='g', slug='g'))
     self.topic.save()