コード例 #1
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_empty_cart(self):
        """
            test empty =cart successfully
        """

        user = fixtures.create_user(
            username='******', email="*****@*****.**", password='******', first_name='Test', last_name='User'
        )

        artist_user = fixtures.create_user(
            username='******', email="*****@*****.**", password='******', first_name='Test', last_name='User'
        )
        self.client.login(username=user.username, password='******')

        s = self.client.session
        s['user_id'] = user.id
        s.save()

        cart = fixtures.create_cart(session_key=s._session_key, user_id=user.id)

        art = fixtures.create_art(user_id=artist_user.id, category='test', photo='/whatever/', title='test art', description='test art')

        cli = fixtures.create_cart_line_item(cart_id=cart.id, art_id=art.id)

        url = reverse('cart.views.empty_cart')
        resp = self.client.post(url)

        self.assertEqual(resp.status_code, 200)
コード例 #2
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_my_art_admin_non_artist_authenticated(self):
        """
            test a get request to the my artist admin view as an authenticated non artist
        """
        art_user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='art', last_name='user'
        )

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user', is_artist=False
        )
        category = fixtures.create_category(name='Test Category')
        art = fixtures.create_art(
            user_id=user.id, category=category.id, photo=('test_photos/art/%s/test_photo.jpg' % art_user.id), title='Test Art', description='Some art'
        )
        like = fixtures.create_art_like(user_id=user.id, art_id=art.id)

        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()

        url = reverse("art.views.my_art_admin")
        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 302)
コード例 #3
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_add_to_cart_authenticated_existing_cart(self):
        """
            test an item being added to the cart via post request existing cart
        """
        user = fixtures.create_user(
            username='******', email="*****@*****.**", password='******', first_name='Test', last_name='User'
        )

        artist_user = fixtures.create_user(
            username='******', email="*****@*****.**", password='******', first_name='Test', last_name='User'
        )
        self.client.login(username=user.username, password='******')

        s = self.client.session
        s['user_id'] = user.id
        s.save()

        cart = fixtures.create_cart(session_key=s._session_key, user_id=user.id)

        art = fixtures.create_art(user_id=artist_user.id, category='test', photo='/whatever/', title='test art', description='test art')

        url = reverse('cart.views.add_to_cart', args=(art.id, ))
        resp = self.client.post(url)

        self.assertEqual(resp.status_code, 200)
コード例 #4
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_save_profile_get(self):
        """
            test the save profile view with a post
            returns 405 for get not allowed
        """
        user = fixtures.create_user(
            username='******', email="*****@*****.**", password='******', first_name='Test', last_name='User'
        )
        #HACK: create the art directory for the user that matches what we insert into the db
        os.system('mkdir test_photos/user/%s' % user.id)
        os.system('cp user_profile/tests/resources/test_user.jpg test_photos/user/%s/' % user.id)
        os.system('mkdir test_photos/art/%s' % user.id)
        os.system('cp art/tests/resources/test_photo.jpg test_photos/art/%s/' % user.id)

        user_profile = fixtures.create_user_profile(
            user_id=user.id, twitter='test_handle', bio='test_bio', photo=('test_photos/user/%s/test_user.jpg' % user.id)
        )
        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()

        url = reverse("user_profile.views.save_profile")

        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 405)
コード例 #5
0
ファイル: test_lib.py プロジェクト: kcshafer/liwi-site
    def test_retrieve_featured_artists(self):

        date_format = '%m/%d/%Y'

        start = datetime.today()
        str_start = start.strftime(date_format)
        #TODO: this would fail in december
        end = datetime(start.year, start.month + 1, 1)
        str_end = end.strftime(date_format)

        for i in range(1, 10):
            user = fixtures.create_user(
                username='******' + str(i), password='******', email='user' + str(i) + '@test.com', first_name='test', last_name='user'
            )

            fa = fixtures.create_featured_artist(
                user_id=user.id, start_date=start, end_date=end, photo='\whatever'
            )

        featured_artists = retrieve_featured_artists(5)
        first_fa_ids = []
        for fa in featured_artists:
            first_fa_ids.append(fa.id)

        self.assertEqual(len(featured_artists), 5)
        self.assertEqual(featured_artists[0].total_imprints, 1)

        next_featured_artists = retrieve_featured_artists(5)
        next_fa_ids = []

        for fa in next_featured_artists:
            next_fa_ids.append(fa.id)

        self.assertNotEqual(first_fa_ids, next_fa_ids)
コード例 #6
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_reset_password_post_success(self):
        """
            test a post request to the reset password view successfully
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        secret_question = fixtures.create_security_question(question='Test')

        fixtures.create_secret_answer(
            user_id=user.id, question_id=secret_question.id, answer='Test Answer'
        )

        cache.set('user_id', user.id, 30)
        post_dict = {'password': '******', 're_password': '******'}

        url = reverse('authentication.views.reset_password')
        resp = self.client.post(url, post_dict, follow=True)
        resp_url = (resp.__dict__.get('redirect_chain')[0])[0]
        parsed_url = urlparse(resp_url)

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(parsed_url.path, '/login/')
コード例 #7
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_unlike_art_get(self):
        """
            test a get request to the unlike view authenticated
        """
        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )
        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()
        category = fixtures.create_category(name='Test Category')

        #HACK: create the art directory for the user that matches what we insert into the db
        os.system('mkdir test_photos/art/%s' % user.id)
        os.system('cp art/tests/resources/test_photo.jpg test_photos/art/%s/' % user.id)

        art = fixtures.create_art(
            user_id=user.id, category=category.id, photo=('test_photos/art/%s/test_photo.jpg' % user.id), title='Test Art', description='Some art'
        )

        like = fixtures.create_art_like(user_id=user.id, art_id=art.id)

        url = reverse("art.views.unlike_art", args=(art.id, ))
        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 405)
コード例 #8
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_view_profile(self):
        user = fixtures.create_user(
            username='******', email="*****@*****.**", password='******', first_name='Test', last_name='User'
        )
        #HACK: create the art directory for the user that matches what we insert into the db
        os.system('mkdir test_photos/user/%s' % user.id)
        os.system('cp user_profile/tests/resources/test_user.jpg test_photos/user/%s/' % user.id)
        os.system('mkdir test_photos/art/%s' % user.id)
        os.system('cp art/tests/resources/test_photo.jpg test_photos/art/%s/' % user.id)

        user_profile = fixtures.create_user_profile(
            user_id=user.id, twitter='test_handle', bio='test_bio', photo=('test_photos/user/%s/test_user.jpg' % user.id)
        )

        category = fixtures.create_category(name='Test Category')

        art = fixtures.create_art(
            user_id=user.id, category=category.id, photo=('test_photos/art/%s/test_photo.jpg' % user.id), title='Test Art', description='Some art'
        )

        url = reverse("user_profile.views.view_profile", args=(user.id, ))

        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 200)
コード例 #9
0
ファイル: test_forms.py プロジェクト: kcshafer/liwi-site
    def test_featured_artist_form_invalid_date_greater(self):
        """
            test the featured artist form fails with a greater start date than end date
        """

        user = fixtures.create_user(
            username='******', email="*****@*****.**", password='******', first_name='Test', last_name='User'
        )

        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()

        date_format = '%m/%d/%Y'

        start = datetime.today()
        str_start = start.strftime(date_format)
        #TODO: this would fail in december
        end = datetime(start.year, start.month + 1, 1)
        str_end = end.strftime(date_format)

        post_dict = {'start_date': str_end, 'end_date': str_start}

        form = FeaturedArtistForm(post_dict)

        self.assertFalse(form.is_valid())
コード例 #10
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_post_get_featured_register_no_start_date(self):
        """
            test a post request to the get_featured_register view failing because of no start date
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()

        date_format = '%m/%d/%Y'

        start = datetime.today()
        str_start = start.strftime(date_format)
        #TODO: this would fail in december
        end = datetime(start.year, start.month + 1, 1)
        str_end = end.strftime(date_format)

        post_dict = {'start_date': '', 'end_date': str_end}
        url = reverse("artists.views.get_featured_register")
        resp = self.client.post(url, post_dict)

        self.assertEqual(resp.status_code, 200)
コード例 #11
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_post_get_featured_register_successful(self):
        """
            test a post request to the get_featured_register view successully
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        user_profile = fixtures.create_user_profile(
            user_id=user.id, twitter='test_handle', bio='test_bio', photo=('test_photos/user/%s/test_user.jpg' % user.id)
        )

        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()

        date_format = '%m/%d/%Y'

        start = datetime.today()
        str_start = start.strftime(date_format)
        #TODO: this would fail in december
        end = datetime(start.year, start.month + 1, 1)
        str_end = end.strftime(date_format)

        post_dict = {'start_date': str_start, 'end_date': str_end}
        url = reverse("artists.views.get_featured_register")
        resp = self.client.post(url, post_dict)

        self.assertEqual(resp.status_code, 302)
コード例 #12
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_validate_answer_post_timeout(self):
        """
            test a post request to the validate answer view where the cached user id times out
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        secret_question = fixtures.create_security_question(question='Test')

        fixtures.create_secret_answer(
            user_id=user.id, question_id=secret_question.id, answer='Test Answer'
        )

        cache.set('user_id', user.id, 0.0000001)
        post_dict = {'secret_answer': 'Test Answer'}

        url = reverse('authentication.views.validate_answer')
        resp = self.client.post(url, post_dict, follow=True)
        resp_url = (resp.__dict__.get('redirect_chain')[0])[0]
        parsed_url = urlparse(resp_url)

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(parsed_url.path, '/resetpassword/forgotpassword/')
コード例 #13
0
ファイル: test_models.py プロジェクト: kcshafer/liwi-site
    def test_create_user(self):
        """
            Test creation of a user record
        """
        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        self.assertTrue(isinstance(user, User))
コード例 #14
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_artist_index(self):
        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )
        fixtures.create_user_profile(
            user_id=user.id, bio='Test bio', twitter='test_handle', photo=None
        )
        url = reverse("artists.views.index")
        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 200)
コード例 #15
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_create_art_form_non_artist(self):
        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user', is_artist=False
        )
        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()
        url = reverse("art.views.create_art_form")
        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 200)
コード例 #16
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_upload_get(self):
        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )
        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()
        url = reverse("art.views.upload")
        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 405)
コード例 #17
0
ファイル: test_models.py プロジェクト: kcshafer/liwi-site
    def test_profile_creation(self):
        """
            Test creation of a profile record
        """
        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )
        user_photo = File('art/tests/resources/test_photo.jpg')
        profile = fixtures.create_user_profile(
            user_id=user.id, twitter='test_handle', bio='Test bio', photo=user_photo
        )

        self.assertTrue(isinstance(profile, Profile))
コード例 #18
0
ファイル: test_models.py プロジェクト: kcshafer/liwi-site
    def test_cart_creation_with_user(self):
        """
            test creation of a cart model with a user
        """

        user = fixtures.create_user(
                username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        cart = fixtures.create_cart(user_id=user.id, session_key='1234abc')


        self.assertTrue(isinstance(cart, Cart))
コード例 #19
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_view_art_unauthenticated(self):
        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )
        category = fixtures.create_category(name='Test Category')
        os.system('mkdir test_photos/art/%s' % user.id)
        os.system('cp art/tests/resources/test_photo.jpg test_photos/art/%s/' % user.id)
        art = fixtures.create_art(
            user_id=user.id, category=category.id, photo=('test_photos/art/%s/test_photo.jpg' % user.id), title='Test Art', description='Some art'
        )
        url = reverse("art.views.view_art_single", args=(art.id, ))

        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 200)
コード例 #20
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_login_post_successful(self):
        """
            test a post login request from a existing user to the login view
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        post_dict = {'username': '******', 'password': '******'}

        url = reverse('authentication.views.login')
        resp = self.client.post(url, post_dict, follow=True)

        self.assertEqual(resp.status_code, 200)
コード例 #21
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_handle_art_activation_unauthenticated_post_(self):
        """
            test a post request to the handle_art_activation unauthenticated
        """
        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )
        category = fixtures.create_category(name='Test Category')
        art = fixtures.create_art(
            user_id=user.id, category=category.id, photo=('test_photos/art/%s/test_photo.jpg' % user.id), title='Test Art', description='Some art'
        )
        like = fixtures.create_art_like(user_id=user.id, art_id=art.id)

        url = reverse("art.views.handle_art_activation", args=(art.id, ))
        resp = self.client.post(url)
        self.assertEqual(resp.status_code, 302)
コード例 #22
0
ファイル: test_models.py プロジェクト: kcshafer/liwi-site
    def test_art_creation(self):
        """
            Test creation of an art record
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        category = fixtures.create_category(name='Test Category')
        art_photo = File('art/tests/resources/test_photo.jpg')
        art = fixtures.create_art(
            user_id=user.id, category=category.id, photo=art_photo, title='Test Art', description='Some art'
        )

        self.assertTrue(isinstance(art, Art))
コード例 #23
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_login_post_no_user(self):
        """
            test a post login request with a username that does not exist
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        post_dict = {'username': '******', 'password': '******'}

        url = reverse('authentication.views.login')
        resp = self.client.post(url, post_dict)

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp.__dict__.get('_container')[0], 'User not found or password incorrect')
コード例 #24
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_get_get_featured_register(self):
        """
            test that get request to the get featured register is blocked
        """
        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()

        url = reverse("artists.views.get_featured_register")
        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 405)
コード例 #25
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_art_index_authenticated(self):
        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )
        category = fixtures.create_category(name='Test Category')
        art = fixtures.create_art(
            user_id=user.id, category=category.id, photo=('test_photos/art/%s/test_photo.jpg' % user.id), title='Test Art', description='Some art'
        )
        like = fixtures.create_art_like(user_id=user.id, art_id=art.id)
        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()
        url = reverse("art.views.index")
        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 200)
コード例 #26
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_activate_user_success(self):
        """
            test a post request to the user activate view, with a user id that has not been activated
        """

        user = fixtures.create_user(
            username='******', password='******',
            email='*****@*****.**', first_name='test',
            last_name='user', is_active=False
        )

        url = reverse('registration.views.activate_user', args=[user.id])
        resp = self.client.post(url, follow=True)
        messages = list(resp.context['messages'])

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(len(messages), 0)
コード例 #27
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_contact_form_authenticated_successful(self):
        """
            test a get request to the contact view by an authenticated user
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )
        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()

        url = reverse('home.views.contact')
        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 200)
コード例 #28
0
ファイル: test_models.py プロジェクト: kcshafer/liwi-site
    def test_create_security_answer(self):
        """
            Test creation of a security answer record

        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        security_question = fixtures.create_security_question(question='Test question?')

        security_answer = fixtures.create_secret_answer(
            user_id=user.id, question_id=security_question.id, answer='Test Answer'
        )

        self.assertTrue(isinstance(security_answer, SecurityAnswer))
コード例 #29
0
ファイル: test_views.py プロジェクト: kcshafer/liwi-site
    def test_get_featured_authenticated_non_artist(self):
        """
            test a get request as an authenticated non artist to the get_featured view
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user', is_artist=False
        )

        self.client.login(username=user.username, password='******')
        s = self.client.session
        s['user_id'] = user.id
        s.save()

        url = reverse("artists.views.get_featured")
        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 302)
コード例 #30
0
ファイル: test_models.py プロジェクト: kcshafer/liwi-site
    def test_like_creation(self):
        """
            test creation of an art like record
        """

        user = fixtures.create_user(
            username='******', password='******', email='*****@*****.**', first_name='test', last_name='user'
        )

        category = fixtures.create_category(name='Test Category')

        art = fixtures.create_art(
            user_id=user.id, category=category.id, photo='test/photo', title='Test Art', description='Some art'
        )

        art_like = fixtures.create_art_like(user_id=user.id, art_id=art.id)

        self.assertTrue(isinstance(art_like, Like))