tests refactoring and some fixes
This commit is contained in:
parent
9a39328e3b
commit
d3676250ab
@ -143,13 +143,19 @@ def pie_packages(**kwargs):
|
||||
|
||||
|
||||
def rrd_path(name):
|
||||
return str(os.path.join(settings.RRD_ROOT, name + '.rrd'))
|
||||
res = str(os.path.join(settings.RRD_ROOT, name))
|
||||
if res.endswith(".rrd"):
|
||||
return res
|
||||
else:
|
||||
return res + ".rrd"
|
||||
|
||||
|
||||
def rrd_create(name, start):
|
||||
def rrd_create(name, start=None):
|
||||
if start is None:
|
||||
start = int(time.time())
|
||||
|
||||
path = rrd_path(name)
|
||||
if os.path.exists(path):
|
||||
return
|
||||
if not os.path.exists(path):
|
||||
rrdtool.create(path, '--step', '86400',
|
||||
'--start', '%s' % int(start - 10),
|
||||
'DS:n_packages_gentoo:GAUGE:4294967295:0:U',
|
||||
@ -178,7 +184,8 @@ def rrd_update(name, datetime, values):
|
||||
"""
|
||||
[-s|--start time] [-e|--end time] [-S|--step seconds]
|
||||
[-t|--title string] [-v|--vertical-label string]
|
||||
[-w|--width pixels] [-h|--height pixels] [-j|--only-graph] [-D|--full-size-mode][-u|--upper-limit value] [-l|--lower-limit value]
|
||||
[-w|--width pixels] [-h|--height pixels] [-j|--only-graph]
|
||||
[-D|--full-size-mode][-u|--upper-limit value] [-l|--lower-limit value]
|
||||
[-u|--upper-limit value] [-l|--lower-limit value] [-r|--rigid]
|
||||
[-A|--alt-autoscale]
|
||||
[-M|--alt-autoscale-max]
|
||||
@ -198,7 +205,10 @@ def cached_rrd_chart(f):
|
||||
kwds['title'] = '%s (%s)' % (f.func_name, kwds['period'])
|
||||
kwds['steps'] = kwds['period']
|
||||
kwds['vertical-label'] = f.func_name
|
||||
|
||||
kwds['rrd'] = rrd_path(rrd_name(**kwds))
|
||||
rrd_create(kwds['rrd']) # create the rrd file if it's not present
|
||||
|
||||
kwds['path'] = path
|
||||
|
||||
kwds['end'] = 'now'
|
||||
@ -229,8 +239,11 @@ def cached_rrd_chart(f):
|
||||
|
||||
@cached_rrd_chart
|
||||
def packages(**kwargs):
|
||||
path = str(kwargs['path'])
|
||||
rrd = kwargs['rrd']
|
||||
|
||||
rrdtool.graph(
|
||||
str(kwargs['path']),
|
||||
path,
|
||||
'--imgformat', 'PNG',
|
||||
'--width', kwargs['width'],
|
||||
'--height', kwargs['height'],
|
||||
@ -243,11 +256,9 @@ def packages(**kwargs):
|
||||
'--vertical-label', kwargs['vertical-label'],
|
||||
'--title', kwargs['title'],
|
||||
'--lower-limit', '0',
|
||||
'DEF:n_packages_gentoo=%s:n_packages_gentoo:AVERAGE' % (kwargs['rrd']),
|
||||
'DEF:n_packages_overlay=%s:n_packages_overlay:AVERAGE' % \
|
||||
(kwargs['rrd']),
|
||||
'DEF:n_packages_outdated=%s:n_packages_outdated:AVERAGE' % \
|
||||
(kwargs['rrd']),
|
||||
'DEF:n_packages_gentoo=%s:n_packages_gentoo:AVERAGE' % rrd,
|
||||
'DEF:n_packages_overlay=%s:n_packages_overlay:AVERAGE' % rrd,
|
||||
'DEF:n_packages_outdated=%s:n_packages_outdated:AVERAGE' % rrd,
|
||||
'LINE1.25:n_packages_gentoo#008000:Gentoo',
|
||||
'LINE1.25:n_packages_overlay#0B17FD:Overlay',
|
||||
'LINE1.25:n_packages_outdated#FF0000:Outdated'
|
||||
@ -256,8 +267,11 @@ def packages(**kwargs):
|
||||
|
||||
@cached_rrd_chart
|
||||
def versions(**kwargs):
|
||||
path = str(kwargs['path'])
|
||||
rrd = kwargs['rrd']
|
||||
|
||||
rrdtool.graph(
|
||||
str(kwargs['path']),
|
||||
path,
|
||||
'--imgformat', 'PNG',
|
||||
'--width', kwargs['width'],
|
||||
'--height', kwargs['height'],
|
||||
@ -269,11 +283,9 @@ def versions(**kwargs):
|
||||
'--vertical-label', kwargs['vertical-label'],
|
||||
'--title', kwargs['title'],
|
||||
'--lower-limit', '0',
|
||||
'DEF:n_versions_gentoo=%s:n_versions_gentoo:AVERAGE' % (kwargs['rrd']),
|
||||
'DEF:n_versions_overlay=%s:n_versions_overlay:AVERAGE' % \
|
||||
(kwargs['rrd']),
|
||||
'DEF:n_versions_outdated=%s:n_versions_upstream:AVERAGE' % \
|
||||
(kwargs['rrd']),
|
||||
'DEF:n_versions_gentoo=%s:n_versions_gentoo:AVERAGE' % rrd,
|
||||
'DEF:n_versions_overlay=%s:n_versions_overlay:AVERAGE' % rrd,
|
||||
'DEF:n_versions_outdated=%s:n_versions_upstream:AVERAGE' % rrd,
|
||||
'LINE1.25:n_versions_gentoo#008000:Gentoo',
|
||||
'LINE1.25:n_versions_overlay#0B17FD:Overlay',
|
||||
'LINE1.25:n_versions_outdated#FF0000:Outdated'
|
||||
|
@ -114,7 +114,7 @@ class PackageManager(models.Manager, PackageMixin):
|
||||
|
||||
class VersionLogMixin(object):
|
||||
def for_package(self, package, order=False):
|
||||
res = filter(package=package)
|
||||
res = self.filter(package=package)
|
||||
if order:
|
||||
res = res.order_by('-id')
|
||||
return res
|
||||
|
@ -8,74 +8,95 @@ class ChartTests(SystemTestCase):
|
||||
Test charts
|
||||
"""
|
||||
|
||||
url = "chart"
|
||||
args = []
|
||||
kwargs = {}
|
||||
|
||||
def test_statistics(self):
|
||||
response = self.get("statistics")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_pie_versions(self):
|
||||
response = self.get("chart", chart="pie-versions")
|
||||
response = self.get(self.url, chart="pie-versions",
|
||||
*self.args, **self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_pie_packages(self):
|
||||
response = self.get("chart", chart="pie-packages")
|
||||
response = self.get(self.url, chart="pie-packages", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_packages(self):
|
||||
response = self.get("chart", chart="packages")
|
||||
response = self.get(self.url, chart="packages", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_packages_options(self):
|
||||
response = self.get("chart", chart="packages-small")
|
||||
response = self.get(self.url, chart="packages-small", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.get("chart", chart="packages-weekly")
|
||||
response = self.get(self.url, chart="packages-weekly", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.get("chart", chart="packages-monthly")
|
||||
response = self.get(self.url, chart="packages-monthly", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.get("chart", chart="packages-yearly")
|
||||
response = self.get(self.url, chart="packages-yearly", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_packages_option_incorrect(self):
|
||||
response = self.get("chart", chart="packages-trololol")
|
||||
response = self.get(self.url, chart="packages-trololol", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_versions(self):
|
||||
response = self.get("chart", chart="versions")
|
||||
response = self.get(self.url, chart="versions", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_versions_options(self):
|
||||
response = self.get("chart", chart="versions-small")
|
||||
response = self.get(self.url, chart="versions-small", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.get("chart", chart="versions-weekly")
|
||||
response = self.get(self.url, chart="versions-weekly", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.get("chart", chart="versions-monthly")
|
||||
response = self.get(self.url, chart="versions-monthly", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.get("chart", chart="versions-yearly")
|
||||
response = self.get(self.url, chart="versions-yearly", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_versions_option_incorrect(self):
|
||||
response = self.get("chart", chart="versions-trololol")
|
||||
response = self.get(self.url, chart="versions-trololol", *self.args,
|
||||
**self.kwargs)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_herd(self):
|
||||
a_herd = HerdFactory.create()
|
||||
response = self.get("chart_herd", chart="pie-packages",
|
||||
herd=a_herd.herd)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_maintainer(self):
|
||||
a_maintainer = MaintainerFactory.create()
|
||||
response = self.get("chart_maintainer", chart="pie-packages",
|
||||
maintainer_id=a_maintainer.pk)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
class CategoryChartTests(ChartTests):
|
||||
def setUp(self):
|
||||
super(CategoryChartTests, self).setUp()
|
||||
self.url = "chart_category"
|
||||
self.kwargs = {"category": PackageFactory.create().category}
|
||||
|
||||
def test_category(self):
|
||||
a_category = PackageFactory.create().category
|
||||
response = self.get("chart_category", chart="pie-packages",
|
||||
category=a_category)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
class HerdChartTests(ChartTests):
|
||||
def setUp(self):
|
||||
super(HerdChartTests, self).setUp()
|
||||
self.url = "chart_herd"
|
||||
self.kwargs = {"herd": HerdFactory.create().herd}
|
||||
|
||||
|
||||
class MaintainerChartTests(ChartTests):
|
||||
def setUp(self):
|
||||
super(MaintainerChartTests, self).setUp()
|
||||
self.url = "chart_maintainer"
|
||||
self.kwargs = {"maintainer_id": MaintainerFactory.create().id}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import StringIO
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
|
||||
from djeuscan.tests import SystemTestCase
|
||||
@ -5,7 +6,7 @@ from djeuscan.tests.euscan_factory import PackageFactory, HerdFactory, \
|
||||
MaintainerFactory, VersionFactory, random_string
|
||||
|
||||
|
||||
class NavigationTest(SystemTestCase):
|
||||
class PagesTest(SystemTestCase):
|
||||
"""
|
||||
Test main pages
|
||||
"""
|
||||
@ -17,80 +18,119 @@ class NavigationTest(SystemTestCase):
|
||||
response = self.get("index")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_categories(self):
|
||||
categories = [PackageFactory.create().category
|
||||
for _ in range(10)]
|
||||
|
||||
response = self.get("categories")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
soup = BeautifulSoup(response.content)
|
||||
rows = soup.findAll("tr")
|
||||
|
||||
self.assertEqual(len(rows), len(categories))
|
||||
|
||||
for category in categories:
|
||||
self.assertTrue(category in response.content)
|
||||
|
||||
def test_herds(self):
|
||||
herds = [HerdFactory.create() for _ in range(10)]
|
||||
packages = []
|
||||
for i in range(0, 10, 2):
|
||||
p = PackageFactory.create()
|
||||
p.herds.add(herds[i])
|
||||
p.herds.add(herds[i + 1])
|
||||
packages.append(p)
|
||||
|
||||
response = self.get("herds")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
soup = BeautifulSoup(response.content)
|
||||
rows = soup.findAll("tr")
|
||||
|
||||
self.assertEqual(len(rows), len(herds))
|
||||
|
||||
for herd in herds:
|
||||
self.assertTrue(herd.herd in response.content)
|
||||
|
||||
def test_maintainers(self):
|
||||
maintainers = [MaintainerFactory.create() for _ in range(10)]
|
||||
packages = []
|
||||
for i in range(0, 10, 2):
|
||||
p = PackageFactory.create()
|
||||
p.maintainers.add(maintainers[i])
|
||||
p.maintainers.add(maintainers[i + 1])
|
||||
packages.append(p)
|
||||
|
||||
response = self.get("maintainers")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
soup = BeautifulSoup(response.content)
|
||||
rows = soup.findAll("tr")
|
||||
|
||||
self.assertEqual(len(rows), len(maintainers))
|
||||
|
||||
for maintainer in maintainers:
|
||||
self.assertTrue(maintainer.name in response.content)
|
||||
|
||||
def test_overlays(self):
|
||||
overlays = [random_string() for _ in range(3)]
|
||||
|
||||
for _ in range(3):
|
||||
package = PackageFactory.create()
|
||||
for overlay in overlays:
|
||||
VersionFactory.create(package=package, overlay=overlay)
|
||||
|
||||
response = self.get("overlays")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
soup = BeautifulSoup(response.content)
|
||||
rows = soup.findAll("tr")
|
||||
|
||||
self.assertEqual(len(rows), len(overlays))
|
||||
|
||||
for overlay in overlays:
|
||||
self.assertTrue(overlay in response.content)
|
||||
|
||||
def test_world(self):
|
||||
response = self.get("world")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_about(self):
|
||||
response = self.get("about")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
class SectionTests(SystemTestCase):
|
||||
def _check_table(self, response, items, attr=None):
|
||||
soup = BeautifulSoup(response.content)
|
||||
rows = soup.findAll("tr")
|
||||
|
||||
self.assertEqual(len(rows), len(items))
|
||||
|
||||
for item in items:
|
||||
if attr:
|
||||
item_str = getattr(item, attr)
|
||||
else:
|
||||
item_str = item
|
||||
self.assertTrue(item_str in response.content)
|
||||
|
||||
|
||||
class CategoriesTests(SectionTests):
|
||||
def setUp(self):
|
||||
super(CategoriesTests, self).setUp()
|
||||
self.categories = [PackageFactory.create().category
|
||||
for _ in range(10)]
|
||||
|
||||
def test_categories(self):
|
||||
response = self.get("categories")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
self._check_table(response, self.categories)
|
||||
|
||||
|
||||
class HerdsTests(SectionTests):
|
||||
def setUp(self):
|
||||
super(HerdsTests, self).setUp()
|
||||
self.herds = [HerdFactory.create() for _ in range(10)]
|
||||
self.packages = []
|
||||
for i in range(0, 10, 2):
|
||||
p = PackageFactory.create()
|
||||
p.herds.add(self.herds[i])
|
||||
p.herds.add(self.herds[i + 1])
|
||||
self.packages.append(p)
|
||||
|
||||
def test_herds(self):
|
||||
response = self.get("herds")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
self._check_table(response, self.herds, attr="herd")
|
||||
|
||||
|
||||
class MaintainersTests(SectionTests):
|
||||
def setUp(self):
|
||||
super(MaintainersTests, self).setUp()
|
||||
self.maintainers = [MaintainerFactory.create() for _ in range(10)]
|
||||
self.packages = []
|
||||
for i in range(0, 10, 2):
|
||||
p = PackageFactory.create()
|
||||
p.maintainers.add(self.maintainers[i])
|
||||
p.maintainers.add(self.maintainers[i + 1])
|
||||
self.packages.append(p)
|
||||
|
||||
def test_maintainers(self):
|
||||
response = self.get("maintainers")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
self._check_table(response, self.maintainers, attr="name")
|
||||
|
||||
|
||||
class OverlayTests(SectionTests):
|
||||
def setUp(self):
|
||||
super(OverlayTests, self).setUp()
|
||||
self.overlays = [random_string() for _ in range(3)]
|
||||
|
||||
for _ in range(3):
|
||||
self.package = PackageFactory.create()
|
||||
for overlay in self.overlays:
|
||||
VersionFactory.create(package=self.package,
|
||||
overlay=overlay)
|
||||
|
||||
def test_overlays(self):
|
||||
response = self.get("overlays")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
self._check_table(response, self.overlays)
|
||||
|
||||
|
||||
class WorldScanTests(SectionTests):
|
||||
def setUp(self):
|
||||
super(WorldScanTests, self).setUp()
|
||||
for _ in range(3):
|
||||
PackageFactory.create()
|
||||
self.packages = [PackageFactory.create().name for _ in range(3)]
|
||||
|
||||
def test_world_scan_packages(self):
|
||||
response = self.post("world_scan",
|
||||
data={"packages": "\n".join(self.packages)})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
self._check_table(response, self.packages)
|
||||
|
||||
def test_world_scan_world(self):
|
||||
world_file = StringIO.StringIO()
|
||||
world_file.write("\n".join(self.packages))
|
||||
world_file.name = "world"
|
||||
world_file.read = world_file.getvalue
|
||||
|
||||
response = self.post("world_scan", data={"world": world_file})
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
self._check_table(response, self.packages)
|
||||
|
@ -59,7 +59,7 @@ def herds(request):
|
||||
@render_to('euscan/herd.html')
|
||||
def herd(request, herd):
|
||||
herd = get_object_or_404(Herd, herd=herd)
|
||||
packages = Package.for_herd(herd, last_versions=True)
|
||||
packages = Package.objects.for_herd(herd, last_versions=True)
|
||||
return {'herd': herd, 'packages': packages}
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ EUSCAN_ROOT = os.path.join(dirname(dirname(abspath(__file__))), "euscanwww")
|
||||
|
||||
settings.configure(
|
||||
DATABASES={
|
||||
'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory;'}
|
||||
'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}
|
||||
},
|
||||
INSTALLED_APPS=['euscanwww.euscanwww', 'djeuscan'],
|
||||
ROOT_URLCONF='euscanwww.euscanwww.urls',
|
||||
|
Loading…
Reference in New Issue
Block a user