def test_score(self): """ Test the scores """ output = self.app.get('/api/v1/score/pingou/') self.assertEqual(output.status_code, 404) output = json.loads(output.data) self.assertEqual(output.keys(), ['output', 'error']) self.assertEqual(output['output'], 'notok') self.assertEqual(output['error'], 'User not found') create_package(self.session) create_tag(self.session) output = self.app.get('/api/v1/score/pingou/') self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output.keys(), ['score', 'gravatar', 'name']) self.assertEqual(output['name'], 'pingou') self.assertEqual(output['score'], 8) output = self.app.get('/api/v1/score/toshio/') self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output.keys(), ['score', 'gravatar', 'name']) self.assertEqual(output['name'], 'toshio') self.assertEqual(output['score'], 2)
def test_statistics(self): """ Test the statistics method. """ out = fedoratagger.lib.statistics(self.session) self.assertEqual(['summary'], out.keys()) self.assertEqual(0, out['summary']['with_tags']) self.assertEqual(0, out['summary']['no_tags']) self.assertEqual(0, out['summary']['tags_per_package']) self.assertEqual(0, out['summary']['tags_per_package_no_zeroes']) self.assertEqual(0, out['summary']['total_packages']) self.assertEqual(0, out['summary']['total_unique_tags']) create_package(self.session) out = fedoratagger.lib.statistics(self.session) self.assertEqual(['summary'], out.keys()) self.assertEqual(0, out['summary']['with_tags']) self.assertEqual(3, out['summary']['no_tags']) self.assertEqual(0, out['summary']['tags_per_package']) self.assertEqual(0, out['summary']['tags_per_package_no_zeroes']) self.assertEqual(3, out['summary']['total_packages']) self.assertEqual(0, out['summary']['total_unique_tags']) create_tag(self.session) out = fedoratagger.lib.statistics(self.session) self.assertEqual(['summary'], out.keys()) self.assertEqual(2, out['summary']['with_tags']) self.assertEqual(1, out['summary']['no_tags']) self.assertEqual(4 / float(3), out['summary']['tags_per_package']) self.assertEqual(2, out['summary']['tags_per_package_no_zeroes']) self.assertEqual(3, out['summary']['total_packages']) self.assertEqual(3, out['summary']['total_unique_tags'])
def test_tag_sqlite(self): """ Test tag_pkg_sqlite. A url for bodhi's masher. """ create_package(self.session) create_tag(self.session) output = self.app.get('/api/v1/tag/sqlitebuildtags/') self.assertEqual(output.status_code, 200) fd, db_filename = tempfile.mkstemp() os.close(fd) with open(db_filename, 'w') as f: f.write(output.data) with sqlite3.connect(db_filename) as conn: cursor = conn.cursor(); cursor.execute("select * from packagetags;") rows = cursor.fetchall() target_rows = [ (u'guake', u'gnóme', 2), (u'guake', u'terminal', 2), (u'geany', u'gnóme', 2), (u'geany', u'ide', 2), ] self.assertEqual(len(rows), len(target_rows)) for actual, target in zip(rows, target_rows): self.assertEqual(actual, target)
def test_pkg_get_tag(self): """ Test the pkg_get_tag function. """ output = self.app.get('/api/v1/guake/tag') self.assertEqual(output.status_code, 301) output = self.app.get('/api/v1/guake/tag/') 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.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'], []) create_tag(self.session) 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'], 2) self.assertEqual(output['tags'][0]['like'], 2) self.assertEqual(output['tags'][0]['dislike'], 0) self.assertEqual(output['tags'][1]['tag'], 'terminal') self.assertEqual(output['tags'][0]['votes'], 2) self.assertEqual(output['tags'][0]['like'], 2) self.assertEqual(output['tags'][0]['dislike'], 0)
def test_statistics(self): """ Test the statistics method. """ out = fedoratagger.lib.statistics(self.session) self.assertEqual(['summary'], out.keys()) self.assertEqual(0, out['summary']['with_tags']) self.assertEqual(0, out['summary']['no_tags']) self.assertEqual(0, out['summary']['tags_per_package']) self.assertEqual(0, out['summary']['tags_per_package_no_zeroes']) self.assertEqual(0, out['summary']['total_packages']) self.assertEqual(0, out['summary']['total_unique_tags']) create_package(self.session) out = fedoratagger.lib.statistics(self.session) self.assertEqual(['summary'], out.keys()) self.assertEqual(0, out['summary']['with_tags']) self.assertEqual(3, out['summary']['no_tags']) self.assertEqual(0, out['summary']['tags_per_package']) self.assertEqual(0, out['summary']['tags_per_package_no_zeroes']) self.assertEqual(3, out['summary']['total_packages']) self.assertEqual(0, out['summary']['total_unique_tags']) create_tag(self.session) out = fedoratagger.lib.statistics(self.session) self.assertEqual(['summary'], out.keys()) self.assertEqual(2, out['summary']['with_tags']) self.assertEqual(1, out['summary']['no_tags']) self.assertEqual(4/float(3), out['summary']['tags_per_package']) self.assertEqual(2, out['summary']['tags_per_package_no_zeroes']) self.assertEqual(3, out['summary']['total_packages']) self.assertEqual(3, out['summary']['total_unique_tags'])
def test_score(self): """ Test the scores """ output = self.app.get("/api/v1/score/pingou/") self.assertEqual(output.status_code, 404) output = json.loads(output.data) self.assertEqual(output.keys(), ["output", "error"]) self.assertEqual(output["output"], "notok") self.assertEqual(output["error"], "User not found") create_package(self.session) create_tag(self.session) output = self.app.get("/api/v1/score/pingou/") self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output.keys(), ["score", "gravatar", "name"]) self.assertEqual(output["name"], "pingou") self.assertEqual(output["score"], 8) output = self.app.get("/api/v1/score/toshio/") self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output.keys(), ["score", "gravatar", "name"]) self.assertEqual(output["name"], "toshio") self.assertEqual(output["score"], 2)
def test_pkg_get_tag(self): """ Test the pkg_get_tag function. """ output = self.app.get("/api/v1/guake/tag") self.assertEqual(output.status_code, 301) output = self.app.get("/api/v1/guake/tag/") 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.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"], []) create_tag(self.session) 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"], 2) self.assertEqual(output["tags"][0]["like"], 2) self.assertEqual(output["tags"][0]["dislike"], 0) self.assertEqual(output["tags"][1]["tag"], "terminal") self.assertEqual(output["tags"][0]["votes"], 2) self.assertEqual(output["tags"][0]["like"], 2) self.assertEqual(output["tags"][0]["dislike"], 0)
def test_tag_sqlite(self): """ Test tag_pkg_sqlite. A url for bodhi's masher. """ create_package(self.session) create_tag(self.session) output = self.app.get('/api/v1/tag/sqlitebuildtags/') self.assertEqual(output.status_code, 200) fd, db_filename = tempfile.mkstemp() os.close(fd) with open(db_filename, 'w') as f: f.write(output.data) with sqlite3.connect(db_filename) as conn: cursor = conn.cursor() cursor.execute("select * from packagetags;") rows = cursor.fetchall() target_rows = [ (u'guake', u'gnóme', 2), (u'guake', u'terminal', 2), (u'geany', u'gnóme', 2), (u'geany', u'ide', 2), ] self.assertEqual(len(rows), len(target_rows)) for actual, target in zip(rows, target_rows): self.assertEqual(actual, target)
def test_tag_dump(self): """ Test tag_pkg_dump """ output = self.app.get("/api/v1/tag/dump/") self.assertEqual(output.status_code, 200) self.assertEqual(output.data, "") create_package(self.session) create_tag(self.session) output = self.app.get("/api/v1/tag/dump/") self.assertEqual(output.status_code, 200) self.assertEqual( output.data.decode("utf-8"), u"guake\tgnóme\n" u"guake\tterminal\n" u"geany\tgnóme\ngeany\tide" )
def test_tag_dump(self): """ Test tag_pkg_dump """ output = self.app.get('/api/v1/tag/dump/') self.assertEqual(output.status_code, 200) self.assertEqual(output.data, '') create_package(self.session) create_tag(self.session) output = self.app.get('/api/v1/tag/dump/') self.assertEqual(output.status_code, 200) self.assertEqual(output.data.decode('utf-8'), u'guake\tgnóme\n' u'guake\tterminal\n' u'geany\tgnóme\ngeany\tide')
def test_leaderboard(self): """ Test the leaderboard method. """ out = fedoratagger.lib.leaderboard(self.session) self.assertEqual([], out.keys()) create_package(self.session) create_tag(self.session) out = fedoratagger.lib.leaderboard(self.session) self.assertEqual(out.keys(), [1, 2, 3, 4, 5, 6]) self.assertEqual(out[1].keys(), ['score', 'gravatar', 'name']) self.assertEqual(out[1]['name'], 'pingou') self.assertEqual(out[1]['score'], 8) self.assertEqual(out[2]['name'], 'toshio') self.assertEqual(out[2]['score'], 2)
def test_tag_dump(self): """ Test tag_pkg_dump """ output = self.app.get('/api/v1/tag/dump/') self.assertEqual(output.status_code, 200) self.assertEqual(output.data, '') create_package(self.session) create_tag(self.session) output = self.app.get('/api/v1/tag/dump/') self.assertEqual(output.status_code, 200) self.assertEqual( output.data.decode('utf-8'), u'guake\tgnóme\n' u'guake\tterminal\n' u'geany\tgnóme\ngeany\tide')
def test_score(self): """ Test the score method. """ self.assertRaises(NoResultFound, fedoratagger.lib.score, self.session, 'asd') create_package(self.session) create_tag(self.session) out = fedoratagger.lib.score(self.session, 'pingou') self.assertEqual(out.keys(), ['score', 'gravatar', 'name']) self.assertEqual(out['name'], 'pingou') self.assertEqual(out['score'], 8) out = fedoratagger.lib.score(self.session, 'toshio') self.assertEqual(out.keys(), ['score', 'gravatar', 'name']) self.assertEqual(out['name'], 'toshio') self.assertEqual(out['score'], 2)
def test_leaderboard(self): """ Test leaderboard """ output = self.app.get('/api/v1/leaderboard/') self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output.keys(), []) create_package(self.session) create_tag(self.session) output = self.app.get('/api/v1/leaderboard/') self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output.keys(), ['1', '3', '2', '5', '4', '6']) self.assertEqual(output['1'].keys(), ['score', 'gravatar', 'name']) self.assertEqual(output['1']['name'], 'pingou') self.assertEqual(output['1']['score'], 8) self.assertEqual(output['2']['name'], 'toshio') self.assertEqual(output['2']['score'], 2) self.assertEqual(output['5']['name'], 'ralph')
def test_leaderboard(self): """ Test leaderboard """ output = self.app.get("/api/v1/leaderboard/") self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output.keys(), []) create_package(self.session) create_tag(self.session) output = self.app.get("/api/v1/leaderboard/") self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output.keys(), ["1", "3", "2", "5", "4", "6"]) self.assertEqual(output["1"].keys(), ["score", "gravatar", "name"]) self.assertEqual(output["1"]["name"], "pingou") self.assertEqual(output["1"]["score"], 8) self.assertEqual(output["2"]["name"], "toshio") self.assertEqual(output["2"]["score"], 2) self.assertEqual(output["5"]["name"], "ralph")
def test_score(self): """ Test the score method. """ self.assertRaises(NoResultFound, fedoratagger.lib.score, self.session, 'asd' ) create_package(self.session) create_tag(self.session) out = fedoratagger.lib.score(self.session, 'pingou') self.assertEqual(out.keys(), ['score', 'gravatar', 'name']) self.assertEqual(out['name'], 'pingou') self.assertEqual(out['score'], 8) out = fedoratagger.lib.score(self.session, 'toshio') self.assertEqual(out.keys(), ['score', 'gravatar', 'name']) self.assertEqual(out['name'], 'toshio') self.assertEqual(out['score'], 2)
def test_tag_get(self): """ Test the tag_get function. """ output = self.app.get(u'/api/v1/tag/gnóme') self.assertEqual(output.status_code, 301) output = self.app.get(u'/api/v1/tag/gnóme/') self.assertEqual(output.status_code, 404) output = json.loads(output.data) self.assertEqual(output['output'], 'notok') self.assertEqual(output['error'], u'Tag "gnóme" not found') create_package(self.session) create_tag(self.session) output = self.app.get(u'/api/v1/tag/gnóme/') self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output['tag'], u'gnóme') self.assertEqual(len(output['packages']), 2) self.assertEqual(output['packages'][0]['package'], 'guake')
def test_tag_get(self): """ Test the tag_get function. """ output = self.app.get(u"/api/v1/tag/gnóme") self.assertEqual(output.status_code, 301) output = self.app.get(u"/api/v1/tag/gnóme/") self.assertEqual(output.status_code, 404) output = json.loads(output.data) self.assertEqual(output["output"], "notok") self.assertEqual(output["error"], u'Tag "gnóme" not found') create_package(self.session) create_tag(self.session) output = self.app.get(u"/api/v1/tag/gnóme/") self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output["tag"], u"gnóme") self.assertEqual(len(output["packages"]), 2) self.assertEqual(output["packages"][0]["package"], "guake")
def test_tag_export(self): """ Test tag_pkg_export. A backwards compat url for fedora-packages' cronjob. """ output = self.app.get('/api/v1/tag/export/') self.assertEqual(output.status_code, 200) target = {'packages': []} self.assertEqual(json.loads(output.data), target) create_package(self.session) create_tag(self.session) output = self.app.get('/api/v1/tag/export/') self.assertEqual(output.status_code, 200) target = { u'packages': [ { u'guake': [{ u'tag': u'gnóme', u'total': 2, }, { u'tag': u'terminal', u'total': 2, }] }, { u'geany': [{ u'tag': u'gnóme', u'total': 2, }, { u'tag': u'ide', u'total': 2, }] }, { u'gitg': [], } ] } self.assertEqual(json.loads(output.data), target)
def test_statistics(self): """ Test statistics """ output = self.app.get('/api/v1/statistics/') self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output.keys(), ['summary']) self.assertEqual(0, output['summary']['with_tags']) self.assertEqual(0, output['summary']['no_tags']) self.assertEqual(0, output['summary']['tags_per_package']) self.assertEqual(0, output['summary']['tags_per_package_no_zeroes']) self.assertEqual(0, output['summary']['total_packages']) self.assertEqual(0, output['summary']['total_unique_tags']) create_package(self.session) output = self.app.get('/api/v1/statistics/') self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(['summary'], output.keys()) self.assertEqual(0, output['summary']['with_tags']) self.assertEqual(3, output['summary']['no_tags']) self.assertEqual(0, output['summary']['tags_per_package']) self.assertEqual(0, output['summary']['tags_per_package_no_zeroes']) self.assertEqual(3, output['summary']['total_packages']) self.assertEqual(0, output['summary']['total_unique_tags']) create_tag(self.session) output = self.app.get('/api/v1/statistics/') self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(['summary'], output.keys()) self.assertEqual(2, output['summary']['with_tags']) self.assertEqual(1, output['summary']['no_tags']) self.assertEqual(4 / float(3), output['summary']['tags_per_package']) self.assertEqual(2, output['summary']['tags_per_package_no_zeroes']) self.assertEqual(3, output['summary']['total_packages']) self.assertEqual(3, output['summary']['total_unique_tags'])
def test_statistics(self): """ Test statistics """ output = self.app.get("/api/v1/statistics/") self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output.keys(), ["summary"]) self.assertEqual(0, output["summary"]["with_tags"]) self.assertEqual(0, output["summary"]["no_tags"]) self.assertEqual(0, output["summary"]["tags_per_package"]) self.assertEqual(0, output["summary"]["tags_per_package_no_zeroes"]) self.assertEqual(0, output["summary"]["total_packages"]) self.assertEqual(0, output["summary"]["total_unique_tags"]) create_package(self.session) output = self.app.get("/api/v1/statistics/") self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(["summary"], output.keys()) self.assertEqual(0, output["summary"]["with_tags"]) self.assertEqual(3, output["summary"]["no_tags"]) self.assertEqual(0, output["summary"]["tags_per_package"]) self.assertEqual(0, output["summary"]["tags_per_package_no_zeroes"]) self.assertEqual(3, output["summary"]["total_packages"]) self.assertEqual(0, output["summary"]["total_unique_tags"]) create_tag(self.session) output = self.app.get("/api/v1/statistics/") self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(["summary"], output.keys()) self.assertEqual(2, output["summary"]["with_tags"]) self.assertEqual(1, output["summary"]["no_tags"]) self.assertEqual(4 / float(3), output["summary"]["tags_per_package"]) self.assertEqual(2, output["summary"]["tags_per_package_no_zeroes"]) self.assertEqual(3, output["summary"]["total_packages"]) self.assertEqual(3, output["summary"]["total_unique_tags"])
def test_statistics(self): """ Test statistics """ output = self.app.get('/api/v1/statistics/') self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output.keys(), ['summary']) self.assertEqual(0, output['summary']['with_tags']) self.assertEqual(0, output['summary']['no_tags']) self.assertEqual(0, output['summary']['tags_per_package']) self.assertEqual(0, output['summary']['tags_per_package_no_zeroes']) self.assertEqual(0, output['summary']['total_packages']) self.assertEqual(0, output['summary']['total_unique_tags']) create_package(self.session) output = self.app.get('/api/v1/statistics/') self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(['summary'], output.keys()) self.assertEqual(0, output['summary']['with_tags']) self.assertEqual(3, output['summary']['no_tags']) self.assertEqual(0, output['summary']['tags_per_package']) self.assertEqual(0, output['summary']['tags_per_package_no_zeroes']) self.assertEqual(3, output['summary']['total_packages']) self.assertEqual(0, output['summary']['total_unique_tags']) create_tag(self.session) output = self.app.get('/api/v1/statistics/') self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(['summary'], output.keys()) self.assertEqual(2, output['summary']['with_tags']) self.assertEqual(1, output['summary']['no_tags']) self.assertEqual(4/float(3), output['summary']['tags_per_package']) self.assertEqual(2, output['summary']['tags_per_package_no_zeroes']) self.assertEqual(3, output['summary']['total_packages']) self.assertEqual(3, output['summary']['total_unique_tags'])
def test_tag_export(self): """ Test tag_pkg_export. A backwards compat url for fedora-packages' cronjob. """ output = self.app.get("/api/v1/tag/export/") self.assertEqual(output.status_code, 200) target = {"packages": []} self.assertEqual(json.loads(output.data), target) create_package(self.session) create_tag(self.session) output = self.app.get("/api/v1/tag/export/") self.assertEqual(output.status_code, 200) target = { u"packages": [ {u"guake": [{u"tag": u"gnóme", u"total": 2}, {u"tag": u"terminal", u"total": 2}]}, {u"geany": [{u"tag": u"gnóme", u"total": 2}, {u"tag": u"ide", u"total": 2}]}, {u"gitg": []}, ] } self.assertEqual(json.loads(output.data), target)
def test_tag_export(self): """ Test tag_pkg_export. A backwards compat url for fedora-packages' cronjob. """ output = self.app.get('/api/v1/tag/export/') self.assertEqual(output.status_code, 200) target = {'packages': []} self.assertEqual(json.loads(output.data), target) create_package(self.session) create_tag(self.session) output = self.app.get('/api/v1/tag/export/') self.assertEqual(output.status_code, 200) target = { u'packages': [{ u'guake': [{ u'tag': u'gnóme', u'total': 2, }, { u'tag': u'terminal', u'total': 2, }] }, { u'geany': [{ u'tag': u'gnóme', u'total': 2, }, { u'tag': u'ide', u'total': 2, }] }, { u'gitg': [], }] } self.assertEqual(json.loads(output.data), target)
def test_vote_put(self): """ Test the vote_tag_pkg_put function. """ ### Test with wrong input data = {'pkgname': 'guake', 'tags': 'terminal', 'vote': '1'} output = self.app.put('/api/v1/vote/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'], ["tag: This field is required."]) data = {'pkgname': 'guake', 'tag': 'terminal', 'vote': '110'} output = self.app.put('/api/v1/vote/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'], ['vote: Input must be either -1 (dislike) ' 'or 1 (like)']) data = {'pkgname': 'guake', 'tag': 'terminal', 'vote': 'as'} output = self.app.put('/api/v1/vote/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'], ["vote: This field is required."]) ### Test with right input format but non-existing package data = {'pkgname': 'guake', 'tag': 'terminal', 'vote': '-1'} output = self.app.put('/api/v1/vote/guake', data=data) self.assertEqual(output.status_code, 301) output = self.app.put('/api/v1/vote/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 could not be found ' 'associated to this package') create_package(self.session) create_tag(self.session) output = self.app.put('/api/v1/vote/guake/', data=data) self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output['output'], 'ok') self.assertEqual(output['messages'], ['Vote added on the tag "terminal"' ' of the package "guake"']) output = self.app.put('/api/v1/vote/guake/', data=data) self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output['output'], 'ok') self.assertEqual(output['messages'], ['Your vote on the tag ' '"terminal" for the package' ' "guake" did not change']) data = {'pkgname': 'guake', 'tag': 'terminal', 'vote': '1'} output = self.app.put('/api/v1/vote/guake/', data=data) self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output['output'], 'ok') self.assertEqual(output['messages'], ['Vote changed on the tag ' '"terminal" of 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'], 2) self.assertEqual(output['tags'][0]['like'], 2) self.assertEqual(output['tags'][0]['dislike'], 0) self.assertEqual(output['tags'][1]['tag'], 'terminal') self.assertEqual(output['tags'][1]['votes'], 3) self.assertEqual(output['tags'][1]['like'], 3) self.assertEqual(output['tags'][1]['dislike'], 0)
def test_vote_put(self): """ Test the vote_tag_pkg_put function. """ ### Test with wrong input data = {"pkgname": "guake", "tags": "terminal", "vote": "1"} output = self.app.put("/api/v1/vote/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"], ["tag: This field is required."]) data = {"pkgname": "guake", "tag": "terminal", "vote": "110"} output = self.app.put("/api/v1/vote/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"], ["vote: Input must be either -1 (dislike) " "or 1 (like)"]) data = {"pkgname": "guake", "tag": "terminal", "vote": "as"} output = self.app.put("/api/v1/vote/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"], ["vote: This field is required."]) ### Test with right input format but non-existing package data = {"pkgname": "guake", "tag": "terminal", "vote": "-1"} output = self.app.put("/api/v1/vote/guake", data=data) self.assertEqual(output.status_code, 301) output = self.app.put("/api/v1/vote/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 could not be found " "associated to this package") create_package(self.session) create_tag(self.session) output = self.app.put("/api/v1/vote/guake/", data=data) self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output["output"], "ok") self.assertEqual(output["messages"], ['Vote added on the tag "terminal"' ' of the package "guake"']) output = self.app.put("/api/v1/vote/guake/", data=data) self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output["output"], "ok") self.assertEqual( output["messages"], ["Your vote on the tag " '"terminal" for the package' ' "guake" did not change'] ) data = {"pkgname": "guake", "tag": "terminal", "vote": "1"} output = self.app.put("/api/v1/vote/guake/", data=data) self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output["output"], "ok") self.assertEqual(output["messages"], ["Vote changed on the tag " '"terminal" of 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"], 2) self.assertEqual(output["tags"][0]["like"], 2) self.assertEqual(output["tags"][0]["dislike"], 0) self.assertEqual(output["tags"][1]["tag"], "terminal") self.assertEqual(output["tags"][1]["votes"], 3) self.assertEqual(output["tags"][1]["like"], 3) self.assertEqual(output["tags"][1]["dislike"], 0)
def test_vote_put(self): """ Test the vote_tag_pkg_put function. """ ### Test with wrong input data = {'pkgname': 'guake', 'tags': 'terminal', 'vote': '1'} output = self.app.put('/api/v1/vote/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'], ["tag: This field is required."]) data = {'pkgname': 'guake', 'tag': 'terminal', 'vote': '110'} output = self.app.put('/api/v1/vote/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'], ['vote: Input must be either -1 (dislike) ' 'or 1 (like)']) data = {'pkgname': 'guake', 'tag': 'terminal', 'vote': 'as'} output = self.app.put('/api/v1/vote/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'], ["vote: This field is required."]) ### Test with right input format but non-existing package data = {'pkgname': 'guake', 'tag': 'terminal', 'vote': '-1'} output = self.app.put('/api/v1/vote/guake', data=data) self.assertEqual(output.status_code, 301) output = self.app.put('/api/v1/vote/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 could not be found ' 'associated to this package') create_package(self.session) create_tag(self.session) output = self.app.put('/api/v1/vote/guake/', data=data) self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output['output'], 'ok') self.assertEqual( output['messages'], ['Vote added on the tag "terminal"' ' of the package "guake"']) output = self.app.put('/api/v1/vote/guake/', data=data) self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output['output'], 'ok') self.assertEqual(output['messages'], [ 'Your vote on the tag ' '"terminal" for the package' ' "guake" did not change' ]) data = {'pkgname': 'guake', 'tag': 'terminal', 'vote': '1'} output = self.app.put('/api/v1/vote/guake/', data=data) self.assertEqual(output.status_code, 200) output = json.loads(output.data) self.assertEqual(output['output'], 'ok') self.assertEqual(output['messages'], [ 'Vote changed on the tag ' '"terminal" of 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'], 2) self.assertEqual(output['tags'][0]['like'], 2) self.assertEqual(output['tags'][0]['dislike'], 0) self.assertEqual(output['tags'][1]['tag'], 'terminal') self.assertEqual(output['tags'][1]['votes'], 3) self.assertEqual(output['tags'][1]['like'], 3) self.assertEqual(output['tags'][1]['dislike'], 0)