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)
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)
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)
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)
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))
def test_my_profile_form_valid(self): user = fixtures.create_user( username='******', email="*****@*****.**", password='******', first_name='Test', last_name='User' ) user_profile = fixtures.create_user_profile( user_id=user.id, twitter='', bio='', photo=None ) self.client.login(username=user.username, password='******') s = self.client.session s['user_id'] = user.id s.save() upload_file = open('user_profile/tests/resources/test_user.jpg', 'rb') post_dict = {'bio': 'Test Bio', 'twitter': 'test_handle'} file_dict = {'photo': SimpleUploadedFile(upload_file.name, upload_file.read())} form = MyProfileForm(post_dict, file_dict) profile = Profile.objects.get(id=user_profile.id) self.assertTrue(form.is_valid())