Unverified Commit e4de4d3b authored by Jelle van der Waa's avatar Jelle van der Waa 🚧 Committed by GitHub
Browse files

Merge pull request #138 from jelly/tests_extended

Tests extended
parents 9fbbdf98 eeb07d7b
from mock import patch
from django.core.management import call_command
from django.test import TransactionTestCase
class RepoReadTest(TransactionTestCase):
fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json']
def test_rematch_developers(self):
with patch('devel.management.commands.rematch_developers.logger') as logger:
call_command('rematch_developers')
logger.info.assert_called()
......@@ -60,15 +60,6 @@ def empty_response():
return empty
def format_http_headers(request):
headers = sorted((k, v) for k, v in request.META.items()
if k.startswith('HTTP_'))
data = []
for k, v in headers:
data.extend([k[5:].replace('_', '-').title(), ': ', v, '\n'])
return ''.join(data)
# utility to make a pair of django choices
make_choice = lambda l: [(str(m), str(m)) for m in l]
......
......@@ -64,3 +64,7 @@ def test_mirrorlist_filter(self):
self.assertNotIn(self.mirror_url.hostname, response.content)
jp_mirror_url.delete()
def test_mirrorlist_status(self):
response = self.client.get('/mirrorlist/?country=all&use_mirror_status=on')
self.assertEqual(response.status_code, 200)
......@@ -62,7 +62,6 @@ class PackageSearchJson(TestCase):
fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json',
'main/fixtures/package.json']
def test_invalid(self):
response = self.client.get('/packages/search/json/')
self.assertEqual(response.status_code, 200)
......@@ -163,6 +162,16 @@ def test_filter_packager_unknown(self):
self.assertEqual(response.status_code, 200)
self.assertIn('5 matching packages found', response.content)
def test_sort(self):
response = self.client.get('/packages/?sort=pkgname')
self.assertEqual(response.status_code, 200)
self.assertIn('5 matching packages found', response.content)
def test_head(self):
response = self.client.head('/packages/?q=unknown')
self.assertEqual(response.status_code, 200)
class OpenSearch(TestCase):
fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json',
'main/fixtures/package.json']
......@@ -225,11 +234,19 @@ def test_packages_download(self):
self.assertEqual(response.status_code, 404)
# TODO: Figure out how to fake a mirror
def test_head(self):
response = self.client.head('/packages/core/x86_64/linux/')
self.assertEqual(response.status_code, 200)
def test_groups(self):
response = self.client.get('/groups/')
self.assertEqual(response.status_code, 200)
def test_groups_detail(self):
def test_groups_arch(self):
response = self.client.get('/groups/x86_64/')
self.assertEqual(response.status_code, 200)
def test_groups_details(self):
response = self.client.get('/groups/x86_64/base/')
self.assertEqual(response.status_code, 404)
# FIXME: add group fixtures.
......
from collections import defaultdict
from itertools import chain
from operator import attrgetter, itemgetter
from operator import itemgetter
import re
from django.core.serializers.json import DjangoJSONEncoder
......@@ -119,59 +119,6 @@ def __hash__(self):
return hash(self.__key())
def get_differences_info(arch_a, arch_b):
# This is a monster. Join packages against itself, looking for packages in
# our non-'any' architectures only, and not having a corresponding package
# entry in the other table (or having one with a different pkgver). We will
# then go and fetch all of these packages from the database and display
# them later using normal ORM models.
sql = """
SELECT p.id, q.id
FROM packages p
LEFT JOIN packages q
ON (
p.pkgname = q.pkgname
AND p.repo_id = q.repo_id
AND p.arch_id != q.arch_id
AND p.id != q.id
)
WHERE p.arch_id IN (%s, %s)
AND (
q.id IS NULL
OR p.pkgver != q.pkgver
OR p.pkgrel != q.pkgrel
OR p.epoch != q.epoch
)
"""
cursor = connection.cursor()
cursor.execute(sql, [arch_a.id, arch_b.id])
results = cursor.fetchall()
# column A will always have a value, column B might be NULL
to_fetch = {row[0] for row in results}
# fetch all of the necessary packages
pkgs = Package.objects.normal().in_bulk(to_fetch)
# now build a set containing differences
differences = set()
for row in results:
pkg_a = pkgs.get(row[0])
pkg_b = pkgs.get(row[1])
# We want arch_a to always appear first
# pkg_a should never be None
if pkg_a.arch == arch_a:
item = Difference(pkg_a.pkgname, pkg_a.repo, pkg_a, pkg_b)
else:
# pkg_b can be None in this case, so be careful
name = pkg_a.pkgname if pkg_a else pkg_b.pkgname
repo = pkg_a.repo if pkg_a else pkg_b.repo
item = Difference(name, repo, pkg_b, pkg_a)
differences.add(item)
# now sort our list by repository, package name
key_func = attrgetter('repo.name', 'pkgname')
differences = sorted(differences, key=key_func)
return differences
def multilib_differences():
# Query for checking multilib out of date-ness
if database_vendor(Package) == 'sqlite':
......
......@@ -11,14 +11,13 @@
from django.views.decorators.cache import cache_control
from django.views.decorators.http import require_safe, require_POST
from main.models import Package, Arch
from main.models import Package
from ..models import PackageRelation
from ..utils import (get_differences_info,
multilib_differences, get_wrong_permissions)
from ..utils import multilib_differences, get_wrong_permissions
# make other views available from this same package
from .display import (details, groups, group_details, files, details_json,
files_json, download)
files_json, download)
from .flag import flaghelp, flag, flag_confirmed, unflag, unflag_all
from .search import search_json
from .signoff import signoffs, signoff_package, signoff_options, signoffs_json
......
......@@ -2,7 +2,7 @@
from django.test import TestCase
from todolists.models import Todolist
from todolists.models import Todolist, TodolistPackage
class TestTodolist(TestCase):
......@@ -33,3 +33,71 @@ def test_todolist_json(self):
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertEqual(data['name'], self.todolist.name)
class TestTodolistAdmin(TestCase):
fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json',
'main/fixtures/package.json']
def setUp(self):
password = 'test'
self.user = User.objects.create_superuser("admin",
"admin@archlinux.org",
password)
self.client.post('/login/', {
'username': self.user.username,
'password': password
})
def tearDown(self):
Todolist.objects.all().delete()
self.user.delete()
def create_todo(self):
return self.client.post('/todo/add/', {
'name': 'Foo rebuild',
'description': 'The Foo Rebuild, please read the instructions',
'raw': 'linux',
})
def test_create_todolist(self):
response = self.create_todo()
self.assertEqual(response.status_code, 302)
self.assertEqual(len(Todolist.objects.all()), 1)
def test_flag_pkg(self):
response = self.create_todo()
self.assertEqual(response.status_code, 302)
todolist = Todolist.objects.first()
package = todolist.packages().first()
self.assertEqual(package.status, TodolistPackage.INCOMPLETE)
response = self.client.get('/todo/{}/flag/{}/'.format(todolist.slug, package.id))
self.assertEqual(response.status_code, 302)
package = todolist.packages().first()
self.assertEqual(package.status, TodolistPackage.COMPLETE)
def test_edit(self):
response = self.create_todo()
self.assertEqual(response.status_code, 302)
todolist = Todolist.objects.first()
self.assertEqual(len(todolist.packages().all()), 1)
response = self.client.post('/todo/{}/edit/'.format(todolist.slug), {
'name': 'Foo rebuild',
'description': 'The Foo Rebuild, please read the instructions',
'raw': 'linux\nglibc',
})
self.assertEqual(response.status_code, 302)
todolist = Todolist.objects.first()
self.assertEqual(len(todolist.packages().all()), 2)
def test_delete(self):
response = self.create_todo()
self.assertEqual(response.status_code, 302)
todolist = Todolist.objects.first()
response = self.client.post('/todo/{}/delete'.format(todolist.slug))
self.assertEqual(response.status_code, 301)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment