コード例 #1
0
    def test_views__document_delete__post__should_delete_document_when_form_is_valid(self):
        # Arrange
        self.client.login(username=self.username, password=self.password)
        profile: Profile = self.profile
        profile.save()
        document_type = DocumentType(name='TestType', group='other')
        document_type.save()
        image = SimpleUploadedFile("testfile.jpg", b"file_content", content_type="image/jpg")
        document = Document(pk=1,
                            profile=self.profile,
                            document_type=document_type,
                            number='123',
                            issuing_date=date.today(),
                            expiry_date=date.today(),
                            issuing_authority='New York City',
                            issuing_place='New York City',
                            issuing_country='United States of America',
                            file=image)
        document.save()

        # Act
        response = self.client.post(self.url, {}, user=self.user)

        # Assert
        self.assertRedirects(response, reverse('document_list'))
        self.assertEquals(Document.objects.all().count(), 0)
コード例 #2
0
    def test_views__document_update__get__should_render_with_document_html_when_document_exists(self):
        # Arrange
        profile: Profile = self.profile
        profile.save()
        document_type = DocumentType(name='TestType', group='other')
        document_type.save()
        image = SimpleUploadedFile("testfile.jpg", b"file_content", content_type="image/jpg")
        document = Document(pk=1,
                            profile=self.profile,
                            document_type=document_type,
                            number='123',
                            issuing_date=date.today(),
                            expiry_date=date.today(),
                            issuing_authority='New York City',
                            issuing_place='New York City',
                            issuing_country='United States of America',
                            file=image)
        document.save()
        self.client.login(username=self.username, password=self.password)

        # Act
        response = self.client.get(self.url, user=self.user)

        # Assert
        self.assertEquals(response.status_code, 200)
        self.assertTemplateUsed(response, 'confirm-delete.html')
コード例 #3
0
    def test_views__document_update__post__should_get_403_when_user_is_not_owner_of_document(
            self):
        # Arrange
        profile: Profile = self.profile
        profile.save()
        user = User.objects.create_user(username='******',
                                        password='******')
        other_profile = Profile(pk=2,
                                user=user,
                                citizenship='Deutsch',
                                date_of_birth=date.today(),
                                place_of_birth='Hansestadt Hamburg',
                                country_of_birth='DE',
                                gender='m',
                                needs_schengen_visa=False,
                                phone='0987654321')
        other_profile.save()
        document_type = DocumentType(name='TestType', group='other')
        document_type.save()
        image = SimpleUploadedFile("testfile.jpg",
                                   b"file_content",
                                   content_type="image/jpg")
        image2 = SimpleUploadedFile("testfile2.jpg",
                                    b"file_content_number2",
                                    content_type="image/jpg")
        document = Document(pk=1,
                            profile=other_profile,
                            document_type=document_type,
                            number='123',
                            issuing_date=date.today(),
                            expiry_date=date.today(),
                            issuing_authority='New York City',
                            issuing_place='New York City',
                            issuing_country='United States of America',
                            file=image)
        document.save()
        self.client.login(username=self.username, password=self.password)

        # Act
        response = self.client.post(self.url, {
            'document_type': document_type.id,
            'number': '1234',
            'issuing_date': date.today(),
            'expiry_date': date.today(),
            'issuing_authority': 'New Jersey',
            'issuing_place': 'New Jersey',
            'issuing_country': 'United States of America',
            'profile': profile.id,
            'file': image2
        },
                                    user=self.user)

        # Assert
        self.assertEquals(response.status_code, 403)
コード例 #4
0
    def test_views__document_list__get__should_show_table_when_document_is_uploaded(
            self):
        # Arrange
        profile = self.profile
        position = Position.objects.all().first()
        profile.save()
        profile.requested_positions.set((position, ))
        document_type = DocumentType(name='TestType', group='other')
        document_type.save()
        image = SimpleUploadedFile("testfile.jpg",
                                   b"file_content",
                                   content_type="image/jpg")
        document = Document(profile=self.profile,
                            document_type=document_type,
                            number='123',
                            issuing_date=date.today(),
                            expiry_date=date.today(),
                            issuing_authority='New York City',
                            issuing_place='New York City',
                            issuing_country='United States of America',
                            file=image)
        document.save()
        self.client.login(username=self.username, password=self.password)

        # Act
        response = self.client.get(self.url, user=self.user)

        # Assert
        self.assertEquals(response.status_code, 200)
        self.assertTemplateUsed(response,
                                './seawatch_registration/document_list.html')
        self.assertContains(response, self.td(document.pk))
        self.assertContains(response, self.td(document.document_type.name))
        self.assertContains(response, self.td(document.number))
        self.assertContains(
            response, self.td(document.issuing_date.strftime('%b. %-d, %Y')))
        self.assertContains(
            response, self.td(document.expiry_date.strftime('%b. %-d, %Y')))
        self.assertContains(response, self.td(document.issuing_authority))
        self.assertContains(response, self.td(document.issuing_place))
        self.assertContains(response, self.td(document.issuing_country))
        self.assertContains(response, self.td(document.file.name))
        self.assertContains(
            response,
            reverse('document_update', kwargs={'document_id': document.pk}))
        self.assertContains(
            response,
            reverse('document_delete', kwargs={'document_id': document.pk}))
コード例 #5
0
    def test_views__document_create__post__should_redirect_to_position_when_form_is_valid(self):
        # Arrange
        self.client.login(username=self.username, password=self.password)
        profile: Profile = self.profile
        profile.save()
        document_type: DocumentType = DocumentType(name='Passport', group='ident')
        document_type.save()
        image = SimpleUploadedFile("testfile.jpg", b"file_content", content_type="image/jpg")

        # Act
        response = self.client.post(self.url + '?initial_registration=yes',
                                    {'document_type': document_type.id,
                                     'number': '1234',
                                     'issuing_date': date.today(),
                                     'expiry_date': date.today(),
                                     'issuing_authority': 'New York City',
                                     'issuing_city': 'New York City',
                                     'issuing_country': 'United States of America',
                                     'profile': profile.id,
                                     'file': image},
                                    user=self.user)

        # Assert
        self.assertRedirects(response, expected_url='/accounts/positions/edit/?initial_registration=yes')
        self.assertEquals(Document.objects.all().count(), 1)
コード例 #6
0
    def test_views__document_update__post__should_render_when_form_is_invalid(
            self):
        # Arrange
        self.client.login(username=self.username, password=self.password)
        profile: Profile = self.profile
        profile.save()
        document_type = DocumentType(name='TestType', group='other')
        document_type.save()
        image = SimpleUploadedFile("testfile.jpg",
                                   b"file_content",
                                   content_type="image/jpg")
        document = Document(pk=1,
                            profile=self.profile,
                            document_type=document_type,
                            number='123',
                            issuing_date=date.today(),
                            expiry_date=date.today(),
                            issuing_authority='New York City',
                            issuing_place='New York City',
                            issuing_country='United States of America',
                            file=image)
        document.save()

        # Act
        response = self.client.post(self.url, {
            'document_type': document_type.id,
            'issuing_date': 'not a date'
        },
                                    user=self.user)

        # Assert
        self.assertEquals(response.status_code, 200)
        self.assertTemplateUsed(response, 'form.html')
        self.assertNotContains(response, 'alert-success')
        self.assertEquals(Document.objects.all().count(), 1)
        self.assertEquals(Document.objects.all().first(), document)
コード例 #7
0
    def test_views__document_create__post__should_render_when_form_is_invalid(self):
        # Arrange
        self.client.login(username=self.username, password=self.password)
        profile: Profile = self.profile
        profile.save()
        document_type: DocumentType = DocumentType(name='Passport', group='ident')
        document_type.save()

        # Act
        response = self.client.post(self.url,
                                    {'document_type': document_type.id},
                                    user=self.user)

        # Assert
        self.assertEquals(response.status_code, 200)
        self.assertTemplateUsed(response, 'form.html')
        self.assertNotContains(response, 'alert-success')
        self.assertEquals(Document.objects.all().count(), 0)
コード例 #8
0
    def test__views__assessment__get__should_show_data_when_all_data_is_set(
            self):
        # Arrange
        assessment = Assessment(profile=self.profile, status='pending')
        assessment.save()
        question = Question.objects.all().first()
        answer1 = Answer(question=question,
                         profile=self.profile,
                         text='Test Answer 1')
        answer2 = Answer(question=question,
                         profile=self.profile,
                         text='Test Answer 2')
        answer1.save()
        answer2.save()
        skill1 = Skill.objects.all().first()
        skill2 = Skill.objects.all().last()
        self.profile.skills.set((skill1, skill2))
        position1 = Position.objects.all().first()
        position2 = Position.objects.all().last()
        self.profile.requested_positions.set((position1, position2))
        document_type = DocumentType(name='Passport')
        document_type.save()
        document = Document(document_type=document_type,
                            profile=self.profile,
                            number='1234',
                            issuing_date=date.today(),
                            expiry_date=date.today(),
                            issuing_authority='NSA',
                            issuing_place='Crypto City',
                            issuing_country='United States of America',
                            file=SimpleUploadedFile("testfile.jpg",
                                                    b"file_content",
                                                    content_type="image/jpg"))
        document.save()

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

        # Act
        response = self.client.get(reverse('assessment_update',
                                           kwargs={'pk': assessment.pk}),
                                   user=self.user)

        # Assert
        self.assertEquals(response.status_code, 200)
        self.assertTemplateUsed(response, 'assessment-update.html')
        self.assertContains(
            response, '<dd class="col-sm-6 text-danger">Not specified</dd>')
        self.assertContains(response,
                            '<dd class="col-sm-6">German, American</dd>')
        self.assertContains(response, self.li(skill1.name))
        self.assertContains(response, self.li(skill2.name))
        self.assertContains(response, self.li(position1.name))
        self.assertContains(response, self.li(position2.name))
        self.assertContains(response,
                            '<dd class="col-sm-8">Test Answer 1</dd>')
        self.assertContains(response,
                            '<dd class="col-sm-8">Test Answer 2</dd>')
        self.assertContains(response, self.td(document.pk))
        self.assertContains(response, self.td(document.document_type))
        self.assertContains(response, self.td(document.number))
        self.assertContains(
            response, self.td(document.issuing_date.strftime('%b. %-d, %Y')))
        self.assertContains(
            response, self.td(document.expiry_date.strftime('%b. %-d, %Y')))
        self.assertContains(response, self.td(document.issuing_authority))
        self.assertContains(response, self.td(document.issuing_place))
        self.assertContains(response, self.td(document.issuing_country))
        self.assertContains(response, self.td(document.file.name))