示例#1
0
    def test_add_rating(self):
        """ Test the add_rating function of taggerlib. """
        create_user(self.session)
        user_pingou = model.FASUser.by_name(self.session, 'pingou')
        user_ralph = model.FASUser.by_name(self.session, 'ralph')

        create_package(self.session)
        out = fedoratagger.lib.add_rating(self.session, 'guake', 100,
                                          user_pingou)
        self.assertEqual(out, 'Rating "100" added to the package "guake"')
        self.session.commit()

        pkg = model.Package.by_name(self.session, 'guake')
        rating = model.Rating.rating_of_package(self.session, pkg.id)
        self.assertEqual(100, rating)

        out = fedoratagger.lib.add_rating(self.session, 'guake', 50,
                                          user_pingou)
        self.assertEqual(out, 'Rating on package "guake" changed to "50"')
        self.session.commit()
        out = fedoratagger.lib.add_rating(self.session, 'guake', 50,
                                          user_pingou)
        self.assertEqual(out, 'Rating on package "guake" did not change')
        self.session.commit()

        out = fedoratagger.lib.add_rating(self.session, 'guake', 100,
                                          user_ralph)
        self.assertEqual(out, 'Rating "100" added to the package "guake"')
        self.session.commit()

        rating = model.Rating.rating_of_package(self.session, pkg.id)
        self.assertEqual(75, rating)

        r = fedoratagger.lib.model.Package.rating(pkg, self.session)
        self.assertEquals(75, r)
    def test_user_assign(self):
        """
        Check user assign and timestamps
        """
        # Test Plugin.add_preference
        test_user1 = tests.create_user(**tests.TEST_USERS["superuser"])
        pref_obj = self.test_plugin.add_preference(
            comment = "pref one",
            data = TEST_DICT1,
            user = test_user1
        )
        self.assertEqual(pref_obj.createby, test_user1)
        self.assertEqual(pref_obj.lastupdateby, test_user1)
        createtime1 = pref_obj.createtime
        lastupdatetime1 = pref_obj.lastupdatetime

        # Test timestamps
        self.failUnless(createtime1 < datetime.now())
        self.failUnless(lastupdatetime1 < datetime.now())

        # Test Preferences.set_data
        test_user2 = tests.create_user(**tests.TEST_USERS["staff"])
        pref_obj.set_data(TEST_DICT2, user=test_user2)
        pref_obj.save()
        self.assertEqual(pref_obj.createby, test_user1)
        self.assertEqual(pref_obj.lastupdateby, test_user2)

        # Test timestamps
        self.failUnless(pref_obj.createtime == createtime1)
        self.failUnless(pref_obj.lastupdatetime > lastupdatetime1)
示例#3
0
    def test_add_rating(self):
        """ Test the add_rating function of taggerlib. """
        create_user(self.session)
        user_pingou = model.FASUser.by_name(self.session, 'pingou')
        user_ralph = model.FASUser.by_name(self.session, 'ralph')

        create_package(self.session)
        out = fedoratagger.lib.add_rating(self.session, 'guake', 100,
                                             user_pingou)
        self.assertEqual(out, 'Rating "100" added to the package "guake"')
        self.session.commit()

        pkg = model.Package.by_name(self.session, 'guake')
        rating = model.Rating.rating_of_package(self.session, pkg.id)
        self.assertEqual(100, rating)

        out = fedoratagger.lib.add_rating(self.session, 'guake', 50,
                                          user_pingou)
        self.assertEqual(out, 'Rating on package "guake" changed to "50"')
        self.session.commit()
        out = fedoratagger.lib.add_rating(self.session, 'guake', 50,
                                          user_pingou)
        self.assertEqual(out, 'Rating on package "guake" did not change')
        self.session.commit()

        out = fedoratagger.lib.add_rating(self.session, 'guake', 100,
                                          user_ralph)
        self.assertEqual(out, 'Rating "100" added to the package "guake"')
        self.session.commit()

        rating = model.Rating.rating_of_package(self.session, pkg.id)
        self.assertEqual(75, rating)

        r = fedoratagger.lib.model.Package.rating(pkg, self.session)
        self.assertEquals(75, r)
示例#4
0
    def test_bypass_login(self):
        create_user()
        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['_user_id'] = '1'
                sess['_fresh'] = True

            rv = c.get('/', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'logout',
                            "response contains text 'logout'")
示例#5
0
    def test_login(self):
        create_user()
        self.app.logger.info("created user")
        with self.app.test_client() as c:
            rv = c.post('/login',
                        data=dict(username="******", password="******"),
                        follow_redirects=True)

            six.assertRegex(self, str(rv.data), 'Logged in successfully.',
                            "response contains login confirmation")
示例#6
0
 def test_admin_required_if_not_admin(self):
     """Test admin_required decorator if user is not admin"""
     create_book()
     create_user()
     response = login_user(self, '*****@*****.**', 'pass123')
     token = response.json["token"]
     response = self.client.delete(
         "/books/1", headers={"Authorization": f"Bearer {token}"})
     self.assertEqual(response.status_code, 403)
     self.assertEqual(response.json["message"], "Admin rights required")
示例#7
0
    def test_add_tag(self):
        """ Test the add_tag function of taggerlib. """
        create_user(self.session)
        user_pingou = model.FASUser.by_name(self.session, 'pingou')
        user_ralph = model.FASUser.by_name(self.session, 'ralph')

        create_package(self.session)

        out = fedoratagger.lib.add_tag(self.session, 'guake', u'gnóme',
                                          user_pingou)
        self.assertEqual(out, u'Tag "gnóme" added to the package "guake"')
        self.session.commit()

        pkg = model.Package.by_name(self.session, 'guake')
        self.assertEqual(1, len(pkg.tags))
        self.assertEqual(u'gnóme', pkg.tags[0].label)

        self.assertRaises(IntegrityError,
                          fedoratagger.lib.add_tag,
                          self.session, 'guake', u'gnóme', user_pingou)
        self.session.rollback()

        out = fedoratagger.lib.add_tag(self.session, 'guake', 'terminal',
                                          user_pingou)
        self.assertEqual(out, 'Tag "terminal" added to the package "guake"')
        self.session.commit()

        pkg = model.Package.by_name(self.session, 'guake')
        self.assertEqual(2, len(pkg.tags))
        self.assertEqual(u'gnóme', pkg.tags[0].label)
        self.assertEqual('terminal', pkg.tags[1].label)
        self.assertEqual(1, pkg.tags[0].like)
        self.assertEqual(1, pkg.tags[1].like)

        out = fedoratagger.lib.add_tag(self.session, 'guake', 'terminal',
                                          user_ralph)
        self.assertEqual(out, 'Tag "terminal" added to the package "guake"')
        self.session.commit()

        pkg = model.Package.by_name(self.session, 'guake')
        self.assertEqual(2, len(pkg.tags))
        self.assertEqual(u'gnóme', pkg.tags[0].label)
        self.assertEqual('terminal', pkg.tags[1].label)
        self.assertEqual(1, pkg.tags[0].like)
        self.assertEqual(2, pkg.tags[1].like)

        self.assertRaises(ValueError,
                          fedoratagger.lib.add_tag,
                          self.session, 'guake', 'ass',
                          user_pingou)

        tagobj1 = model.Tag.get(self.session, pkg.id, 'terminal')
        self.assertEquals('terminal on guake', tagobj1.__unicode__())
        tagobj2 = model.Tag.get(self.session, pkg.id, u'gnóme')
        self.assertEquals(u'gnóme on guake', tagobj2.__unicode__())
示例#8
0
    def test_add_tag(self):
        """ Test the add_tag function of taggerlib. """
        create_user(self.session)
        user_pingou = model.FASUser.by_name(self.session, 'pingou')
        user_ralph = model.FASUser.by_name(self.session, 'ralph')

        create_package(self.session)

        out = fedoratagger.lib.add_tag(self.session, 'guake', u'gnóme',
                                       user_pingou)
        self.assertEqual(out, u'Tag "gnóme" added to the package "guake"')
        self.session.commit()

        pkg = model.Package.by_name(self.session, 'guake')
        self.assertEqual(1, len(pkg.tags))
        self.assertEqual(u'gnóme', pkg.tags[0].label)

        self.assertRaises(IntegrityError, fedoratagger.lib.add_tag,
                          self.session, 'guake', u'gnóme', user_pingou)
        self.session.rollback()

        out = fedoratagger.lib.add_tag(self.session, 'guake', 'terminal',
                                       user_pingou)
        self.assertEqual(out, 'Tag "terminal" added to the package "guake"')
        self.session.commit()

        pkg = model.Package.by_name(self.session, 'guake')
        self.assertEqual(2, len(pkg.tags))
        self.assertEqual(u'gnóme', pkg.tags[0].label)
        self.assertEqual('terminal', pkg.tags[1].label)
        self.assertEqual(1, pkg.tags[0].like)
        self.assertEqual(1, pkg.tags[1].like)

        out = fedoratagger.lib.add_tag(self.session, 'guake', 'terminal',
                                       user_ralph)
        self.assertEqual(out, 'Tag "terminal" added to the package "guake"')
        self.session.commit()

        pkg = model.Package.by_name(self.session, 'guake')
        self.assertEqual(2, len(pkg.tags))
        self.assertEqual(u'gnóme', pkg.tags[0].label)
        self.assertEqual('terminal', pkg.tags[1].label)
        self.assertEqual(1, pkg.tags[0].like)
        self.assertEqual(2, pkg.tags[1].like)

        self.assertRaises(ValueError, fedoratagger.lib.add_tag, self.session,
                          'guake', 'ass', user_pingou)

        tagobj1 = model.Tag.get(self.session, pkg.id, 'terminal')
        self.assertEquals('terminal on guake', tagobj1.__unicode__())
        tagobj2 = model.Tag.get(self.session, pkg.id, u'gnóme')
        self.assertEquals(u'gnóme on guake', tagobj2.__unicode__())
    def test_refresh(self):
        create_user()
        setup_journal()

        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['_user_id'] = '1'
                sess['_fresh'] = True
            rv = c.get('/', follow_redirects=True)
            rv = c.get('/refresh', follow_redirects=True)
            rv = c.get('/day/2012-10-03.html', follow_redirects=True)
            six.assertRegex(self, str(rv.data),
                            r'graduate management consulting association',
                            "journal was loaded")
示例#10
0
    def test_pkg_get_usage(self):
        """ Test the pkg_get_usage function.  """

        output = self.app.get('/api/v1/guake/usage')
        self.assertEqual(output.status_code, 301)

        output = self.app.get('/api/v1/guake/usage/')
        self.assertEqual(output.status_code, 404)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Package "guake" not found')

        create_user(self.session)
        create_package(self.session)

        output = self.app.get('/api/v1/guake/usage/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['name'], 'guake')
        self.assertEqual(output['usage'], 0)

        # Mark two people as using it.
        set_usages(self.session, usage=True)

        output = self.app.get('/api/v1/guake/usage/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['usage'], 2)
        self.assertEqual(output['name'], 'guake')

        # And now have them no longer use it.
        set_usages(self.session, usage=False)

        output = self.app.get('/api/v1/guake/usage/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['usage'], 0)
        self.assertEqual(output['name'], 'guake')

        # But if we try to mark this twice, it only counts once.
        set_usages(self.session, usage=True)
        set_usages(self.session, usage=True)
        set_usages(self.session, usage=True)

        output = self.app.get('/api/v1/guake/usage/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['usage'], 2)
        self.assertEqual(output['name'], 'guake')
示例#11
0
    def test_pkg_get_usage(self):
        """ Test the pkg_get_usage function.  """

        output = self.app.get('/api/v1/guake/usage')
        self.assertEqual(output.status_code, 301)

        output = self.app.get('/api/v1/guake/usage/')
        self.assertEqual(output.status_code, 404)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Package "guake" not found')

        create_user(self.session)
        create_package(self.session)

        output = self.app.get('/api/v1/guake/usage/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['name'], 'guake')
        self.assertEqual(output['usage'], 0)

        # Mark two people as using it.
        set_usages(self.session, usage=True)

        output = self.app.get('/api/v1/guake/usage/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['usage'], 2)
        self.assertEqual(output['name'], 'guake')

        # And now have them no longer use it.
        set_usages(self.session, usage=False)

        output = self.app.get('/api/v1/guake/usage/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['usage'], 0)
        self.assertEqual(output['name'], 'guake')

        # But if we try to mark this twice, it only counts once.
        set_usages(self.session, usage=True)
        set_usages(self.session, usage=True)
        set_usages(self.session, usage=True)

        output = self.app.get('/api/v1/guake/usage/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['usage'], 2)
        self.assertEqual(output['name'], 'guake')
    def test_latest(self):
        create_user()
        setup_journal()

        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['_user_id'] = '1'
                sess['_fresh'] = True

            # trigger refresh of journal
            rv = c.get('/refresh', follow_redirects=True)

            rv = c.get('/latest', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03',
                            "request latest.html")
示例#13
0
    def test_banned(self):
        """ Test the banned property of a Tag"""
        create_user(self.session)
        user_pingou = model.FASUser.by_name(self.session, 'pingou')
        create_package(self.session)
        pkg = model.Package.by_name(self.session, 'guake')
        out = fedoratagger.lib.add_tag(self.session, 'guake', 'X-test',
                                       user_pingou)
        self.assertEqual(out, 'Tag "x-test" added to the package "guake"')

        tagobj = model.Tag.get(self.session, pkg.id, 'x-test')
        self.assertEquals(True, tagobj.banned)
        out = fedoratagger.lib.add_tag(self.session, 'guake', 'terminal',
                                       user_pingou)
        self.assertEqual(out, 'Tag "terminal" added to the package "guake"')
        tagobj = model.Tag.get(self.session, pkg.id, 'terminal')
        self.assertEquals(False, tagobj.banned)
        out = fedoratagger.lib.add_tag(self.session, 'guake', 'application',
                                       user_pingou)
        self.assertEqual(out, 'Tag "application" added to the package "guake"')
        tagobj = model.Tag.get(self.session, pkg.id, 'application')
        self.assertEquals(True, tagobj.banned)
    def test_representations(self):
        create_user()
        setup_journal()

        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['_user_id'] = '1'
                sess['_fresh'] = True

            # trigger refresh of journal
            rv = c.get('/refresh', follow_redirects=True)

            rv = c.get('/day/2012-10-03.html', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03',
                            "get day as HTML")
            rv = c.get('/day/2012-10-02.html', follow_redirects=True)

            self.assertNotRegex(str(rv.data), r'2012-10-03',
                                "get non-existent day as HTML")

            rv = c.get('/day/2012-10-03.txt', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03',
                            "get day as text")
            rv = c.get('/day/2012-10-02.txt', follow_redirects=True)

            self.assertNotRegex(str(rv.data), r'2012-10-03',
                                "get non-existent day as text")

            rv = c.get('/day/2012-10-03.md', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03',
                            "get day as markdown")
            rv = c.get('/day/2012-10-02.md', follow_redirects=True)

            self.assertNotRegex(str(rv.data), r'2012-10-03',
                                "get non-existent day as markdown")

            rv = c.get('/day/2012-10-03.pdf', follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'PDF', "get day as PDF")
            self.assertEqual(len(rv.data), 306, "size match on download")
    def test_search(self):
        create_user()
        setup_journal()

        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['_user_id'] = '1'
                sess['_fresh'] = True

            # trigger refresh of journal
            rv = c.get('/refresh', follow_redirects=True)

            rv = c.get('/search?q={q}'.format(q="graduate"),
                       follow_redirects=True)
            six.assertRegex(self, str(rv.data), r'2012-10-03',
                            "search for a findable string finds something")

            rv = c.get('/search?q={q}'.format(q="zorkle"),
                       follow_redirects=True)

            self.assertNotRegex(
                str(rv.data), r'2012-10-03',
                "search for a unfindable string finds nothing")
示例#16
0
    def test_banned(self):
        """ Test the banned property of a Tag"""
        create_user(self.session)
        user_pingou = model.FASUser.by_name(self.session, 'pingou')
        create_package(self.session)
        pkg = model.Package.by_name(self.session, 'guake')
        out = fedoratagger.lib.add_tag(self.session, 'guake', 'X-test',
                                       user_pingou)
        self.assertEqual(out, 'Tag "x-test" added to the package "guake"')

        tagobj = model.Tag.get(self.session, pkg.id, 'x-test')
        self.assertEquals(True, tagobj.banned)
        out = fedoratagger.lib.add_tag(self.session, 'guake',
                                       'terminal',
                                       user_pingou)
        self.assertEqual(out, 'Tag "terminal" added to the package "guake"')
        tagobj = model.Tag.get(self.session, pkg.id, 'terminal')
        self.assertEquals(False, tagobj.banned)
        out = fedoratagger.lib.add_tag(self.session, 'guake',
                                       'application',
                                       user_pingou)
        self.assertEqual(out, 'Tag "application" added to the package "guake"')
        tagobj = model.Tag.get(self.session, pkg.id, 'application')
        self.assertEquals(True, tagobj.banned)
示例#17
0
def test_user_meta_update_web(db, app):
    users = [create_user(db) for x in range(0, 8)]
    old_onlines = {}

    for user in users:
        with app.test_client() as client:
            old_onlines[user.id] = user.last_online.timestamp()
            login(user.username, "password", client=client)
            rv = client.get("/")
            assert rv.status_code == 200

    update_user_meta()
    db.expire_all()

    for uid, oldtime in old_onlines.items():
        updated = db.query(User).filter(User.id == uid).one()
        check_valid_time(oldtime, updated.last_online.timestamp())
示例#18
0
def test_user_meta_update_web(db, app):
    users = [create_user(db) for x in range(0, 8)]
    old_onlines = {}

    for user in users:
        with app.test_client() as client:
            old_onlines[user.id] = user.last_online.timestamp()
            login(user.username, "password", client=client)
            rv = client.get("/")
            assert rv.status_code == 200

    update_user_meta()
    db.expire_all()

    for uid, oldtime in old_onlines.items():
        updated = db.query(User).filter(User.id == uid).one()
        check_valid_time(oldtime, updated.last_online.timestamp())
    def setUp(self):
        """
        Create some pages, groups and users to play with.
        """
        # groups
        group_names = ('groupA','groupB')
        groups = {}
        for name in group_names:
            (groups[name],dummy) = self.Group.objects.get_or_create(name=name)
            groups[name].save()
        # users
        USERS = {
            "A": {
                    "username": "******",
                    "email": "*****@*****.**",
                    "password": "******",
                    "is_staff": False,
                    "is_superuser": False,
                    },
            "B": {
                    "username": "******",
                    "email": "*****@*****.**",
                    "password": "******",
                    "is_staff": False,
                    "is_superuser": False,
                    },
            }
        for usertype, userdata in USERS.iteritems():
            u = tests.create_user(**userdata)
            u.groups.add(groups['group'+usertype])
            u.save
        self.USERS = USERS

        self.groupPage = tests.create_page({'name':'PageForGroupA',"shortcut":"PageForGroupA"})
        self.groupPage.permitViewGroup = groups['groupA']
        self.groupPage.save()
示例#20
0
    def test_rating_put(self):
        """ Test the rating_pkg_put function.  """

        data = {'pkgname': 'guake', 'ratings': 1}

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Invalid input submitted')
        self.assertEqual(output['error_detail'],
                         ["rating: This field is required."])

        data = {'pkgname': 'guake', 'rating': '110'}

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Invalid input submitted')
        self.assertEqual(output['error_detail'],
                         ["rating: Input is not a percentage"])

        data = {'pkgname': 'guake', 'rating': '-1'}

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Invalid input submitted')
        self.assertEqual(output['error_detail'],
                         ["rating: Input is not a percentage"])

        data = {'pkgname': 'guake', 'rating': 'asd'}

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Invalid input submitted')
        self.assertEqual(output['error_detail'],
                         ["rating: This field is required."])

        data = {'pkgname': 'guake', 'rating': 100}

        output = self.app.put('/api/v1/rating/guake', data=data)
        self.assertEqual(output.status_code, 301)

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 404)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Package "guake" not found')

        create_package(self.session)

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'ok')
        self.assertEqual(output['messages'],
                         ['Rating "100" added to the package "guake"'])

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'ok')
        self.assertEqual(output['messages'],
                         ['Rating on package "guake" did not change'])

        data = {'pkgname': 'guake', 'rating': 50}
        create_user(self.session)
        user = model.FASUser.by_name(self.session, 'pingou')
        self.infos = fedoratagger.lib.get_api_token(self.session, user)

        output = self.request_with_auth('/api/v1/rating/guake/',
                                        'PUT',
                                        data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'ok')
        self.assertEqual(output['messages'],
                         ['Rating "50" added to the package "guake"'])

        output = self.app.get('/api/v1/guake/rating/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['rating'], 75.0)
        self.assertEqual(output['name'], 'guake')
示例#21
0
    def test_tag_put(self):
        """ Test the tag_pkg_put function.  """

        data = {'pkgname': 'guake', 'tags': 'terminal'}

        output = self.app.put('/api/v1/tag/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Invalid input submitted')
        self.assertEqual(output['error_detail'][0],
                         'tag: This field is required.')

        data = {'pkgname': 'guake', 'tag': 'terminal'}

        output = self.app.put('/api/v1/tag/guake', data=data)
        self.assertEqual(output.status_code, 301)

        output = self.app.put('/api/v1/tag/guake/', data=data)
        self.assertEqual(output.status_code, 404)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Package "guake" not found')

        create_package(self.session)

        output = self.app.put('/api/v1/tag/guake/', data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'ok')
        self.assertEqual(output['messages'][0],
                         'Tag "terminal" added to the package "guake"')
        self.assertEqual(output['user']['username'], 'anonymous')

        output = self.app.put('/api/v1/tag/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'],
                         'This tag is already associated to this package')

        data = {'pkgname': 'guake', 'tag': u'terminal,, gnóme'}

        create_user(self.session)
        user = model.FASUser.by_name(self.session, 'pingou')
        self.infos = fedoratagger.lib.get_api_token(self.session, user)
        self.infos['token'] = 'fake'

        output = self.request_with_auth('/api/v1/tag/guake/', 'PUT', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Login invalid/expired')

        self.infos = fedoratagger.lib.get_api_token(self.session, user)

        output = self.request_with_auth('/api/v1/tag/guake/', 'PUT', data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'ok')
        self.assertEqual(output['messages'][0],
                         'Tag "terminal" added to the package "guake"')
        self.assertEqual(output['messages'][1],
                         u'Tag "gnóme" added to the package "guake"')

        output = self.app.get('/api/v1/guake/tag/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['name'], 'guake')
        self.assertEqual(output['tags'][0]['tag'], u'gnóme')
        self.assertEqual(output['tags'][0]['votes'], 1)
        self.assertEqual(output['tags'][0]['like'], 1)
        self.assertEqual(output['tags'][0]['dislike'], 0)
        self.assertEqual(output['tags'][1]['tag'], 'terminal')
        self.assertEqual(output['tags'][1]['votes'], 2)
        self.assertEqual(output['tags'][1]['like'], 2)
        self.assertEqual(output['tags'][1]['dislike'], 0)

        #This tests that invalid tags are rejected.
        data = {'pkgname': 'guake', 'tag': 'ass'}

        output = self.app.put('/api/v1/tag/guake/', data=data)
        self.assertEqual(output.status_code, 406)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
示例#22
0
 def setUp(self):
     db.create_all()
     create_user(id=1)
     db.session.commit()
示例#23
0
 def test_encode_auth_token(self):
     """Test auth token encode"""
     user = create_user()
     auth_token = encode_auth_token(user.uuid)
     self.assertTrue(isinstance(auth_token, str))
示例#24
0
    def test_rating_put(self):
        """ Test the rating_pkg_put function.  """

        data = {'pkgname': 'guake', 'ratings': 1}

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Invalid input submitted')
        self.assertEqual(output['error_detail'],
                         ["rating: This field is required."])

        data = {'pkgname': 'guake', 'rating': '110'}

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Invalid input submitted')
        self.assertEqual(output['error_detail'],
                         ["rating: Input is not a percentage"])

        data = {'pkgname': 'guake', 'rating': '-1'}

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Invalid input submitted')
        self.assertEqual(output['error_detail'],
                         ["rating: Input is not a percentage"])

        data = {'pkgname': 'guake', 'rating': 'asd'}

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Invalid input submitted')
        self.assertEqual(output['error_detail'],
                         ["rating: This field is required."])

        data = {'pkgname': 'guake', 'rating': 100}

        output = self.app.put('/api/v1/rating/guake', data=data)
        self.assertEqual(output.status_code, 301)

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 404)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Package "guake" not found')

        create_package(self.session)

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'ok')
        self.assertEqual(output['messages'], [
                         'Rating "100" added to the package "guake"'])

        output = self.app.put('/api/v1/rating/guake/', data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'ok')
        self.assertEqual(output['messages'], [
                        'Rating on package "guake" did not change'])

        data = {'pkgname': 'guake', 'rating': 50}
        create_user(self.session)
        user = model.FASUser.by_name(self.session, 'pingou')
        self.infos = fedoratagger.lib.get_api_token(self.session, user)

        output = self.request_with_auth('/api/v1/rating/guake/', 'PUT', data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'ok')
        self.assertEqual(output['messages'], [
                         'Rating "50" added to the package "guake"'])

        output = self.app.get('/api/v1/guake/rating/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['rating'], 75.0)
        self.assertEqual(output['name'], 'guake')
示例#25
0
 def test_user(self):
     user = tests.create_user()
     self.assertFalse(isinstance(user, Status))
     self.assertTrue(isinstance(user, User))
     self.assertFalse(isinstance(user, DirectMessage))
     self.assertEqual(user.__str__(), user.id_str)
示例#26
0
    def test_tag_put(self):
        """ Test the tag_pkg_put function.  """

        data = {'pkgname': 'guake', 'tags': 'terminal'}

        output = self.app.put('/api/v1/tag/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Invalid input submitted')
        self.assertEqual(output['error_detail'][0], 'tag: This field is required.')

        data = {'pkgname': 'guake', 'tag': 'terminal'}

        output = self.app.put('/api/v1/tag/guake', data=data)
        self.assertEqual(output.status_code, 301)

        output = self.app.put('/api/v1/tag/guake/', data=data)
        self.assertEqual(output.status_code, 404)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Package "guake" not found')

        create_package(self.session)

        output = self.app.put('/api/v1/tag/guake/', data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'ok')
        self.assertEqual(output['messages'][0],
                          'Tag "terminal" added to the package "guake"')
        self.assertEqual(output['user']['username'], 'anonymous')

        output = self.app.put('/api/v1/tag/guake/', data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'],
                         'This tag is already associated to this package')

        data = {'pkgname': 'guake', 'tag': u'terminal,, gnóme'}

        create_user(self.session)
        user = model.FASUser.by_name(self.session, 'pingou')
        self.infos = fedoratagger.lib.get_api_token(self.session, user)
        self.infos['token'] = 'fake'

        output = self.request_with_auth('/api/v1/tag/guake/', 'PUT',
                                        data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
        self.assertEqual(output['error'], 'Login invalid/expired')

        self.infos = fedoratagger.lib.get_api_token(self.session, user)

        output = self.request_with_auth('/api/v1/tag/guake/', 'PUT',
                                        data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'ok')
        self.assertEqual(output['messages'][0],
                          'Tag "terminal" added to the package "guake"')
        self.assertEqual(output['messages'][1],
                          u'Tag "gnóme" added to the package "guake"')

        output = self.app.get('/api/v1/guake/tag/')
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output['name'], 'guake')
        self.assertEqual(output['tags'][0]['tag'], u'gnóme')
        self.assertEqual(output['tags'][0]['votes'], 1)
        self.assertEqual(output['tags'][0]['like'], 1)
        self.assertEqual(output['tags'][0]['dislike'], 0)
        self.assertEqual(output['tags'][1]['tag'], 'terminal')
        self.assertEqual(output['tags'][1]['votes'], 2)
        self.assertEqual(output['tags'][1]['like'], 2)
        self.assertEqual(output['tags'][1]['dislike'], 0)

        #This tests that invalid tags are rejected.
        data = {'pkgname': 'guake', 'tag': 'ass'}

        output = self.app.put('/api/v1/tag/guake/', data=data)
        self.assertEqual(output.status_code, 406)
        output = json.loads(output.data)
        self.assertEqual(output['output'], 'notok')
示例#27
0
 def test_user(self):
     user = tests.create_user()
     self.assertFalse(isinstance(user, Status))
     self.assertTrue(isinstance(user, User))
     self.assertFalse(isinstance(user, DirectMessage))
     self.assertEqual(user.__str__(), user.id_str)
    def unsupported_test_attachments(self):
        create_user()
        setup_journal()

        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['_user_id'] = '1'
                sess['_fresh'] = True

            # trigger refresh of journal
            rv = c.get('/refresh', follow_redirects=True)

            # upload small image
            with open("tests/data/gthnk.png", "rb") as f:
                buf = six.BytesIO(f.read())
            rv = c.post('/inbox/2012-10-03',
                        data=dict(file=(buf, 'gthnk.png'), ),
                        follow_redirects=True)

            # upload big image
            with open("tests/data/gthnk-big.jpg", "rb") as f:
                buf = six.BytesIO(f.read())
            rv = c.post('/inbox/2012-10-03',
                        data=dict(file=(buf, 'gthnk-big.jpg'), ),
                        follow_redirects=True)

            # thumbnails
            rv = c.get('/thumbnail/2012-10-03-0.jpg', follow_redirects=True)
            self.assertEqual(len(rv.data), 819,
                             "size match on small thumbnail")
            rv = c.get('/thumbnail/2012-10-03-1.jpg', follow_redirects=True)
            self.assertEqual(len(rv.data), 1640, "size match on big thumbnail")

            # previews
            rv = c.get('/preview/2012-10-03-0.jpg', follow_redirects=True)
            self.assertEqual(len(rv.data), 819, "size match on small preview")
            rv = c.get('/preview/2012-10-03-1.jpg', follow_redirects=True)
            self.assertEqual(len(rv.data), 8611, "size match on big preview")

            # attachments
            rv = c.get('/attachment/2012-10-03-0.jpg', follow_redirects=True)
            self.assertEqual(len(rv.data), 7348,
                             "size match on small attachment")
            rv = c.get('/attachment/2012-10-03-1.jpg', follow_redirects=True)
            self.assertEqual(len(rv.data), 27441,
                             "size match on big attachment")

            # download
            rv = c.get('/download/2012-10-03.pdf', follow_redirects=True)
            self.assertEqual(len(rv.data), 17097, "size match on download")

            # attachment management
            rv = c.get('/day/2012-10-03/1/move_up', follow_redirects=True)
            rv = c.get('/day/2012-10-03/0/move_down', follow_redirects=True)
            rv = c.get('/download/2012-10-03.pdf', follow_redirects=True)
            self.assertEqual(len(rv.data), 17097, "size match on download")
            # TODO: need more robust testing of PDF ordering

            from gthnk import Day

            how_many_1 = len(
                Day.query.filter_by(date='2012-10-03').first().pages)
            self.assertEqual(how_many_1, 2, "there are 2 attachments")

            rv = c.get('/day/2012-10-03/attachment/1/delete',
                       follow_redirects=True)
            how_many_2 = len(
                Day.query.filter_by(date='2012-10-03').first().pages)
            self.assertEqual(how_many_2, 1, "there is now 1 attachments")
            rv = c.get('/download/2012-10-03.pdf', follow_redirects=True)
            self.assertEqual(len(rv.data), 1596, "size match on download")

            rv = c.get('/day/2012-10-03/attachment/0/delete',
                       follow_redirects=True)
            how_many_3 = len(
                Day.query.filter_by(date='2012-10-03').first().pages)
            self.assertEqual(how_many_3, 0, "there are no attachments")
            rv = c.get('/download/2012-10-03.pdf', follow_redirects=True)
            self.assertEqual(len(rv.data), 306, "size match on download")
示例#29
0
 def setup_class(self):
     self.app, self.db = create_app()
     self.user = create_user(self.app)
示例#30
0
    def test_tag_put(self):
        """ Test the tag_pkg_put function.  """

        data = {"pkgname": "guake", "tags": "terminal"}

        output = self.app.put("/api/v1/tag/guake/", data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "notok")
        self.assertEqual(output["error"], "Invalid input submitted")
        self.assertEqual(output["error_detail"][0], "tag: This field is required.")

        data = {"pkgname": "guake", "tag": "terminal"}

        output = self.app.put("/api/v1/tag/guake", data=data)
        self.assertEqual(output.status_code, 301)

        output = self.app.put("/api/v1/tag/guake/", data=data)
        self.assertEqual(output.status_code, 404)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "notok")
        self.assertEqual(output["error"], 'Package "guake" not found')

        create_package(self.session)

        output = self.app.put("/api/v1/tag/guake/", data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "ok")
        self.assertEqual(output["messages"][0], 'Tag "terminal" added to the package "guake"')
        self.assertEqual(output["user"]["username"], "anonymous")

        output = self.app.put("/api/v1/tag/guake/", data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "notok")
        self.assertEqual(output["error"], "This tag is already associated to this package")

        data = {"pkgname": "guake", "tag": u"terminal,, gnóme"}

        create_user(self.session)
        user = model.FASUser.by_name(self.session, "pingou")
        self.infos = fedoratagger.lib.get_api_token(self.session, user)
        self.infos["token"] = "fake"

        output = self.request_with_auth("/api/v1/tag/guake/", "PUT", data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "notok")
        self.assertEqual(output["error"], "Login invalid/expired")

        self.infos = fedoratagger.lib.get_api_token(self.session, user)

        output = self.request_with_auth("/api/v1/tag/guake/", "PUT", data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "ok")
        self.assertEqual(output["messages"][0], 'Tag "terminal" added to the package "guake"')
        self.assertEqual(output["messages"][1], u'Tag "gnóme" added to the package "guake"')

        output = self.app.get("/api/v1/guake/tag/")
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output["name"], "guake")
        self.assertEqual(output["tags"][0]["tag"], u"gnóme")
        self.assertEqual(output["tags"][0]["votes"], 1)
        self.assertEqual(output["tags"][0]["like"], 1)
        self.assertEqual(output["tags"][0]["dislike"], 0)
        self.assertEqual(output["tags"][1]["tag"], "terminal")
        self.assertEqual(output["tags"][1]["votes"], 2)
        self.assertEqual(output["tags"][1]["like"], 2)
        self.assertEqual(output["tags"][1]["dislike"], 0)

        # This tests that invalid tags are rejected.
        data = {"pkgname": "guake", "tag": "ass"}

        output = self.app.put("/api/v1/tag/guake/", data=data)
        self.assertEqual(output.status_code, 406)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "notok")
示例#31
0
def normal_user(db):
    return create_user(db)
示例#32
0
def admin_user(db):
    return create_user(db, admin=True)
示例#33
0
    def test_rating_put(self):
        """ Test the rating_pkg_put function.  """

        data = {"pkgname": "guake", "ratings": 1}

        output = self.app.put("/api/v1/rating/guake/", data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "notok")
        self.assertEqual(output["error"], "Invalid input submitted")
        self.assertEqual(output["error_detail"], ["rating: This field is required."])

        data = {"pkgname": "guake", "rating": "110"}

        output = self.app.put("/api/v1/rating/guake/", data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "notok")
        self.assertEqual(output["error"], "Invalid input submitted")
        self.assertEqual(output["error_detail"], ["rating: Input is not a percentage"])

        data = {"pkgname": "guake", "rating": "-1"}

        output = self.app.put("/api/v1/rating/guake/", data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "notok")
        self.assertEqual(output["error"], "Invalid input submitted")
        self.assertEqual(output["error_detail"], ["rating: Input is not a percentage"])

        data = {"pkgname": "guake", "rating": "asd"}

        output = self.app.put("/api/v1/rating/guake/", data=data)
        self.assertEqual(output.status_code, 500)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "notok")
        self.assertEqual(output["error"], "Invalid input submitted")
        self.assertEqual(output["error_detail"], ["rating: This field is required."])

        data = {"pkgname": "guake", "rating": 100}

        output = self.app.put("/api/v1/rating/guake", data=data)
        self.assertEqual(output.status_code, 301)

        output = self.app.put("/api/v1/rating/guake/", data=data)
        self.assertEqual(output.status_code, 404)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "notok")
        self.assertEqual(output["error"], 'Package "guake" not found')

        create_package(self.session)

        output = self.app.put("/api/v1/rating/guake/", data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "ok")
        self.assertEqual(output["messages"], ['Rating "100" added to the package "guake"'])

        output = self.app.put("/api/v1/rating/guake/", data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "ok")
        self.assertEqual(output["messages"], ['Rating on package "guake" did not change'])

        data = {"pkgname": "guake", "rating": 50}
        create_user(self.session)
        user = model.FASUser.by_name(self.session, "pingou")
        self.infos = fedoratagger.lib.get_api_token(self.session, user)

        output = self.request_with_auth("/api/v1/rating/guake/", "PUT", data=data)
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output["output"], "ok")
        self.assertEqual(output["messages"], ['Rating "50" added to the package "guake"'])

        output = self.app.get("/api/v1/guake/rating/")
        self.assertEqual(output.status_code, 200)
        output = json.loads(output.data)
        self.assertEqual(output["rating"], 75.0)
        self.assertEqual(output["name"], "guake")