# Copyright (C) 2015  The Debsources developers <info@sources.debian.net>.
# See the AUTHORS file at the top-level directory of this distribution and at
# https://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=AUTHORS;hb=HEAD
#
# This file is part of Debsources. Debsources is free software: you can
# redistribute it and/or modify it under the terms of the GNU Affero General
# Public License as published by the Free Software Foundation, either version 3
# of the License, or (at your option) any later version.  For more information
# see the COPYING file at the top-level directory of this distribution and at
# https://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=COPYING;hb=HEAD

from __future__ import absolute_import

import json
import unittest

from nose.plugins.attrib import attr

from debsources.tests.test_webapp import DebsourcesBaseWebTests


@attr('patches')
class CopyrightTestCase(DebsourcesBaseWebTests, unittest.TestCase):

    def test_api_ping(self):
        rv = json.loads(self.app.get('/patches/api/ping/').data)
        self.assertEqual(rv["status"], "ok")
        self.assertEqual(rv["http_status_code"], 200)

    def test_api_packages_list(self):
        rv = json.loads(
            self.app.get('/patches/api/list/').data)
        self.assertIn({'name': "ocaml-curses"}, rv['packages'])
        self.assertEqual(len(rv['packages']), 18)

    def test_api_by_prefix(self):
        rv = json.loads(
            self.app.get('/patches/api/prefix/o/').data)
        self.assertIn({'name': "ocaml-curses"}, rv['packages'])
        # suite specified
        rv = json.loads(
            self.app.get('/patches/api/prefix/o/?suite=wheezy').data)
        self.assertIn({'name': "ocaml-curses"}, rv['packages'])
        # a non-existing suite specified
        rv = json.loads(self.app.get(
            '/patches/api/prefix/libc/?suite=non-existing').data)
        self.assertEqual([], rv['packages'])
        # special suite name "all" is specified
        rv = json.loads(
            self.app.get('/patches/api/prefix/libc/?suite=all').data)
        self.assertIn({'name': "libcaca"}, rv['packages'])

    def test_by_prefix(self):
        rv = self.app.get('/patches/prefix/libc/')
        self.assertIn("/summary/libcaca", rv.data)
        # suite specified
        rv = self.app.get('/patches/prefix/libc/?suite=squeeze')
        self.assertIn("/summary/libcaca", rv.data)
        # a non-existing suite specified
        rv = self.app.get(
            '/patches/prefix/libc/?suite=non-existing')
        self.assertNotIn("/summary/libcaca", rv.data)
        # special suite name "all" is specified
        rv = self.app.get(
            '/patches/prefix/libc/?suite=all')
        self.assertIn("/summary/libcaca", rv.data)

    def test_latest(self):
        rv = self.app.get('/patches/summary/gnubg/latest/',
                          follow_redirects=True)
        self.assertIn("Package: gnubg / 1.02.000-2", rv.data)


if __name__ == '__main__':
    unittest.main(exit=False)

@@ -2966,16 +2966,797 @@
 .data)%0A%0A
+    def test_package_summary(self):%0A        rv = self.app.get('/patches/summary/beignet/1.0.0-1/')%0A        self.assertIn(%22Enhance debug output%22, rv.data)%0A        self.assertIn(%22utests/builtin_acos_asin.cpp  %7C    8 +++++---%22, rv.data)%0A%0A        # test non quilt package%0A        rv = self.app.get('/patches/summary/cvsnt/2.5.03.2382-3/')%0A        self.assertIn(%22The format of the patches in the package%22, rv.data)%0A%0A    def test_view_patch(self):%0A        rv = self.app.get('/patches/patch/beignet/1.0.0-1/'%0A                          'Enable-test-debug.patch/')%0A        self.assertIn('%3Ccode id=%22sourcecode%22 class=%22diff%22%3E', rv.data)%0A        # highlight inside?%0A        self.assertIn('hljs.highlightBlock', rv.data)%0A        self.assertIn('highlight/highlight.min.js%22%3E%3C/script%3E', rv.data)%0A%0A
 %0Aif __na

Add tests for package summary and patch view