Esempio n. 1
0
    def test_mark_done(self):
        """
        Test that a participant can be marked as ready.
        """
        gb = GroupBuildFactory.create(status=GroupbuildStatuses.accepted)

        user = UserFactory.create()
        other_user = UserFactory.create()
        topic = TopicFactory.create(forum__forum_name=gb.theme,
                                    topic_title='Participant 1')
        participant = ParticipantFactory.create(topic_id=topic.topic_id,
                                                user=user)

        endpoint = reverse('api:participant-detail',
                           kwargs={'pk': participant.pk})
        self.client.login(username=user.username, password='******')
        response = self.client.patch(endpoint, {'finished': True},
                                     format='json')
        self.assertEqual(response.status_code, 200)
        participant = Participant.objects.get(pk=participant.pk)
        self.assertTrue(participant.finished)

        self.client.login(username=other_user.username, password='******')
        response = self.client.patch(endpoint, {'finished': False},
                                     format='json')
        self.assertEqual(response.status_code, 403)
Esempio n. 2
0
    def test_user_submit(self):
        """ Test that the user can submit the concept """
        user1 = UserFactory.create()
        user2 = UserFactory.create()

        groupbuild = GroupBuildFactory.create(status=GroupbuildStatuses.concept)
        groupbuild.admins.add(user1, groupbuild.applicant)
        self.assertEqual(groupbuild.admins.count(), 2)

        # test that user2 cannot submit the groupbuilds
        self.client.login(username=user2.username, password='******')
        url = reverse('groupbuilds:submit', kwargs={'slug': groupbuild.slug})
        response = self.client.get(url)
        self.assertEquals(response.status_code, 404)
        self.client.logout

        self.client.login(username=user1, password='******')
        url = reverse('groupbuilds:submit', kwargs={'slug': groupbuild.slug})
        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)

        response = self.client.post(url)
        self.assertEquals(response.status_code, 302)
        groupbuild = GroupBuild.objects.get(slug=groupbuild.slug)
        self.assertEquals(groupbuild.status, GroupbuildStatuses.submitted)
Esempio n. 3
0
    def setUp(self):
        super(SearchTests, self).setUp()
        self.user1 = UserFactory.create(username='******')
        self.user2 = UserFactory.create(username='******')

        self.builds_user1 = [
            BuildFactory.create(title='Sopwith Triplane', user=self.user1),
            BuildFactory.create(title='Honda McJugen', user=self.user1)
        ]
        self.builds_user2 = [
            BuildFactory.create(title='Monogram 4wheel drive', user=self.user2),
        ]
        self.url = reverse('api:builds:search')
Esempio n. 4
0
    def setUp(self):
        # user - forumuser linked by id
        self.user = UserFactory.create()
        self.forum_user = ForumUserFactory.create(username=self.user.username)
        self.user.forumuser_id = self.forum_user.pk
        self.user.save()

        # user -forumuser linked by username
        self.user2 = UserFactory.create()
        self.forum_user2 = ForumUserFactory.create(username=self.user2.username)

        # forum user without user
        self.forum_user3 = ForumUserFactory.create()
Esempio n. 5
0
    def setUp(self):
        # user - forumuser linked by id
        self.user = UserFactory.create()
        self.forum_user = ForumUserFactory.create(username=self.user.username)
        self.user.forumuser_id = self.forum_user.pk
        self.user.save()

        # user -forumuser linked by username
        self.user2 = UserFactory.create()
        self.forum_user2 = ForumUserFactory.create(
            username=self.user2.username)

        # forum user without user
        self.forum_user3 = ForumUserFactory.create()
Esempio n. 6
0
    def setUp(self):
        super(SearchTests, self).setUp()
        self.user1 = UserFactory.create(username='******')
        self.user2 = UserFactory.create(username='******')

        self.builds_user1 = [
            BuildFactory.create(title='Sopwith Triplane', user=self.user1),
            BuildFactory.create(title='Honda McJugen', user=self.user1)
        ]
        self.builds_user2 = [
            BuildFactory.create(title='Monogram 4wheel drive',
                                user=self.user2),
        ]
        self.url = reverse('api:builds:search')
Esempio n. 7
0
 def test_dashboard(self):
     """
     Test that the admin dashboard works as expected.
     """
     superuser = UserFactory.create(is_superuser=True, is_staff=True)
     admin = self.app.get(reverse('admin:index'), user=superuser)
     self.assertEqual(admin.status_code, 200)
    def test_preferences(self):
        """
        Ensure we can retrieve the album preferences.
        """
        url = reverse('api:preferences-list')
        url_detail = reverse('api:preferences-detail', kwargs={'pk': 'self'})

        # anonymous
        response = self.client.get(url)
        self.assertEqual(response.data, [])
        response = self.client.get(url_detail)
        self.assertEqual(response.data, PreferencesSerializer(Preferences()).data)

        # authenticated
        self.client.login(username=self.user.username, password='******')
        response = self.client.get(url_detail)
        self.assertEqual(response.data['id'], self.user.preferences.id)
        self.assertEqual(response.data['user'], self.user.pk)

        user2 = UserFactory.create()
        Preferences.objects.get_for(user2)

        self.assertEqual(Preferences.objects.count(), 2)
        response = self.client.get(url)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['id'], self.user.preferences.id)
Esempio n. 9
0
    def test_restore_photo(self):
        photo = PhotoFactory.create(user=self.user)
        photo.trash = True
        photo.save()

        url_restore = reverse('albums:photo_restore', kwargs={'pk': photo.pk})

        # anonymous user
        self.app.get(photo.get_absolute_url(), status=404)
        # try it anyway
        restore_page = self.app.get(url_restore)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_restore)
        self.assertRedirects(restore_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(photo.user, other_user)
        restore_page = self.app.get(url_restore, user=other_user, status=404)

        # photo owner
        restore_page = self.app.get(url_restore, user=self.user, status=200)
        restore_page.form.submit().follow()

        photo = Photo.objects.get(pk=photo.pk)
        self.assertFalse(photo.trash)
Esempio n. 10
0
    def test_restore_album(self):
        album = AlbumFactory.create(user=self.user, title='Album to restore')
        self.assertEqual(album.clean_title, 'Album to restore')
        album.trash = True
        album.save()

        url_restore = reverse('albums:restore', kwargs={'pk': album.pk})

        # anonymous user
        self.app.get(album.get_absolute_url(), status=404)
        # try it anyway
        restore_page = self.app.get(url_restore)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_restore)
        self.assertRedirects(restore_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(album.user, other_user)
        restore_page = self.app.get(url_restore, user=other_user, status=404)

        # album owner
        restore_page = self.app.get(url_restore, user=self.user, status=200)
        restore_page.form.submit().follow()

        album = Album.objects.get(pk=album.pk)
        self.assertFalse(album.trash)
        self.assertEqual(album.title, 'Album to restore')
Esempio n. 11
0
    def test_preferences(self):
        """
        Ensure we can retrieve the album preferences.
        """
        url = reverse('api:preferences-list')
        url_detail = reverse('api:preferences-detail', kwargs={'pk': 'self'})

        # anonymous
        response = self.client.get(url)
        self.assertEqual(response.data, [])
        response = self.client.get(url_detail)
        self.assertEqual(response.data,
                         PreferencesSerializer(Preferences()).data)

        # authenticated
        self.client.login(username=self.user.username, password='******')
        response = self.client.get(url_detail)
        self.assertEqual(response.data['id'], self.user.preferences.id)
        self.assertEqual(response.data['user'], self.user.pk)

        user2 = UserFactory.create()
        Preferences.objects.get_for(user2)

        self.assertEqual(Preferences.objects.count(), 2)
        response = self.client.get(url)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['id'], self.user.preferences.id)
Esempio n. 12
0
    def test_restore_album(self):
        album = AlbumFactory.create(user=self.user, title='Album to restore')
        self.assertEqual(album.clean_title, 'Album to restore')
        album.trash = True
        album.save()

        url_restore = reverse('albums:restore', kwargs={'pk': album.pk})

        # anonymous user
        self.app.get(album.get_absolute_url(), status=404)
        # try it anyway
        restore_page = self.app.get(url_restore)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_restore)
        self.assertRedirects(restore_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(album.user, other_user)
        restore_page = self.app.get(url_restore, user=other_user, status=404)

        # album owner
        restore_page = self.app.get(url_restore, user=self.user, status=200)
        restore_page.form.submit().follow()

        album = Album.objects.get(pk=album.pk)
        self.assertFalse(album.trash)
        self.assertEqual(album.title, 'Album to restore')
Esempio n. 13
0
    def test_update_photo(self):
        albums = AlbumFactory.create_batch(2, user=self.user)
        photo = PhotoFactory.create(user=self.user,
                                    description='Initial description',
                                    album=albums[0])
        url_update = reverse('albums:photo_update', kwargs={'pk': photo.pk})

        # anonymous user
        album_page = self.app.get(photo.album.get_absolute_url(), status=200)
        self.assertNotContains(album_page, url_update)
        detail_page = self.app.get(photo.get_absolute_url(), status=200)
        self.assertNotContains(detail_page, url_update)
        # try it anyway
        update_page = self.app.get(url_update)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_update)
        self.assertRedirects(update_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(photo.user, other_user)
        update_page = self.app.get(url_update, user=other_user, status=404)

        # photo owner
        update_page = self.app.get(url_update, user=self.user, status=200)
        update_page.form['description'] = 'New description'
        update_page.form['album'] = [str(albums[1].pk)]
        update_page.form.submit().follow()

        photo = Photo.objects.get(pk=photo.pk)
        self.assertEqual(photo.description, 'New description')
        self.assertEqual(photo.album, albums[1])
Esempio n. 14
0
    def test_update_album(self):
        album = AlbumFactory.create(user=self.user, title='Initial title')
        url_update = reverse('albums:update', kwargs={'pk': album.pk})

        # anonymous user
        detail_page = self.app.get(album.get_absolute_url())
        self.assertEqual(detail_page.status_code, 200)
        self.assertNotContains(detail_page, url_update)
        # try it anyway
        update_page = self.app.get(url_update)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_update)
        self.assertRedirects(update_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(album.user, other_user)
        update_page = self.app.get(url_update, user=other_user, status=404)

        # album owner
        update_page = self.app.get(url_update, user=self.user, status=200)
        update_page.form['title'] = 'New title'
        update_page.form.submit().follow()

        album = Album.objects.get(pk=album.pk)
        self.assertEqual(album.title, 'New title')
 def test_dashboard(self):
     """
     Test that the admin dashboard works as expected.
     """
     superuser = UserFactory.create(is_superuser=True, is_staff=True)
     admin = self.app.get(reverse('admin:index'), user=superuser)
     self.assertEqual(admin.status_code, 200)
Esempio n. 16
0
    def test_gb_participant_check(self):
        """
        Test that the check returns the expected data.
        """
        user = UserFactory.create()
        self.client.login(username=user.username, password='******')
        forums = ForumFactory.create_batch(2)
        gb = GroupBuildFactory.create(status=GroupbuildStatuses.accepted,
                                      forum_id=forums[0].pk)

        five_min_ago = int((timezone.now() - timedelta(minutes=5)).strftime("%s"))
        topic1 = TopicFactory.create(forum=forums[0], create_time=five_min_ago)
        topic2 = TopicFactory.create(forum=forums[0])

        ParticipantFactory.create(
            groupbuild=gb, topic_id=topic1.pk, user=user)

        endpoint = reverse('api:groupbuilds:participant-check')

        invalid_data = {'forum_id': 'abcd', 'topic_id': topic1.pk}
        response = self.client.get(endpoint, invalid_data)
        self.assertEqual(response.status_code, 400)
        self.assertDictEqual(response.data, {'error': 'Bad query parameters'})

        # check with existing topic (created > 3 min ago)
        valid_data = {'forum_id': forums[0].pk, 'topic_id': topic1.pk}
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, {'topic_created': False})

        # check with new topic
        valid_data['topic_id'] = topic2.pk
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(response.data['topic_created'])
        self.assertEqual(response.data['groupbuild']['id'], gb.pk)

        # test irrelevant forum
        valid_data['forum_id'] = forums[1].pk
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertFalse(response.data['topic_created'])

        topic3 = TopicFactory.create(
            forum=forums[0], topic_title='my wonderful model')
        participant = ParticipantFactory.create(
            groupbuild=gb, model_name='My model', user=user)
        valid_data['topic_id'] = topic3.pk
        valid_data['forum_id'] = forums[0].pk
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(response.data['topic_created'])
        self.assertEqual(response.data['participant'], {
            'id': participant.id,
            'model_name': 'My model',
            'username': user.username,
            'topic': None,
            'finished': False,
        })
        self.assertEqual(response.data['groupbuild']['id'], gb.pk)
Esempio n. 17
0
    def test_preferences_cache(self):
        user = UserFactory.create()

        # log the user in
        self.client.login(username=user.username, password='******')
        self.assertEqual(Preferences.objects.filter(user=user).count(), 0)

        cache_key = 'album-preferences:%d' % user.id

        # make sure the cache is empty
        prefs = cache.get(cache_key)
        self.assertIsNone(prefs)

        # ok, get the preferences now
        prefs = Preferences.objects.get_for(user)
        self.assertTrue(isinstance(prefs, dict))

        cached_prefs = cache.get(cache_key)
        self.assertEqual(cached_prefs, prefs)

        # change preferences, make sure the cache is updated
        prefs_obj = Preferences.objects.get(user=user)
        prefs_obj.auto_start_uploading = True
        prefs_obj.save()

        cached_prefs = cache.get(cache_key)
        self.assertEqual(cached_prefs['auto_start_uploading'], prefs_obj.auto_start_uploading)
Esempio n. 18
0
    def test_update_album(self):
        album = AlbumFactory.create(user=self.user, title='Initial title')
        url_update = reverse('albums:update', kwargs={'pk': album.pk})

        # anonymous user
        detail_page = self.app.get(album.get_absolute_url())
        self.assertEqual(detail_page.status_code, 200)
        self.assertNotContains(detail_page, url_update)
        # try it anyway
        update_page = self.app.get(url_update)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_update)
        self.assertRedirects(update_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(album.user, other_user)
        update_page = self.app.get(url_update, user=other_user, status=404)

        # album owner
        update_page = self.app.get(url_update, user=self.user, status=200)
        update_page.form['title'] = 'New title'
        update_page.form.submit().follow()

        album = Album.objects.get(pk=album.pk)
        self.assertEqual(album.title, 'New title')
Esempio n. 19
0
    def test_submit_review_with_topic(self):
        """
        Assert that only the relevant topics are listed.
        """
        kit = ModelKitFactory.create()
        user = UserFactory.create()
        forum_user = ForumUserFactory.create(username=user.username)
        user.forumuser_id = forum_user.pk
        user.save()

        topic1 = TopicFactory.create()
        topic2 = TopicFactory.create(author=forum_user)


        url = reverse('kitreviews:review-add', kwargs={'slug': kit.slug})
        add_page = self.app.get(url, user=user)

        # non-authored topics may not be shown
        with self.assertRaisesRegexp(ValueError, r'^Option %s not found \(from' % topic1.pk):
            add_page.form['topic'].select(topic1.pk)
        add_page.form['topic'].select(topic2.pk)
        add_page.form['raw_text'] = 'Dummy review'
        response = add_page.form.submit().follow()

        review = KitReview.objects.get()
        self.assertEqual(review.topic, topic2)
Esempio n. 20
0
    def test_anonymous_add_kit(self):
        """
        When not logged in, you may not get the popup to add a kit, but you must
        be presented with a login button.
        """
        # search by brand
        search_page = self.app.get(self.url)
        search_page.form['kit_name'] = 'gibberish'
        search_results = search_page.form.submit()
        queryset = search_results.context['kits']
        self.assertFalse(queryset.exists())

        search_url = search_results.request.url

        self.assertEqual(len(search_results.forms), 2)
        login_form = search_results.forms[1]
        self.assertEqual(login_form.action, reverse('users:login'))
        login_page = login_form.submit()

        user = UserFactory.create(password='******')
        login_page.form['username'] = user.username
        login_page.form['password'] = '******'
        search_results = login_page.form.submit().follow()
        self.assertEqual(search_results.request.url, search_url)
        self.assertContains(search_results, _('Add kit'))
Esempio n. 21
0
    def test_restore_photo(self):
        photo = PhotoFactory.create(user=self.user)
        photo.trash = True
        photo.save()

        url_restore = reverse('albums:photo_restore', kwargs={'pk': photo.pk})

        # anonymous user
        self.app.get(photo.get_absolute_url(), status=404)
        # try it anyway
        restore_page = self.app.get(url_restore)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_restore)
        self.assertRedirects(restore_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(photo.user, other_user)
        restore_page = self.app.get(url_restore, user=other_user, status=404)

        # photo owner
        restore_page = self.app.get(url_restore, user=self.user, status=200)
        restore_page.form.submit().follow()

        photo = Photo.objects.get(pk=photo.pk)
        self.assertFalse(photo.trash)
Esempio n. 22
0
    def test_update_photo(self):
        albums = AlbumFactory.create_batch(2, user=self.user)
        photo = PhotoFactory.create(
            user=self.user, description='Initial description',
            album=albums[0]
        )
        url_update = reverse('albums:photo_update', kwargs={'pk': photo.pk})

        # anonymous user
        album_page = self.app.get(photo.album.get_absolute_url(), status=200)
        self.assertNotContains(album_page, url_update)
        detail_page = self.app.get(photo.get_absolute_url(), status=200)
        self.assertNotContains(detail_page, url_update)
        # try it anyway
        update_page = self.app.get(url_update)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_update)
        self.assertRedirects(update_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(photo.user, other_user)
        update_page = self.app.get(url_update, user=other_user, status=404)

        # photo owner
        update_page = self.app.get(url_update, user=self.user, status=200)
        update_page.form['description'] = 'New description'
        update_page.form['album'] = [str(albums[1].pk)]
        update_page.form.submit().follow()

        photo = Photo.objects.get(pk=photo.pk)
        self.assertEqual(photo.description, 'New description')
        self.assertEqual(photo.album, albums[1])
Esempio n. 23
0
    def test_update(self):
        """
        Tests that updating builds works as expected.

        It should be possible to add/remove kits of a build
        """
        kits = ModelKitFactory.create_batch(2)
        build = BuildFactory.create(user=self.user, kits=kits)
        build_photo = BuildPhotoFactory.create(
            photo_url='http://i.imgur.com/asdljfo.jpg', build=build)

        url = reverse('builds:update', kwargs={'slug': build.slug})

        # test that non-auth can't update
        response = self.app.get(url)
        self.assertRedirects(response,
                             '{}?next={}'.format(settings.LOGIN_URL, url))

        # test that different user can't update
        other_user = UserFactory.create()
        self.app.get(url, user=other_user, status=404)

        # owner
        page = self.app.get(url, user=self.user, status=200)

        kit_fields = page.form.fields.get('kits')
        self.assertEqual(len(kit_fields), build.kits.count())

        # delete a kit
        pk = int(kit_fields[0].value)
        kit_fields[0].checked = False

        # test add photo
        self.assertEqual(page.form['photos-TOTAL_FORMS'].value, '1')
        self.assertEqual(page.form['photos-INITIAL_FORMS'].value, '1')

        photo = PhotoFactory.create(user=self.user)
        page.form['photos-TOTAL_FORMS'] = 2
        self._add_field(page.form, 'photos-1-id', '')
        self._add_field(page.form, 'photos-1-build', '')
        self._add_field(page.form, 'photos-1-photo', '{}'.format(photo.pk))
        self._add_field(page.form, 'photos-1-photo_url', '')
        self._add_field(page.form, 'photos-1-order', '')

        # test delete photo
        page.form['photos-0-DELETE'].checked = True

        redirect = page.form.submit()
        self.assertRedirects(redirect, build.get_absolute_url())

        build.refresh_from_db()

        kits = build.kits.all()
        self.assertEqual(kits.count(), 1)
        self.assertFalse(kits.filter(pk=pk).exists())

        # check photos
        self.assertEqual(build.photos.count(), 1)
        self.assertNotEqual(build.photos.get(), build_photo)
Esempio n. 24
0
    def test_update(self):
        """
        Tests that updating builds works as expected.

        It should be possible to add/remove kits of a build
        """
        kits = ModelKitFactory.create_batch(2)
        build = BuildFactory.create(user=self.user, kits=kits)
        build_photo = BuildPhotoFactory.create(build=build)

        url = reverse('builds:update', kwargs={'slug': build.slug})

        # test that non-auth can't update
        response = self.app.get(url)
        self.assertRedirects(response, '{}?next={}'.format(settings.LOGIN_URL, url))

        # test that different user can't update
        other_user = UserFactory.create()
        self.app.get(url, user=other_user, status=404)

        # owner
        page = self.app.get(url, user=self.user, status=200)

        kit_fields = page.form.fields.get('kits')
        self.assertEqual(len(kit_fields), build.kits.count())

        # delete a kit
        pk = int(kit_fields[0].value)
        kit_fields[0].checked = False

        # test add photo
        self.assertEqual(page.form['photos-TOTAL_FORMS'].value, '1')
        self.assertEqual(page.form['photos-INITIAL_FORMS'].value, '1')

        photo = PhotoFactory.create(user=self.user)
        page.form['photos-TOTAL_FORMS'] = '2'
        self._add_field(page.form, 'photos-1-id', '')
        self._add_field(page.form, 'photos-1-build', '')
        self._add_field(page.form, 'photos-1-photo', '{}'.format(photo.pk))
        self._add_field(page.form, 'photos-1-photo_url', '')
        self._add_field(page.form, 'photos-1-order', '')

        # test delete photo
        page.form['photos-0-DELETE'].checked = True

        redirect = page.form.submit()
        self.assertRedirects(redirect, build.get_absolute_url())

        build.refresh_from_db()

        kits = build.kits.all()
        self.assertEqual(kits.count(), 1)
        self.assertFalse(kits.filter(pk=pk).exists())

        # check photos
        self.assertEqual(build.photos.count(), 1)
        self.assertNotEqual(build.photos.get(), build_photo)
Esempio n. 25
0
    def test_mark_done(self):
        """
        Test that a participant can be marked as ready.
        """
        gb = GroupBuildFactory.create(status=GroupbuildStatuses.accepted)

        user = UserFactory.create()
        other_user = UserFactory.create()
        topic = TopicFactory.create(forum__forum_name=gb.theme,
                                    topic_title='Participant 1')
        participant = ParticipantFactory.create(topic_id=topic.topic_id, user=user)

        endpoint = reverse('api:participant-detail', kwargs={'pk': participant.pk})
        self.client.login(username=user.username, password='******')
        response = self.client.patch(endpoint, {'finished': True}, format='json')
        self.assertEqual(response.status_code, 200)
        participant = Participant.objects.get(pk=participant.pk)
        self.assertTrue(participant.finished)

        self.client.login(username=other_user.username, password='******')
        response = self.client.patch(endpoint, {'finished': False}, format='json')
        self.assertEqual(response.status_code, 403)
Esempio n. 26
0
    def test_limit_authenticated_user(self):
        """ Test that the limit per user is respected (user authenticated)"""
        user = UserFactory.create()

        # create one model belonging to self.competition
        ShowCasedModelFactory.create(owner=user, competition=self.competition, is_competitor=True)
        self.assertEqual(self.competition.showcasedmodel_set.all().count(), 1)

        # try to add a new one, add the user to the form data
        self.form_data['owner'] = user.pk
        form = ShowCasedModelSignUpForm(competition=self.competition, data=self.form_data)
        self.assertFalse(form.is_valid())
        self.assertIsNotNone(form.errors.get('__all__'))
Esempio n. 27
0
    def test_zip_download(self):
        """ Test that zipfiles are correctly generated and downloaded """
        # create the necessary objects
        user = UserFactory.create()
        album = AlbumFactory.create(user=user)
        PhotoFactory.create_batch(2, album=album, user=user)

        url = reverse('albums:download', kwargs={'pk': album.pk})
        self._test_login_required(url)

        # logged in
        response = self.app.get(url, user=user)
        self.assertEqual(response.status_code, 200)
        self.assertIn('X-Accel-Redirect', response.headers)  # X-SendFile
        self.assertEqual(len(response.content), 0, 'Body is not empty')
Esempio n. 28
0
    def test_submitter_is_admin(self):
        """
        Test that the applicant is an admin of the build.
        """
        user = UserFactory.create()
        gb = GroupBuildFactory.create(applicant=user)
        self.assertQuerysetEqual(gb.admins.all(), [repr(user)], ordered=False)

        gb.save()  # trigger signal
        self.assertEqual(gb.admins.count(), 1)

        # test that existing groupbuilds aren't forced
        gb = gb.__class__.objects.get(pk=gb.pk)
        gb.admins.remove(gb.applicant)
        self.assertQuerysetEqual(gb.admins.all(), [], ordered=False)
Esempio n. 29
0
    def test_zip_download(self):
        """ Test that zipfiles are correctly generated and downloaded """
        # create the necessary objects
        user = UserFactory.create()
        album = AlbumFactory.create(user=user)
        PhotoFactory.create_batch(2, album=album, user=user)

        url = reverse('albums:download', kwargs={'pk': album.pk})
        self._test_login_required(url)

        # logged in
        response = self.app.get(url, user=user)
        self.assertEqual(response.status_code, 200)
        self.assertIn('X-Accel-Redirect', response.headers)  # X-SendFile
        self.assertEqual(len(response.content), 0, 'Body is not empty')
Esempio n. 30
0
    def test_submit_review_for_kit(self):
        kit = ModelKitFactory.create()
        user = UserFactory.create()

        url = reverse('kitreviews:review-add', kwargs={'slug': kit.slug})
        add_page = self.app.get(url, user=user)
        form = add_page.form
        self.assertEqual(form['model_kit'].value, str(kit.pk))

        form['raw_text'] = 'My review with [b]BBCode[/b]\nFoo'
        response = form.submit()
        review = KitReview.objects.get()
        self.assertRedirects(response, review.get_absolute_url())
        self.assertEqual(review.model_kit, kit)
        self.assertEqual(review.raw_text, 'My review with [b]BBCode[/b]\nFoo')
        self.assertHTMLEqual(review.render_raw_text(), 'My review with <strong>BBCode</strong><br>Foo')
        self.assertEqual(review.reviewer, user)
Esempio n. 31
0
    def test_submit_review(self):
        """
        Asserts that submitting a review is only possible as logged in user.
        """
        # test that auth is required
        add_page = self.app.get(self.url)
        self._test_login_required(self.url, response=add_page)

        # add some test data - dummy albums etc.
        user = UserFactory.create()
        invalid_albums = AlbumFactory.create_batch(3)
        AlbumFactory.create_batch(4, user=user)
        kits = ModelKitFactory.create_batch(3)
        KitReviewPropertyFactory.create_batch(3)

        self.assertFalse(KitReview.objects.exists())
        add_page = self.app.get(self.url, user=user)
        form = add_page.form

        # try some invalid input
        self.assertNotIn('model_kit', form.fields)  # no kit submitted - a review must belong to a kit
        with self.assertRaises(ValueError):
            form['album'].select(str(random.choice(invalid_albums).pk))  # an album from a different user
        form['raw_text'] = ''  # empty review

        response = form.submit()
        self.assertFormError(response, 'form', 'raw_text', _('This field is required.'))
        self.assertFormError(response, 'form', 'model_kit', _('This field is required.'))

        # now select a kit
        kit = random.choice(kits)
        self._add_field(form, 'model_kit', str(kit.pk))
        # and enter a review text
        form['raw_text'] = 'My very short review'

        response = form.submit()
        review = KitReview.objects.get()
        self.assertRedirects(response, review.get_absolute_url())
        self.assertEqual(review.ratings.count(), 3)
        self.assertEqual(review.model_kit, kit)
        self.assertEqual(review.raw_text, 'My very short review')
        self.assertEqual(review.reviewer, user)
    def test_upload_endpoint(self):
        user = UserFactory.create()
        self.client.force_login(user, backend='django.contrib.auth.backends.ModelBackend')

        url = reverse('api:boxart-list')

        # create an image
        image = Image.new('RGB', (10, 10), 'green')
        tmp_file = tempfile.NamedTemporaryFile(suffix='.jpg')
        image.save(tmp_file, format='JPEG')

        with open(tmp_file.name, 'rb') as image:
            response = self.client.post(url, {'image': image}, format='multipart')

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        boxart = Boxart.objects.get()
        self.assertEqual(response.data, {
            'uuid': boxart.uuid,
            'image': 'http://testserver{}'.format(boxart.image.url),
            'success': True,
        })
Esempio n. 33
0
    def test_detail_page(self):
        gb = GroupBuildFactory.create()
        gb.admins.add(gb.applicant)
        url = gb.get_absolute_url()

        # anonymous user
        response = self.app.get(url)
        self.assertEquals(response.status_code, 200)
        self.assertIn(gb.theme, response)
        self.assertFalse(response.context['can_edit'])

        # login as owner user
        response = self.app.get(url, user=gb.applicant)
        self.assertEquals(response.status_code, 200)
        self.assertTrue(response.context['can_edit'])

        # and as superuser
        superuser = UserFactory.create(is_staff=True, is_superuser=True)
        response = self.app.get(url, user=superuser)
        self.assertEquals(response.status_code, 200)
        self.assertTrue(response.context['can_edit'])
Esempio n. 34
0
    def test_dashboard(self):
        """ Test that the correct groupbuilds are visible in the dashboard """
        url = reverse('groupbuilds:dashboard')

        user = UserFactory.create()
        gb = GroupBuildFactory.create(
            applicant=user,
            status=GroupbuildStatuses.concept,
            reason_denied='My valid reason',
        )
        gb.admins.add(user)

        participant = ParticipantFactory.create(user=user, groupbuild__status=GroupbuildStatuses.accepted)

        dashboard = self.app.get(url)
        self.assertRedirects(dashboard, settings.LOGIN_URL+u'?next={}'.format(url))

        dashboard = self.app.get(url, user=user)
        self.assertEqual(dashboard.status_code, 200)
        qs = dashboard.context['view'].get_queryset()
        self.assertQuerysetEqual(qs, [repr(gb), repr(participant.groupbuild)], ordered=False)
Esempio n. 35
0
    def test_participant_create(self):
        gb = GroupBuildFactory.create(status=GroupbuildStatuses.accepted)

        user = UserFactory.create()
        topic = TopicFactory.create(forum__forum_name=gb.theme,
                                    topic_title='Participant 1')

        endpoint = reverse('api:groupbuilds:groupbuild-participant',
                           kwargs={'pk': gb.pk})
        data = {
            'groupbuild': gb.pk,
            'model_name': 'Participant 1',
            'topic_id': topic.pk,
        }
        self.client.login(username=user.username, password='******')
        response = self.client.post(endpoint, data, format='json')
        self.assertEqual(response.status_code, 201)  # created

        self.assertEqual(gb.participant_set.count(), 1)
        participant = gb.participant_set.first()
        self.assertEqual(participant.topic_id, topic.topic_id)
        self.assertEqual(participant.model_name, 'Participant 1')
Esempio n. 36
0
    def test_participant_create(self):
        gb = GroupBuildFactory.create(status=GroupbuildStatuses.accepted)

        user = UserFactory.create()
        topic = TopicFactory.create(forum__forum_name=gb.theme,
                                    topic_title='Participant 1')

        endpoint = reverse('api:groupbuilds:groupbuild-participant',
                           kwargs={'pk': gb.pk})
        data = {
            'groupbuild': gb.pk,
            'model_name': 'Participant 1',
            'topic_id': topic.pk,
        }
        self.client.login(username=user.username, password='******')
        response = self.client.post(endpoint, data, format='json')
        self.assertEqual(response.status_code, 201)  # created

        self.assertEqual(gb.participant_set.count(), 1)
        participant = gb.participant_set.first()
        self.assertEqual(participant.topic_id, topic.topic_id)
        self.assertEqual(participant.model_name, 'Participant 1')
Esempio n. 37
0
    def test_delete_album(self):
        album = AlbumFactory.create(user=self.user)
        url_delete = reverse('albums:delete', kwargs={'pk': album.pk})

        # anonymous user
        detail_page = self.app.get(album.get_absolute_url(), status=200)
        self.assertNotContains(detail_page, url_delete)
        # try it anyway
        delete_page = self.app.get(url_delete)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_delete)
        self.assertRedirects(delete_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(album.user, other_user)
        delete_page = self.app.get(url_delete, user=other_user, status=404)

        # album owner
        delete_page = self.app.get(url_delete, user=self.user, status=200)
        delete_page.form.submit().follow()

        album = Album.objects.get(pk=album.pk)
        self.assertTrue(album.trash)
Esempio n. 38
0
    def test_delete_album(self):
        album = AlbumFactory.create(user=self.user)
        url_delete = reverse('albums:delete', kwargs={'pk': album.pk})

        # anonymous user
        detail_page = self.app.get(album.get_absolute_url(), status=200)
        self.assertNotContains(detail_page, url_delete)
        # try it anyway
        delete_page = self.app.get(url_delete)
        expected_redirect = u'%s?next=%s' % (settings.LOGIN_URL, url_delete)
        self.assertRedirects(delete_page, expected_redirect)

        # other user
        other_user = UserFactory.create()
        self.assertNotEqual(album.user, other_user)
        delete_page = self.app.get(url_delete, user=other_user, status=404)

        # album owner
        delete_page = self.app.get(url_delete, user=self.user, status=200)
        delete_page.form.submit().follow()

        album = Album.objects.get(pk=album.pk)
        self.assertTrue(album.trash)
Esempio n. 39
0
 def setUp(self):
     super(PhotoViewsetTests, self).setUp()
     self.user = UserFactory.create()
     self.album = AlbumFactory.create(user=self.user)
     self.list_url = reverse('api:photo-list')
Esempio n. 40
0
 def setUp(self):
     self.user = UserFactory.create()
     self.builds = BuildFactory.create_batch(5)
Esempio n. 41
0
    def test_gb_participant_check(self):
        """
        Test that the check returns the expected data.
        """
        user = UserFactory.create()
        self.client.login(username=user.username, password='******')
        forums = ForumFactory.create_batch(2)
        gb = GroupBuildFactory.create(status=GroupbuildStatuses.accepted,
                                      forum_id=forums[0].pk)

        five_min_ago = int(
            (timezone.now() - timedelta(minutes=5)).strftime("%s"))
        topic1 = TopicFactory.create(forum=forums[0], create_time=five_min_ago)
        topic2 = TopicFactory.create(forum=forums[0])

        ParticipantFactory.create(groupbuild=gb, topic_id=topic1.pk, user=user)

        endpoint = reverse('api:groupbuilds:participant-check')

        invalid_data = {'forum_id': 'abcd', 'topic_id': topic1.pk}
        response = self.client.get(endpoint, invalid_data)
        self.assertEqual(response.status_code, 400)
        self.assertDictEqual(response.data, {'error': 'Bad query parameters'})

        # check with existing topic (created > 3 min ago)
        valid_data = {'forum_id': forums[0].pk, 'topic_id': topic1.pk}
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, {'topic_created': False})

        # check with new topic
        valid_data['topic_id'] = topic2.pk
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(response.data['topic_created'])
        self.assertEqual(response.data['groupbuild']['id'], gb.pk)

        # test irrelevant forum
        valid_data['forum_id'] = forums[1].pk
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertFalse(response.data['topic_created'])

        topic3 = TopicFactory.create(forum=forums[0],
                                     topic_title='my wonderful model')
        participant = ParticipantFactory.create(groupbuild=gb,
                                                model_name='My model',
                                                user=user)
        valid_data['topic_id'] = topic3.pk
        valid_data['forum_id'] = forums[0].pk
        response = self.client.get(endpoint, valid_data)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(response.data['topic_created'])
        self.assertEqual(
            response.data['participant'], {
                'id': participant.id,
                'model_name': 'My model',
                'username': user.username,
                'topic': None,
                'finished': False,
            })
        self.assertEqual(response.data['groupbuild']['id'], gb.pk)
 def setUp(self):
     super(PreferencesTests, self).setUp()
     self.user = UserFactory.create()
     cache.clear()
Esempio n. 43
0
 def setUp(self):
     self.user = UserFactory.create()
     self.builds = BuildFactory.create_batch(5)
Esempio n. 44
0
 def setUp(self):
     super(MyAlbumTests, self).setUp()
     self.user = UserFactory.create()
Esempio n. 45
0
 def setUp(self):
     super(MyAlbumTests, self).setUp()
     self.user = UserFactory.create()
Esempio n. 46
0
 def setUp(self):
     super(PreferencesTests, self).setUp()
     self.user = UserFactory.create()
     cache.clear()
Esempio n. 47
0
 def setUp(self):
     super(PrivateViewTests, self).setUp()
     self.user = UserFactory.create()
Esempio n. 48
0
 def setUp(self):
     super(UploadTests, self).setUp()
     self.user = UserFactory.create()
Esempio n. 49
0
 def setUp(self):
     super(PrivateViewTests, self).setUp()
     self.user = UserFactory.create()
Esempio n. 50
0
 def setUp(self):
     self.superuser = UserFactory.create(is_staff=True, is_superuser=True)