コード例 #1
0
ファイル: home_tests.py プロジェクト: vosechu/mltshp
    def test_home_page_with_friends(self):
        """
        Creates ten users, user 1 follows five of them, each user uploads a file, 
        result from hitting /friends will return five files.
        
        When we go to friends for first time, bookmark will be set. If done multiple times, 
        still will only have one bookmark if no files have been uploaded between visits.
        """
        for x in range(10):
            user = User(name='test%s' % (x),
                        email='*****@*****.**' % (x),
                        email_confirmed=1)
            user.save()
            sf = test.factories.sharedfile(user)
            sf.add_to_shake(user.shake())
            if (x % 2) == 0:
                self.admin.subscribe(user.shake())

        ssf = Shakesharedfile.all()
        self.assertEqual(len(ssf), 10)
        self.assertEqual(len(self.admin.sharedfiles_from_subscriptions()), 5)

        response = self.fetch_url('/friends')
        self.assertEqual(response.code, 200)
        self.assertEqual(1, len(Bookmark.all()))

        response = self.fetch_url('/friends')
        self.assertEqual(response.code, 200)
        self.assertEqual(1, len(Bookmark.all()))
コード例 #2
0
ファイル: home_tests.py プロジェクト: vosechu/mltshp
    def test_home_page_non_user_request(self):
        """
        Safari, Firefox and other browsers like to fetch pages to create
        preview images (i.e. Safari's Top Sites) feature.  Or prefetch
        for speeding up future render times. When we can detect that
        the request is not user-intiated, we want to make sure
        we don't set any bookmarks for the user.
        
        When a browser bot accesses the home page, no bookmarks should be
        set.
        """
        user = User(name='user2', email='*****@*****.**', email_confirmed=1)
        user.save()
        self.admin.subscribe(user.shake())

        saved_files = []
        for x in range(5):
            sf = test.factories.sharedfile(user)
            sf.add_to_shake(user.shake())
            saved_files.append(sf)

        response = self.fetch_url('/friends', headers={"X-Purpose": "preview"})
        self.assertEqual(response.code, 200)
        self.assertEqual(0, len(Bookmark.all()))

        response = self.fetch_url('/friends', headers={"X-Moz": "prefetch"})
        self.assertEqual(response.code, 200)
        self.assertEqual(0, len(Bookmark.all()))

        response = self.fetch_url('/friends', )
        self.assertEqual(response.code, 200)
        self.assertEqual(1, len(Bookmark.all()))
コード例 #3
0
ファイル: test_models.py プロジェクト: jkpluta/jkpluta
 def testBookmark(self):
     Bookmark(author=self.current_user, title='Test 1').put()
     self.assertEqual(1, Bookmark.all().count(10))
     Bookmark(author=self.current_user, title='Test 2').put()
     self.assertEqual(2, Bookmark.all().count(10))
     bookmark = Bookmark(author=self.current_user, title='Test 3', description=u'Treść', url='jkpluta.appspot.com')
     bookmark.put()
     self.assertEqual(3, Bookmark.all().count(10))
     Bookmark(author=self.current_user, reference=bookmark, title='Test 3A').put()
     self.assertEqual(4, Bookmark.all().count(10))
     Bookmark(author=self.current_user, reference=bookmark, title='Test 3B').put()
     self.assertEqual(5, Bookmark.all().count(10))
     Bookmark(author=self.current_user, reference=bookmark, title='Test 3C').put()
     self.assertEqual(6, Bookmark.all().count(10))
     with self.assertRaises(datastore_errors.BadValueError):
         Bookmark().put()
     self.assertEqual(6, Bookmark.all().count(10))
     db.delete(bookmark)
     self.assertEqual(5, Bookmark.all().count(10))
     child_bookmark = Bookmark(author=self.current_user, reference=bookmark, title='Test X')
     child_bookmark.put()
     self.assertEqual(6, Bookmark.all().count(10))
     test_bookmark = db.get(db.Key.from_path('Bookmark', int(child_bookmark.key().id())))
     with self.assertRaises(datastore_errors.ReferencePropertyResolveError):
         test_bookmark.reference != None
コード例 #4
0
ファイル: home_tests.py プロジェクト: vosechu/mltshp
 def test_home_page_no_sharedfiles(self):
     """
     Accessing friend page with no files
     - Should not error. 
     - No bookmarks should be created.
     - Introduction to mltshp should show.
     """
     response = self.fetch_url('/friends')
     self.assertEqual(200, response.code)
     self.assertEqual(0, len(Bookmark.all()))
コード例 #5
0
ファイル: main_handler.py プロジェクト: diptanu/bookmarkplus
 def get(self):
     user = users.get_current_user()
     if user is None:
         self.redirect(users.create_login_url(self.request.uri))
     
     logout_url = users.create_logout_url(self.request.uri)
     username = user.nickname() if user is not None else ""
     urls_query = Bookmark.all()
     last_cursor = memcache.get('bookmark_cursor')
     if last_cursor:
         urls_query.with_cursor(last_cursor)
     urls_query.filter('user ='******'bookmark_cursor', urls_query.cursor())
     logging.error(urls)
     template_values = {'user_name': username, 'logout_url': logout_url, 'urls': urls}
     path = os.path.join(os.path.dirname(__file__), 'templates/index.html')
     self.response.out.write(template.render(path, template_values))
コード例 #6
0
ファイル: api.py プロジェクト: bavardage/Bookmarks
    def get(self):
        g = self.request.get
        q = Bookmark.all()
        if g('key'):
            b = Bookmark.get(g('key'))
            if b:
                if self.has_permission_for(b):
                    self.json_output([b,])
                    return
                else:
                    self.do_error('forbidden')
            else:
                self.do_error('not-found')
        if g('tag'):
            q = q.filter('tags=', g('tag'))
        if g('tags'): #union comma sep
            q = q.filter('tags IN', g('tags').split(','))
        if g('all_tags'):
            for t in g('all_tags').split(','):
                q = q.filter('tags=', t)
        if g('link'):
            l = Link.all().filter('url=', g('link')).get()
            if l:
                q = q.filter('link=', l)
        if g('title'):
            q = q.filter('title=', g('title'))
        if g('access'):
            q = q.filter('access=', g('access'))
        if g('user'):
            q = q.filter('user='******'-created')

        try:
            limit = int(g('limit'))
        except:
            limit = 10

        results = [r for r in q.fetch(limit) if self.can_view(r)]
        self.json_output(results)
コード例 #7
0
ファイル: test_utils.py プロジェクト: jkpluta/jkpluta
 def test_read_bookmarks_from_file(self):
     with codecs.open(os.path.join(os.path.dirname(__file__), 'bookmarks.html'), 'r', 'utf-8') as f:
         html = f.read()
     soup = BeautifulSoup(html, "html5lib")
     parse_bookmarks(soup.dl, None)
     self.assertEqual(106, Bookmark.all().count(1000))
コード例 #8
0
ファイル: bookmarks.py プロジェクト: jkpluta/jkpluta
 def delete_all(self):
     if not users.get_current_user():
         webapp2.abort(401)
     bookmarks = Bookmark.all()
     db.delete(bookmarks)
     return self.redirect('/bookmark/list')