diff options
Diffstat (limited to 'archaeological_operations/tests.py')
| -rw-r--r-- | archaeological_operations/tests.py | 134 | 
1 files changed, 133 insertions, 1 deletions
| diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 42ceea292..8e956c3ab 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -990,9 +990,11 @@ def create_orga(user):      return orga -def create_operation(user, orga=None, values={}): +def create_operation(user, orga=None, values=None):      operation_type = models.OperationType.objects.get(          txt_idx="arch_diagnostic") +    if not values: +        values = {}      dct = {'year': 2010, 'operation_type_id': operation_type.pk,             'history_modifier': user}      dct.update(values) @@ -2992,3 +2994,133 @@ class AutocompleteTest(AutocompleteTestBase, TestCase):              operation_type=models.OperationType.objects.all()[0]          )          return item, None + + +class OperationQATest(OperationInitTest, TestCase): +    fixtures = OPERATION_FIXTURES +    model = models.Operation + +    def setUp(self): +        self.username, self.password, self.user = create_superuser() +        self.orgas = self.create_orgas(self.user) +        self.create_operation(self.user, self.orgas[0]) +        self.create_operation(self.user, self.orgas[0]) +        self.alt_username, self.alt_password, self.alt_user = create_user() +        self.alt_user.user_permissions.add(Permission.objects.get( +            codename='change_operation')) + +    def test_bulk_update(self): +        c = Client() +        pks = u"{}-{}".format(self.operations[0].pk, self.operations[1].pk) +        response = c.get(reverse('operation-qa-bulk-update', args=[pks])) +        self.assertRedirects(response, '/') + +        c = Client() +        c.login(username=self.username, password=self.password) +        response = c.get(reverse('operation-qa-bulk-update', args=[pks])) +        self.assertEqual(response.status_code, 200) + +        c = Client() +        c.login(username=self.alt_username, password=self.alt_password) +        response = c.get(reverse('operation-qa-bulk-update', args=[pks])) +        self.assertEqual(response.status_code, 200) + +        operation_0 = self.operations[0] +        operation_1 = self.operations[1] +        base_desc_0 = u"Base description 1" +        operation_0.description = base_desc_0 +        operation_0.save() +        base_desc_1 = u"Base description 2" +        operation_1.description = base_desc_1 +        operation_1.save() + +        operation_type = models.OperationType.objects.exclude( +            txt_idx="arch_diagnostic").all()[0] + +        self.assertNotEqual( +            models.Operation.objects.get(pk=operation_0.pk).operation_type, +            operation_type +        ) +        self.assertNotEqual( +            models.Operation.objects.get(pk=operation_1.pk).operation_type, +            operation_type +        ) + +        response = c.post( +            reverse('operation-qa-bulk-update-confirm', args=[pks]), +            {'qa_operation_type': operation_type.pk} +        ) +        if response.status_code != 200: +            self.assertRedirects(response, '/success/') +        self.assertEqual( +            models.Operation.objects.get(pk=operation_0.pk).operation_type, +            operation_type +        ) +        self.assertEqual( +            models.Operation.objects.get(pk=operation_1.pk).operation_type, +            operation_type +        ) + + +class DocumentQATest(OperationInitTest, TestCase): +    fixtures = OPERATION_FIXTURES +    model = Document + +    def setUp(self): +        self.username, self.password, self.user = create_superuser() +        self.alt_username, self.alt_password, self.alt_user = create_user() +        self.alt_user.user_permissions.add(Permission.objects.get( +            codename='change_document')) +        self.source_1 = models.Document.objects.create( +            title="Source title", +            source_type=models.SourceType.objects.all()[0] +        ) +        self.source_2 = models.Document.objects.create( +            title="Source title2", +            source_type=models.SourceType.objects.all()[0] +        ) + +    def test_bulk_update(self): +        c = Client() +        pks = u"{}-{}".format(self.source_1.pk, self.source_2.pk) +        response = c.get(reverse('document-qa-bulk-update', args=[pks])) +        self.assertRedirects(response, '/') + +        c = Client() +        c.login(username=self.username, password=self.password) +        response = c.get(reverse('document-qa-bulk-update', args=[pks])) +        self.assertEqual(response.status_code, 200) + +        c = Client() +        c.login(username=self.alt_username, password=self.alt_password) +        response = c.get(reverse('document-qa-bulk-update', args=[pks])) +        self.assertEqual(response.status_code, 200) + +        document_0 = self.source_1 +        document_1 = self.source_2 +        source_type = models.SourceType.objects.exclude( +            txt_idx=self.source_1.source_type.txt_idx).all()[0] + +        self.assertNotEqual( +            models.Document.objects.get(pk=document_0.pk).source_type, +            source_type +        ) +        self.assertNotEqual( +            models.Document.objects.get(pk=document_1.pk).source_type, +            source_type +        ) + +        response = c.post( +            reverse('document-qa-bulk-update-confirm', args=[pks]), +            {'qa_source_type': source_type.pk} +        ) +        if response.status_code != 200: +            self.assertRedirects(response, '/success/') +        self.assertEqual( +            models.Document.objects.get(pk=document_0.pk).source_type, +            source_type +        ) +        self.assertEqual( +            models.Document.objects.get(pk=document_1.pk).source_type, +            source_type +        ) | 
