Exemple #1
0
    def test_rating_dump(self):
        """ Test rating_pkg_dump """
        output = self.app.get('/api/v1/rating/dump/')
        self.assertEqual(output.status_code, 200)
        self.assertEqual(output.data, '')

        create_package(self.session)
        create_rating(self.session)
        set_usages(self.session, usage=True)

        output = self.app.get('/api/v1/rating/dump/')
        self.assertEqual(output.status_code, 200)
        expected = 'guake\t75.0\t2\t2\ngeany\t100.0\t1\t1\ngitg\t-1.0\t0\t1'
        self.assertEqual(output.data, expected)
    def test_rating_dump(self):
        """ Test rating_pkg_dump """
        output = self.app.get('/api/v1/rating/dump/')
        self.assertEqual(output.status_code, 200)
        self.assertEqual(output.data, '')

        create_package(self.session)
        create_rating(self.session)
        set_usages(self.session, usage=True)

        output = self.app.get('/api/v1/rating/dump/')
        self.assertEqual(output.status_code, 200)
        expected = 'guake\t75.0\t2\t2\ngeany\t100.0\t1\t1\ngitg\t-1.0\t0\t1'
        self.assertEqual(output.data, expected)
Exemple #3
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_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')