summaryrefslogtreecommitdiffstats
path: root/main/tests.py
blob: 543a0c1331b5e7f70ecb601395e3cbc377231160 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
## test cases
from django.test import TestCase
from main.models import Package, PackageDepend
from django.contrib.auth.models import User

class ModelTest(TestCase):
    fixtures = ['arches.json', 'repos.json', 'test_packages.json']

    def setUp(self):
        self.user = User(id=1,username='tester',first_name='test', 
                         last_name='user', password='testuser',
                         is_active=True, is_staff=True)
        self.user.save()
        self.orphan = User(id=0,first_name='Orphans')
        pass

    def testPackageGetDepends(self):
        """
        Test the Package object's get_depends() method
        """
        p = Package.objects.get(pkgname='abs',arch__name__iexact='i686')
        dep1 = {'dep': PackageDepend.objects.get(id=1),
                'pkg': Package.objects.get(id=7)}
        dep2 = {'dep': PackageDepend.objects.get(id=2), 'pkg': None}
        expected = [dep1, dep2]
        results = p.get_depends()
        self.failUnlessEqual(results, expected)
        del p
    
    def testPackageGetRequiredBy(self):
        """
        Test the Package object's get_requiredby() method
        """
        p = Package.objects.get(pkgname='iproute',arch__name__iexact='i686')
        expected = [Package.objects.get(id=123),Package.objects.get(id=163)]
        results = p.get_requiredby()
        self.failUnlessEqual(results, expected)
        del p

    def testGetFlagStats(self):
        """
        Test the PackageManager get_flag_stats method
        """
        results = Package.objects.get_flag_stats()
        expected = [(self.orphan, 0L, 0L),(self.user, 346L, 0L)]
        self.failUnlessEqual(results, expected)
        del results