def test_delete_user(self): user_to_del = User(name='user_delete', email='*****@*****.**', email_confirmed=1, is_paid=1) user_to_del.set_password('asdfasdf') user_to_del.save() sourcefile = Sourcefile(width=20, height=20, file_key="asdf", thumb_key="asdf_t") sourcefile.save() sharedfile = Sharedfile(source_id=sourcefile.id, name="my shared file", user_id=user_to_del.id, content_type="image/png", share_key="ok") sharedfile.save() user_shake = user_to_del.shake() sharedfile.add_to_shake(user_shake) self.post_url('/admin/delete-user', arguments={ 'user_id': user_to_del.id, 'user_name': user_to_del.name }) deleted_user = User.get('id = %s and name = %s', user_to_del.id, user_to_del.name) self.assertEqual(deleted_user.deleted, 1) sf = Sharedfile.get('id=%s', sharedfile.id) self.assertEqual(sf.deleted, 1)
def test_oembed_response_json_for_link(self): url = 'https://vimeo.com/20379529' sourcefile = Sourcefile(width=100, height=100, data="{'junk':'here'}", type='link', file_key="asdfasdfasdfasdfasdf") sourcefile.save() sharedfile = Sharedfile(source_id=sourcefile.id, user_id=self.user.id, name=url, title="Some Title", source_url=url, content_type='text/html') sharedfile.save() sharedfile.share_key = base36encode(sharedfile.id) sharedfile.save() sharedfile = Sharedfile.get('id = %s', 1) file_time_stamp = int(time.mktime(sharedfile.created_at.timetuple())) self.http_client.fetch( self.get_url("/services/oembed?url=http%3A//mltshp.com/p/1"), self.stop) response = self.wait() j_response = json_decode(response.body) self.assertEqual(j_response['type'], "link") self.assertEqual(j_response['url'], url)
def setUp(self): super(ConversationTests, self).setUp() self.admin = User(name='admin', email='*****@*****.**', email_confirmed=1, is_paid=1) self.admin.set_password('asdfasdf') self.admin.save() self.user2 = User(name='user2', email='*****@*****.**', email_confirmed=1, is_paid=1) self.user2.set_password('asdfasdf') self.user2.save() self.sid = self.sign_in('user2', 'asdfasdf') self.xsrf = self.get_xsrf() self.src = Sourcefile(width=1, height=1, file_key='asdf', thumb_key='qwer') self.src.save() self.shf = Sharedfile(source_id=self.src.id, user_id=self.admin.id, name='shared.jpg', title='shared', share_key='1', content_type='image/jpg') self.shf.save()
def setUp(self): super(FileViewTests, self).setUp() self.user = User(name='admin', email='*****@*****.**', email_confirmed=1, is_paid=1) self.user.set_password('asdfasdf') self.user.save() self.user2 = User(name='user', email='*****@*****.**', email_confirmed=1, is_paid=1) self.user2.set_password('asdfasdf') self.user2.save() self.sid2 = self.sign_in('user', 'asdfasdf') self.sid = self.sign_in('admin', 'asdfasdf') self.xsrf = self.get_xsrf() self.test_file1_path = os.path.abspath("test/files/1.png") self.test_file1_sha1 = Sourcefile.get_sha1_file_key( self.test_file1_path) self.test_file1_content_type = "image/png" self.test_file2_path = os.path.abspath("test/files/love.gif") self.test_file2_sha1 = Sourcefile.get_sha1_file_key( self.test_file2_path) self.test_file2_content_type = "image/gif"
def setUp(self): """ Create a user, source and shared file. """ super(NotificationModelTests, self).setUp() self.user = User(name='example', email='*****@*****.**', verify_email_token='created', password='******', email_confirmed=1, is_paid=1) self.user.save() self.user2 = User(name='example2', email='*****@*****.**', verify_email_token='created', password='******', email_confirmed=1, is_paid=1) self.user2.save() self.sourcefile = Sourcefile(width=20,height=20,file_key="asdf", \ thumb_key="asdf_t") self.sourcefile.save() self.sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file", \ user_id=self.user.id, content_type="image/png", share_key="ok") self.sharedfile.save()
def test_pagination_returns_correct_counts(self): """ This tests creating 111 shared files for a user and then tests that pagination on their user page returns the correct pages """ user = User.get('name="admin"') user_shake = user.shake() source_file = Sourcefile(width=10, height=10, file_key='mumbles', thumb_key='bumbles') source_file.save() missing_ids = [] for i in range(111): sf = Sharedfile(source_id=source_file.id, user_id=user.id, name="shgaredfile.png", title='shared file', share_key='asdf', content_type='image/png', deleted=0) sf.save() sf.add_to_shake(user_shake) for i in range(12): response = self.fetch('/user/admin/%s' % (i + 1)) self.assertEqual(response.code, 200)
def setUp(self): super(CeleryTaskTests, self).setUp() # register connection. #create two users. self.user_a = User(name='user_a', email='*****@*****.**', verify_email_token='created') self.user_a.save() self.user_b = User(name='user_b', email='*****@*****.**', verify_email_token='created') self.user_b.save() #have the second user follow the first self.shake_a = Shake.get('user_id = %s and type=%s', self.user_a.id, 'user') self.user_b.subscribe(self.shake_a) #user one adds two files to their shake self.source = Sourcefile(width=20, height=20, file_key="asdf", thumb_key="asdf_t") self.source.save() self.shared_1 = Sharedfile(source_id=self.source.id, name="my shared file",user_id=self.user_a.id, \ content_type="image/png", share_key="oj") self.shared_1.save() self.shared_2 = Sharedfile(source_id=self.source.id, name="my shared file",user_id=self.user_a.id, \ content_type="image/png", share_key="ok") self.shared_2.save()
def test_query_friend_shake_before_after(self): """ Admin (user_a), who user2 (user_b) follows, uploads 10 files, which appear in Admin's stream. /friends/before/{share_key} should return all files that came before passed in share_key while /friends/after/{share_key} should return those that came after. We assume there is already one file uploaded by Admin (share_key -> 1) """ files = [] for x in range(10): source_file = Sourcefile(width=10, height=10, file_key='mumbles', thumb_key='bumbles') source_file.save() sf = Sharedfile(source_id = source_file.id, user_id = self.user_a.id, name="shgaredfile.png", title='shared file', content_type='image/png', deleted=0) sf.save() sf.share_key = base36encode(sf.id) sf.save() sf.add_to_shake(self.user_a.shake()) files.append(sf) request = signed_request(self.access_token, self.get_url('/api/friends/before/%s' % files[3].share_key)) self.http_client.fetch(request, self.stop) response = self.wait() j_response = json_decode(response.body) self.assertEqual(4, len(j_response['friend_shake'])) request = signed_request(self.access_token, self.get_url('/api/friends/after/%s' % files[3].share_key)) self.http_client.fetch(request, self.stop) response = self.wait() j_response = json_decode(response.body) self.assertEqual(6, len(j_response['friend_shake']))
def test_paginated_sharedfiles_and_count(self): """ Tests both the pagination of a shake's shared files and the count """ sharedfiles = [] sourcefile = Sourcefile(width=20, height=20, file_key="asdf", thumb_key="asdf_t") sourcefile.save() for i in range(31): sf = Sharedfile(source_id=sourcefile.id, name="my shared file", user_id=self.user.id, content_type="image/png", share_key="1", description="some\ndescription\nhere", source_url="https://www.mltshp.com/?hi") sf.save() sf.add_to_shake(self.shake) sharedfiles.append(sf) self.assertEqual(len(self.shake.sharedfiles()), 10) #default self.assertEqual(len(self.shake.sharedfiles(page=1)), 10) self.assertEqual(len(self.shake.sharedfiles(page=2)), 10) self.assertEqual(len(self.shake.sharedfiles(page=3)), 10) self.assertEqual(len(self.shake.sharedfiles(page=4)), 1) self.assertEqual(len(self.shake.sharedfiles(page=1, per_page=31)), 31)
def test_quick_notifications(self): """ /account/quick-notifications should return without error when populated with all possible notification types. Page should also not be accessible if you're not signed in. """ self.user2 = User(name='example2',email='*****@*****.**', \ verify_email_token = 'created', password='******', email_confirmed=1, is_paid=1) self.user2.save() self.sourcefile = Sourcefile(width=20,height=20,file_key="asdf", \ thumb_key="asdf_t") self.sourcefile.save() self.sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file", \ user_id=self.user.id, content_type="image/png", share_key="ok") self.sharedfile.save() self.shake = Shake(user_id=self.user2.id, name='asdf', type='group', title='My Test Shake', description='Testing this shake test.') self.shake.save() # new subscription new_sub = Subscription(user_id=self.user2.id, shake_id=1) new_sub.save() new_subscriber = Notification.new_subscriber(sender=self.user2, receiver=self.user, action_id=new_sub.id) # new favorite new_favorite = Notification.new_favorite(sender=self.user2, sharedfile=self.sharedfile) # new save new_save = Notification.new_save(sender=self.user2, sharedfile=self.sharedfile) # new comment new_comment = Comment(user_id=self.user2.id, sharedfile_id=self.sharedfile.id, body="Testing comment") new_comment.save() # new mention new_mention = Notification.new_mention(receiver=self.user, comment=new_comment) # new invitation new_mention = Notification.new_invitation(sender=self.user2, receiver=self.user, action_id=self.shake.id) response = self.fetch_url('/account/quick-notifications') self.assertEqual(200, response.code) self.sign_out() response = self.fetch_url('/account/quick-notifications', follow_redirects=False) self.assertEqual(302, response.code)
def on_thumbnail_response(self, response): if response.code != 200: self.render( "tools/save-video-error.html", message= "We could not load the thumbnail for this file and therefore could not save this video. Please contact support." ) return # save the response url = self.get_argument('url') current_user = self.get_current_user_object() sha1_key = Sourcefile.get_sha1_file_key(file_path=None, file_data=url) thumbnail_path = "%s/%s" % (options.uploaded_files, sha1_key) fh = open(thumbnail_path, 'wb') fh.write(response.body) fh.close() source_file = Sourcefile.create_from_json_oembed( link=url, oembed_doc=self.oembed_doc, thumbnail_file_path=thumbnail_path) #cleanup if not options.debug: try: os.remove(thumbnail_path) except: pass title = '' if self.oembed_doc.has_key('title'): title = self.oembed_doc['title'] shared_file = Sharedfile(user_id=current_user.id, name=url, content_type='text/html', source_id=source_file.id, title=title, source_url=url) shared_file.save() share_key = base36encode(shared_file.id) shared_file.share_key = share_key shared_file.save() user_shake = Shake.get('user_id = %s and type=%s', current_user.id, 'user') shared_file.add_to_shake(self.destination_shake) if self.oembed_doc.has_key('description'): shared_file.description = self.oembed_doc['description'] self.write({'path': "/p/%s" % (share_key)}) self.finish()
class ConversationModelTests(BaseTestCase): def setUp(self): """ Create a user, a source file and a shared file to user in tests. """ super(ConversationModelTests, self).setUp() self.user = User(name='example',email='*****@*****.**', verify_email_token = 'created', password='******', email_confirmed=1, is_paid=1) self.user.save() self.another_user = User(name='somethingelse',email='*****@*****.**', verify_email_token = 'created', password='******', email_confirmed=1, is_paid=1) self.another_user.save() self.sourcefile = Sourcefile(width=20,height=20,file_key="asdf", \ thumb_key="asdf_t") self.sourcefile.save() self.sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file", \ user_id=self.user.id, content_type="image/png", share_key="ok") self.sharedfile.save() def test_relevant_comments(self): """ Conversation.relevant_comments returns all the comments for the conversation at hand. """ comment = Comment(sharedfile_id=self.sharedfile.id, user_id=self.another_user.id, body='test') comment.save() another_user_conversation = Conversation.get('user_id = %s', self.another_user.id) self.assertEqual(1, len(another_user_conversation.relevant_comments())) comment2 = Comment(sharedfile_id=self.sharedfile.id, user_id=self.another_user.id, body='two') comment2.save() self.assertEqual(2, len(another_user_conversation.relevant_comments())) def test_for_user_doesnt_return_muted_conversations(self): """ When we create a Comment, conversation gets created for the sharedfile owner and the commenter. The conversation should appear for the commenter, unless the conversation gets muted, in which case it doesn't get returned. """ comment = Comment(sharedfile_id=self.sharedfile.id, user_id=self.another_user.id, body='test') comment.save() another_user_conversation = Conversation.get('user_id = %s', self.another_user.id) self.assertEqual(0, another_user_conversation.muted) self.assertEqual(1, len(Conversation.for_user(self.another_user.id))) another_user_conversation.muted = 1 another_user_conversation.save() self.assertEqual(0, len(Conversation.for_user(self.another_user.id)))
def setUp(self): """ Create a user sourcefile and sharedfile to work with. """ super(SharedfileModelTests, self).setUp() # register connection. self.user = User(name='thename',email='*****@*****.**',verify_email_token='created',email_confirmed=0) self.user.set_password('pass') self.user.save() self.sourcefile = Sourcefile(width=20,height=20,file_key="asdf",thumb_key="asdf_t") self.sourcefile.save() self.sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file",user_id=self.user.id, \ content_type="image/png", share_key="1", description="some\ndescription\nhere", source_url="http://www.mltshp.com/?hi") self.sharedfile.save()
def _create_sharedfile(self, user): """ Utility to create a stub sharedfile for the user. """ sourcefile = Sourcefile(width=20,height=20,file_key="asdf",thumb_key="asdf_t") sourcefile.save() sharedfile = Sharedfile(source_id=sourcefile.id, name="the name",user_id=user.id, \ content_type="image/png", title='the title', description="the description", \ source_url="https://www.mltshp.com/?hi") sharedfile.save() sharedfile.share_key = lib.utilities.base36encode(sharedfile.id) sharedfile.save() return sharedfile
def test_create_from_json_oembed(self): o_encoded = [ 'https://vimeo.com/api/oembed.json?url=https%3A%2F%2Fvimeo.com%2F7100569', 'https://www.youtube.com/oembed?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbDOYN-6gdRE&format=json&maxwidth=550' ] #get each url #and # test_responses = [ r'{"provider_url": "https:\/\/www.youtube.com\/", "title": "Auto-Tune the News #8: dragons. geese. Michael Vick. (ft. T-Pain)", "html": "<object width=\"425\" height=\"344\"><param name=\"movie\" value=\"https:\/\/www.youtube.com\/e\/bDOYN-6gdRE\"><\/param><param name=\"allowFullScreen\" value=\"true\"><\/param><param name=\"allowscriptaccess\" value=\"always\"><\/param><embed src=\"https:\/\/www.youtube.com\/e\/bDOYN-6gdRE\" type=\"application\/x-shockwave-flash\" width=\"425\" height=\"344\" allowscriptaccess=\"always\" allowfullscreen=\"true\"><\/embed><\/object>", "author_name": "schmoyoho", "height": 344, "thumbnail_width": 480, "width": 425, "version": "1.0", "author_url": "https:\/\/www.youtube.com\/user\/schmoyoho", "provider_name": "YouTube", "thumbnail_url": "http:\/\/i3.ytimg.com\/vi\/bDOYN-6gdRE\/hqdefault.jpg", "type": "video", "thumbnail_height": 360}', r'{"type":"video","version":"1.0","provider_name":"Vimeo","provider_url":"https:\/\/vimeo.com\/","title":"Brad!","author_name":"Casey Donahue","author_url":"https:\/\/vimeo.com\/caseydonahue","is_plus":"1","html":"<iframe src=\"https:\/\/player.vimeo.com\/video\/7100569\" width=\"1280\" height=\"720\" frameborder=\"0\"><\/iframe>","width":"1280","height":"720","duration":"118","description":"Brad finally gets the attention he deserves.","thumbnail_url":"http:\/\/b.vimeocdn.com\/ts\/294\/128\/29412830_1280.jpg","thumbnail_width":1280,"thumbnail_height":720,"video_id":"7100569"}', ] for response in test_responses: Sourcefile.create_from_json_oembed(response)
def test_make_oembed_url(self): v_urls = [ 'https://vimeo.com/7100569', 'https://www.youtube.com/watch?v=bDOYN-6gdRE' ] o_encoded = [ 'https://vimeo.com/api/oembed.json?url=https%3A%2F%2Fvimeo.com%2F7100569&maxwidth=550', 'https://www.youtube.com/oembed?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbDOYN-6gdRE&maxwidth=550&format=json' ] oembed_url = Sourcefile.make_oembed_url(v_urls[0]) self.assertEqual(oembed_url, o_encoded[0]) oembed_url = Sourcefile.make_oembed_url(v_urls[1]) self.assertEqual(oembed_url, o_encoded[1])
def setUp(self): """ Create a user sourcefile and sharedfile to work with. """ super(CommentModelTests, self).setUp() # register connection. self.user = User(name='thename',email='*****@*****.**',verify_email_token='created',email_confirmed=1, is_paid=1) self.user.save() self.sourcefile = Sourcefile(width=20,height=20,file_key="asdf",thumb_key="asdf_t") self.sourcefile.save() self.sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file",user_id=self.user.id, \ content_type="image/png", share_key="ok") self.sharedfile.save() self.visitor = User(name='visitor',email='*****@*****.**',verify_email_token='created',email_confirmed=1, is_paid=1) self.visitor.save()
def test_posting_fails_when_provider_is_not_localhost(self): provider = "http://notes.torrez.org" """ Copies a file to the file-system, then POSTs the location and details to the upload method for processing """ file_path = os.path.abspath("test/files/1.png") sha1 = Sourcefile.get_sha1_file_key(file_path) content_type = "image/png" file_name = os.path.basename(file_path) file_size = os.path.getsize(file_path) body = "media_name=%s&media_content_type=%s&media_sha1=%s&media_size=%s&media_path=%s" % ( file_name, content_type, sha1, file_size, file_path) request = HTTPRequest( url=self.get_url('/upload'), method='POST', headers={ 'X-Auth-Service-Provider': provider, 'X-Verify-Credentials-Authorization': 'OAuth oauth_timestamp="1290404453", oauth_version="1.0", oauth_consumer_key="IQKbtAYlXLripLGPWd0HUA", oauth_token="37458155-JCG7c8oejM6N4TK4HJbXVC5VGq1gtaSUPt90wxFI", oauth_signature="9QxkJqBAJfZ83sbz6SCJKSaPn9U%3D", oauth_nonce="C7AB0CBC-9193-44EE-AFC1-6FE3BA51F048", oauth_signature_method="HMAC-SHA1"' }, body=body, ) self.http_client.fetch(request, self.stop) response = self.wait() self.assertEqual(response.code, 403)
def setUp(self): """ Create a user, a source file and a shared file to user in tests. """ super(UserModelTests, self).setUp() self.user = User(name='example',email='*****@*****.**', \ verify_email_token = 'created', password='******', email_confirmed=1, is_paid=1) self.user.save() self.sourcefile = Sourcefile(width=20,height=20,file_key="asdf", \ thumb_key="asdf_t") self.sourcefile.save() self.sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file", \ user_id=self.user.id, content_type="image/png", share_key="ok") self.sharedfile.save() self.user_shake = self.user.shake() self.sharedfile.add_to_shake(self.user_shake)
def setUp(self): super(NotificationTests, self).setUp() self.sender = User(name="admin", email="*****@*****.**", email_confirmed=1, is_paid=1) self.sender.set_password('asdfasdf') self.sender.save() self.receiver = User(name="user2", email="*****@*****.**", email_confirmed=1, is_paid=1) self.receiver.set_password('asdfasdf') self.receiver.save() self.xsrf = self.get_xsrf() self.sender_sid = self.sign_in('admin', 'asdfasdf') self.receiver_sid = self.sign_in('user2', 'asdfasdf') self.test_file1_path = os.path.abspath("test/files/1.png") self.test_file1_sha1 = Sourcefile.get_sha1_file_key( self.test_file1_path) self.test_file1_content_type = "image/png" self.upload_file(self.test_file1_path, self.test_file1_sha1, self.test_file1_content_type, 1, self.receiver_sid, self.xsrf)
def test_total_file_count_for_this_month(self): """ tests that the current amount of new files uploaded for the current month is correct """ images = ['red.gif', 'blue.gif', 'green.gif', 'love.gif'] for image in images: file_name = image file_content_type = 'image/gif' file_path = os.path.abspath("test/files/%s" % (file_name)) file_sha1 = Sourcefile.get_sha1_file_key(file_path) sf = Sharedfile.create_from_file(file_path=file_path, file_name=file_name, sha1_value=file_sha1, content_type=file_content_type, user_id=self.user.id) month_days = calendar.monthrange(datetime.utcnow().year, datetime.utcnow().month) start_time = datetime.utcnow().strftime("%Y-%m-01") end_time = datetime.utcnow().strftime("%Y-%m-" + str(month_days[1])) self.assertEqual( self.user.uploaded_kilobytes(start_time=start_time, end_time=end_time), 72)
def test_sharedfile_from_new_file(self): test_files = os.path.join(os.path.dirname(os.path.dirname(__file__)), "files") file_key = Sourcefile.get_sha1_file_key(test_files + "/1.png") shutil.copyfile("%s/1.png" % (test_files), "/tmp/%s" % (file_key)) shared_file = Sharedfile.create_from_file("/tmp/%s" % (file_key),"1.png", file_key, "image/png", self.user.id) self.assertEqual(shared_file.id, 2) self.assertEqual(shared_file.source_id, 2)
def _post_to_shake(self, user, to_shake=None): """ Utility method for creating a post to a shake. If shake is not specified, the newly created sharedfile will be added to the user's shake. """ source_file = Sourcefile(width=10, height=10, file_key='mumbles', thumb_key='bumbles') source_file.save() sf = Sharedfile(source_id=source_file.id, user_id=user.id, name="sharedfile.png", title='shared file', content_type='image/png', deleted=0) sf.save() sf.share_key = base36encode(sf.id) sf.save() if to_shake: sf.add_to_shake(to_shake) else: sf.add_to_shake(user.shake()) return sf
def test_subscription_timeline_shows_appropriate_images(self): """ We have a user subscribe to the shakes of 2 other users. The users that are being subscribed to have one sharedfile each, both pointing to same source file. When a user subscribes, his timeline will be populated with last 10 posts from user being subscribed to. In this case, timeline will suppress dupes. """ user1 = User(name='user', email='*****@*****.**', is_paid=1) user1.save() source_file = Sourcefile(width=10, height=10, file_key='mumbles', thumb_key='bumbles') source_file.save() users = ['user2', 'user3', 'user4'] for name in users: user = User(name=name, email='*****@*****.**' % (name), is_paid=1) user.save() sf = Sharedfile(source_id=source_file.id, user_id = user.id, name='%s file.jpg' % (name), \ title='%s file' % (name), share_key='%s' % (name), content_type='image/jpg', deleted=0) sf.save() sf.add_to_shake(user.shake()) # have user follow two users' shakes user2 = User.get('name=%s', 'user2') user3 = User.get('name=%s', 'user3') user1.subscribe(user2.shake()) user1.subscribe(user3.shake()) shared_files = user1.sharedfiles_from_subscriptions() self.assertEqual(1, len(shared_files)) self.assertEqual(shared_files[0].source_id, source_file.id) shared_files[0].deleted = 1 shared_files[0].save() # they should no longer see the shared file since it # was deleted. shared_files = user1.sharedfiles_from_subscriptions() self.assertEqual(0, len(shared_files))
def test_non_signed_in_permalink_view(self): user = User(name='admin', email='*****@*****.**', email_confirmed=1) user.save() src = Sourcefile(width=100, height=100, file_key="asdf", thumb_key="asdfqwer") src.save() sf = Sharedfile(source_id=src.id, user_id=1, name="some.jpg", title="some", share_key="1", content_type="image/jpg") sf.save() self.http_client.fetch(self.get_url('/p/1'), self.stop) response = self.wait() self.assertEqual(response.code, 200)
def test_user_paid_account_rss_works(self): sourcefile = Sourcefile(width=20, height=20, file_key="asdf", thumb_key="asdf_t") sourcefile.save() sharedfile = Sharedfile(source_id=sourcefile.id, name="the name",user_id=self.user.id, \ content_type="image/png", description="description", source_url="https://www.mltshp.com/?hi") sharedfile.save() sharedfile.share_key = lib.utilities.base36encode(sharedfile.id) sharedfile.save() sharedfile.add_to_shake(self.user.shake()) response = self.fetch_url('/user/admin/rss') self.assertEqual(response.headers['Content-Type'], 'application/xml') parsed_xml = lib.utilities.parse_xml(response.body) self.assertEqual(parsed_xml['rss']['channel']['item']['link'], 'https://mltshp.com/p/1')
def setUp(self): super(ReadonlyTests, self).setUp() options.readonly = False self.admin = test.factories.user() self.sid = self.sign_in("admin", "password") self.xsrf = self.get_xsrf() self.test_file1_path = os.path.abspath("test/files/1.png") self.test_file1_sha1 = Sourcefile.get_sha1_file_key(self.test_file1_path) self.test_file1_content_type = "image/png"
def setUp(self): """ user_a -> admin user_b -> user2 user_a uploads shared file. We authenticate to the API with user_b. user_b subscribes to user_a's shake.] """ super(APIResourceRequests, self).setUp() self.user_a = User( name='admin', email='*****@*****.**', email_confirmed=1, is_paid=1, about="admin", website='https://mltshp.com') self.user_a.set_password('asdfasdf') self.user_a.save() self.sid = self.sign_in('admin', 'asdfasdf') self.xsrf = self.get_xsrf() self.test_file1_path = os.path.abspath("test/files/1.png") self.test_file1_sha1 = Sourcefile.get_sha1_file_key(self.test_file1_path) self.test_file1_content_type = "image/png" response = self.upload_file(file_path=self.test_file1_path, sha1=self.test_file1_sha1, content_type=self.test_file1_content_type, user_id=self.user_a.id, sid=self.sid, xsrf=self.xsrf) self.user_b = User(name='user2', email='*****@*****.**', email_confirmed=1, is_paid=1) self.user_b.set_password('asdfasdf') self.user_b.save() self.group_shake = self.user_b.create_group_shake(title='Group Shake', name='groupshake', description='This is a group shake.') self.group_shake_2 = self.user_a.create_group_shake(title='Another Group', name='anothergroup') # Add user_b to user_a's group shake, so we get it in user_b's /shakes endpoint. shake_manager = ShakeManager(user_id=self.user_b.id, shake_id=self.group_shake_2.id) shake_manager.save() self.app = App(user_id=self.user_a.id, title='An App', description='Nothing yet.', redirect_url='http://client.example.com/return') self.app.save() self.authorization = Authorizationcode.generate(self.app.id, self.app.redirect_url, self.user_b.id) self.access_token = Accesstoken.generate(self.authorization.id) extra_authorization = Authorizationcode.generate(self.app.id, self.app.redirect_url, self.user_b.id) self.ratelimited_access_token = Accesstoken.generate(extra_authorization.id) now_hour = datetime.utcnow().strftime('%Y-%m-%d %H:00:00') ratelimit = Apihit(accesstoken_id=self.ratelimited_access_token.id, hits=options.api_hits_per_hour - 2, hour_start=now_hour) ratelimit.save() #subscription self.user_b.subscribe(self.user_a.shake())
def upload_test_file(self, shake_id=None): arguments = {} if shake_id: arguments['shake_id'] = int(shake_id) arguments['file_name'] = 'love.gif' arguments['file_content_type'] = 'image/gif' arguments['file_path'] = os.path.abspath("test/files/love.gif") arguments['file_sha1'] = Sourcefile.get_sha1_file_key( arguments['file_path']) arguments['file_size'] = os.path.getsize(arguments['file_path']) return self.post_url('/upload?skip_s3=1', arguments)
def get(self): url = self.get_argument('url', None) shake_id = self.get_argument('shake_id', "") if not url: self.render("tools/save-video.html", url=url, shake_id=shake_id) return url = Sourcefile.make_oembed_url(url.strip()) if url: self.handle_oembed_url(url) else: self.render("tools/save-video-error.html", message="Invalid URL. We didn't recognize that URL")