def test_generate_slug(self): """ Original test was to create all possible 1-character slugs except for one ('A') but after trying that out, found out that it can take so much time to be able to generate that remaining useable slug (but it's definitely possible!). Therefore, as a remedy, instead of leaving a single useable slug, 10 useable slugs were left, which are the ten digits (0-9). """ #Create all possible slugs with only 1 ascii character for char in string.ascii_uppercase: Video.objects.create(slug=char, uploader=self.user1) #Now, test the generate_slug function for length 1 slug = generate_slug(SLUG_LENGTH) self.assertTrue(slug in string.digits) logger.info('Videos generate_slug() test successful.')
def test_generate_slug(self): """ Original test was to create all possible 1-character slugs except for one ('A') but after trying that out, found out that it can take so much time to be able to generate that remaining useable slug (but it's definitely possible!). Therefore, as a remedy, instead of leaving a single useable slug, 10 useable slugs were left, which are the ten digits (0-9). """ # Create all possible slugs with only 1 ascii character for char in string.ascii_uppercase: Video.objects.create(slug=char, uploader=self.user1) # Now, test the generate_slug function for length 1 slug = generate_slug(SLUG_LENGTH) self.assertTrue(slug in string.digits) logger.info("Videos generate_slug() test successful.")
def handle(self, *args, **options): if len(args) > 2: raise CommandError('Too many arguments given. Provide either one or two usernames.') elif len(args) == 2: try: free_user = User(username=args[0], first_name=args[0] + '_free', last_name='User', email='*****@*****.**') paid_user = User(username=args[1], first_name=args[1] + '_paid', last_name='User', email='*****@*****.**') free_user.save() paid_user.save() self.stdout.write('Successfully created fake users using supplied usernames.\n') except: raise CommandError("Could not create users with supplied usernames. Try different usernames.") elif len(args) == 1: try: free_user = User(username=args[0] + '_free', first_name=args[0] + '_free', last_name='User', email='*****@*****.**') paid_user = User(username=args[0] + '_paid', first_name=args[0] + '_paid', last_name='User', email='*****@*****.**') free_user.save() paid_user.save() self.stdout.write('Successfully created fake users using the supplied username + suffixes "_free" and "_paid".\n') except: raise CommandError("Could not create users with supplied username. Try a different username.") elif len(args) == 0: try: free_user = User(username='******', first_name='fakeuser_free', last_name='User', email='*****@*****.**') paid_user = User(username='******', first_name='fakeuser_paid', last_name='User', email='*****@*****.**') free_user.save() paid_user.save() self.stdout.write('Successfully created fake users using default usernames.\n') except: raise CommandError("Fake users already exist. Create differently named users using 'manage.py create_test_accounts <username>'") free_user.set_password('password') paid_user.set_password('password') free_user.save() paid_user.save() # Set paid_user account paid_level = AccountLevel.objects.get(level='Paid') paid_user.userprofile.account_level = paid_level paid_user.userprofile.save() # Create videos for free users for u in (free_user, paid_user): created_videos = () for i in range(10): temp_slug = generate_slug(5) temp_vid = Video(uploader=u, title="Test Fake Uploads Video " + str(i), slug=temp_slug) temp_vid.save() created_videos = created_videos + (temp_vid,) #### Videos #Normal temp_vid = created_videos[0] temp_vid.title = "Normal private video" temp_vid.description = "Normal private video." temp_vid.save() upload_to_s3(temp_vid.slug) ### Expired videos, for free user temp_vid = created_videos[1] if not u == free_user: upload_to_s3(temp_vid.slug) temp_vid = created_videos[2] upload_to_s3(temp_vid.slug) temp_vid = created_videos[3] upload_to_s3(temp_vid.slug) #Expired Yesterday, created 2 days ago temp_vid = created_videos[1] temp_vid.title = "Expired the day previous to creation" temp_vid.description = "Expired the day previous to creation." temp_vid.created = datetime.datetime.now() - datetime.timedelta(days=2) temp_vid.save() if u == free_user: temp_vid.expired = True temp_vid.expiry_date = datetime.datetime.now() - datetime.timedelta(days=1) temp_vid.save() temp_vid.delete() #Expires Today in 4 hours temp_vid = created_videos[2] temp_vid.title = "Expires 4 hours from creation" temp_vid.description = "Expires 4 hours from creation." if u == free_user: temp_vid.expiry_date = datetime.datetime.now() + datetime.timedelta(hours=4) temp_vid.save() #Expires in 3 days temp_vid = created_videos[3] temp_vid.title = "Expires 3 days from creation" temp_vid.description = "Expires 3 days from creation." if u == free_user: temp_vid.expiry_date = datetime.datetime.now() + datetime.timedelta(days=3) temp_vid.save() #Created Yesterday temp_vid = created_videos[4] upload_to_s3(temp_vid.slug) temp_vid.created = datetime.datetime.now() - datetime.timedelta(days=1) temp_vid.title = "Time-stamped as created the day previous to actual creation" temp_vid.description = "Time-stamped as created the day previous to actual creation." temp_vid.save() #Created A Week Previous temp_vid = created_videos[5] upload_to_s3(temp_vid.slug) temp_vid.created = datetime.datetime.now() - datetime.timedelta(days=7) temp_vid.title = "Time-stamped as created a week previous to actual creation" temp_vid.description = "Time-stamped as created a week previous to actual creation." temp_vid.save() #Public temp_vid = created_videos[6] upload_to_s3(temp_vid.slug) temp_vid.is_public = True temp_vid.title = "Public." temp_vid.description = "Public." temp_vid.save() #Public. Expired Yesterday, created 2 days ago temp_vid = created_videos[7] upload_to_s3(temp_vid.slug) temp_vid.title = "Public. Expired the day previous to creation" temp_vid.description = "Public. Expired the day previous to creation." temp_vid.is_public = True temp_vid.created = datetime.datetime.now() - datetime.timedelta(days=2) if u == free_user: temp_vid.expired = True temp_vid.expiry_date = datetime.datetime.now() - datetime.timedelta(days=1) temp_vid.save() #Outlined temp_vid = created_videos[8] upload_to_s3(temp_vid.slug) temp_vid.title = "Outlined" temp_vid.description = "Outlined." temp_vid.save() outline = VideoOutline(video=temp_vid) outline.save() outline_pin = VideoOutlinePin(video_outline=outline, text="Start") outline_pin.save() #Transferred to Youtube, created 2 days ago, deleted from server yesterday temp_vid = created_videos[9] upload_to_s3(temp_vid.slug) temp_vid.youtube_embed_url= "http://www.youtube.com/embed/yc5W-AClSlI" temp_vid.created = datetime.datetime.now() - datetime.timedelta(days=2) temp_vid.youtube_video_expiry_date = datetime.datetime.now() - datetime.timedelta(days=1) temp_vid.title = "YouTube video" temp_vid.description = "YouTube video." temp_vid.save() self.stdout.write('Successfully created videos!\n')