Exemple #1
0
class PrjTest (TestCase):

    def setUp (self, peopleTest = None):

        self.client = Client ()

        self.peopleTestDep = TestCaseDep (peopleTest, people.tests.PeopleTest)
        self.peopleTestDep.setUp ()

        prj = PROJECT.objects.create (
            name       = 'P2P Banking',
            contact    = PERSON.objects.order_by ('?')[0],
          # team       = PERSON.objects.all (),
            start_date = '2000-01-01'
        )

        for p in PERSON.objects.all ():

            prj.team.add (p)

    def tearDown (self):

        self.peopleTestDep.tearDown ()

    def runTest (self, n = 128):

        ##
        ## $ python -m cProfile manage.py test prj.PrjTest.runTest
        ##

        for _ in xrange (n):

            self.test_project ()
            self.test_project_set ()

    def test_project (self, id = 1):

        rsp = self.client.get ('/project/json/PROJECT/%d/' % id)
        self.failUnlessEqual(rsp.status_code, 200)

    def test_project_set (self):

        rsp = self.client.get ('/project/json/PROJECT_SET/')
        self.failUnlessEqual(rsp.status_code, 200)
Exemple #2
0
class AuctionTest (TestCase):

    def setUp (self, peopleTest=None, prjTest=None):

        self.client = Client ()

        self.peopleTestDep = TestCaseDep (peopleTest, people.tests.PeopleTest)
        self.peopleTestDep.setUp ()

        self.prjTestDep = TestCaseDep (prjTest, prj.tests.PrjTest)
        self.prjTestDep.setUp (self.peopleTestDep)

        AUCTION.objects.create (
            project       = PROJECT.objects.order_by ('?')[0],
            start_date    = '2000-01-01',
            expiry_date   = '2000-04-01',
            target_amount = 1000000,
            target_rate   = '0.08'
        )

    def tearDown (self):

        self.prjTestDep.tearDown ()
        self.peopleTestDep.tearDown ()

    def runTest (self, n = 128):

        ##
        ## $ python -m cProfile manage.py test auction.AuctionTest.runTest
        ##

        for _ in xrange (n):

            self.test_auction ()
            self.test_auction_set ()

            self.test_bid ()
            self.test_bid_set ()

            self.test_post_bid ()

    def test_auction (self, id = 1):

        rsp = self.client.get ('/auction/json/AUCTION/%d/' % id)
        self.failUnlessEqual(rsp.status_code, 200)

    def test_auction_set (self):

        rsp = self.client.get ('/auction/json/AUCTION_SET/')
        self.failUnlessEqual(rsp.status_code, 200)

    def test_bid (self, id = 1):

        rsp = self.client.get ('/auction/json/BID/%d/' % id)
        self.failUnlessEqual(rsp.status_code, 200)

    def test_bid_set (self):

        rsp = self.client.get ('/auction/json/BID_SET/')
        self.failUnlessEqual(rsp.status_code, 200)

    def test_post_bid (self):

        user    = PERSON.objects.order_by ('?')[0]
        auction = AUCTION.objects.order_by ('?')[0]
        amount  = 25 * randint (1,10)
        rate    = random ()

        params = "?user-id=%s&auction-id=%s&amount=%s&rate=%s" % (
             user.id, auction.id, amount, '%2.f' % rate
        )

        rsp = self.client.post ('/auction/post/BID/' + params)
        self.failUnlessEqual(rsp.status_code, 200)