2012-05-07 19:09:08 +02:00
|
|
|
import StringIO
|
2012-05-07 14:27:54 +02:00
|
|
|
from BeautifulSoup import BeautifulSoup
|
|
|
|
|
|
|
|
from djeuscan.tests import SystemTestCase
|
|
|
|
from djeuscan.tests.euscan_factory import PackageFactory, HerdFactory, \
|
|
|
|
MaintainerFactory, VersionFactory, random_string
|
2012-05-05 16:09:04 +02:00
|
|
|
|
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
class PagesTest(SystemTestCase):
|
2012-05-05 16:09:04 +02:00
|
|
|
"""
|
|
|
|
Test main pages
|
|
|
|
"""
|
|
|
|
|
|
|
|
def test_index(self):
|
|
|
|
"""
|
|
|
|
Test index
|
|
|
|
"""
|
|
|
|
response = self.get("index")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-05-07 14:27:54 +02:00
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
def test_world(self):
|
|
|
|
response = self.get("world")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-05-07 14:27:54 +02:00
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
def test_about(self):
|
|
|
|
response = self.get("about")
|
2012-05-07 14:27:54 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
|
|
|
|
class SectionTests(SystemTestCase):
|
|
|
|
def _check_table(self, response, items, attr=None):
|
2012-05-07 14:27:54 +02:00
|
|
|
soup = BeautifulSoup(response.content)
|
|
|
|
rows = soup.findAll("tr")
|
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
self.assertEqual(len(rows), len(items))
|
2012-05-07 14:27:54 +02:00
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
for item in items:
|
|
|
|
if attr:
|
|
|
|
item_str = getattr(item, attr)
|
|
|
|
else:
|
|
|
|
item_str = item
|
|
|
|
self.assertTrue(item_str in response.content)
|
2012-05-07 14:27:54 +02:00
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
|
|
|
|
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 = []
|
2012-05-07 14:27:54 +02:00
|
|
|
for i in range(0, 10, 2):
|
|
|
|
p = PackageFactory.create()
|
2012-05-07 19:09:08 +02:00
|
|
|
p.herds.add(self.herds[i])
|
|
|
|
p.herds.add(self.herds[i + 1])
|
|
|
|
self.packages.append(p)
|
2012-05-07 14:27:54 +02:00
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
def test_herds(self):
|
2012-05-07 14:27:54 +02:00
|
|
|
response = self.get("herds")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
self._check_table(response, self.herds, attr="herd")
|
2012-05-07 14:27:54 +02:00
|
|
|
|
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
class MaintainersTests(SectionTests):
|
|
|
|
def setUp(self):
|
|
|
|
super(MaintainersTests, self).setUp()
|
|
|
|
self.maintainers = [MaintainerFactory.create() for _ in range(10)]
|
|
|
|
self.packages = []
|
2012-05-07 14:27:54 +02:00
|
|
|
for i in range(0, 10, 2):
|
|
|
|
p = PackageFactory.create()
|
2012-05-07 19:09:08 +02:00
|
|
|
p.maintainers.add(self.maintainers[i])
|
|
|
|
p.maintainers.add(self.maintainers[i + 1])
|
|
|
|
self.packages.append(p)
|
2012-05-07 14:27:54 +02:00
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
def test_maintainers(self):
|
2012-05-07 14:27:54 +02:00
|
|
|
response = self.get("maintainers")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
self._check_table(response, self.maintainers, attr="name")
|
2012-05-07 14:27:54 +02:00
|
|
|
|
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
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)
|
2012-05-07 14:27:54 +02:00
|
|
|
|
|
|
|
def test_overlays(self):
|
2012-05-07 19:09:08 +02:00
|
|
|
response = self.get("overlays")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-05-07 14:27:54 +02:00
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
self._check_table(response, self.overlays)
|
|
|
|
|
|
|
|
|
|
|
|
class WorldScanTests(SectionTests):
|
|
|
|
def setUp(self):
|
|
|
|
super(WorldScanTests, self).setUp()
|
2012-05-07 14:27:54 +02:00
|
|
|
for _ in range(3):
|
2012-05-07 19:09:08 +02:00
|
|
|
PackageFactory.create()
|
|
|
|
self.packages = [PackageFactory.create().name for _ in range(3)]
|
2012-05-07 14:27:54 +02:00
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
def test_world_scan_packages(self):
|
|
|
|
response = self.post("world_scan",
|
|
|
|
data={"packages": "\n".join(self.packages)})
|
2012-05-07 14:27:54 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
self._check_table(response, self.packages)
|
2012-05-07 14:27:54 +02:00
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
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
|
2012-05-07 14:27:54 +02:00
|
|
|
|
2012-05-07 19:09:08 +02:00
|
|
|
response = self.post("world_scan", data={"world": world_file})
|
2012-05-07 14:27:54 +02:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2012-05-07 19:09:08 +02:00
|
|
|
|
|
|
|
self._check_table(response, self.packages)
|