Exemple #1
0
 def setUp(self):
     TransactionTestCase.setUp(self)
     self.factory = ModelFactory()
Exemple #2
0
    def setUp(self):
        TransactionTestCase.setUp(self)
        ac = transaction.get_autocommit(using=None)  # flailing, debugging
        transaction.set_autocommit(False)
        ac = transaction.get_autocommit(using=None)

        sptext = None
        with open("storedprocs.sql", "r") as spf:
            sptext = spf.read()
        self.assertTrue(sptext)
        self.assertTrue(len(sptext) > 100)
        cursor = connection.cursor()
        cursor.execute(sptext)
        cursor.close()
        djuser = User.objects.create_user(
            'testuser1', '*****@*****.**', 'twisted')
        self.userp = TCUserProfile.objects.get(djuser=djuser)
        self.userp.prefs.history = 4
        self.userp.prefs.nature = 1
        self.userp.prefs.social = 2
        self.userp.prefs.save()
        djrevuser1 = User.objects.create_user(
            'testrevuser1', '*****@*****.**', 'twisted')
        self.rev1p = TCUserProfile.objects.get(djuser=djrevuser1)
        self.rev1p.prefs.history = 2
        self.rev1p.prefs.nature = 2
        self.rev1p.prefs.social = 4
        self.rev1p.prefs.save()
        djrevuser2 = User.objects.create_user(
            'testrevuser2', '*****@*****.**', 'twisted')
        self.rev2p = TCUserProfile.objects.get(djuser=djrevuser2)
        self.rev2p.prefs.history = 4
        self.rev2p.prefs.nature = 2
        self.rev2p.prefs.save()
        # populate places
        p_earth = Place(name="Earth", latitude=0, longitude=0, radiuskm=21000)
        p_earth.parent = None
        p_earth.save()
        p_asia = Place(
            name="Asia", latitude=30, longitude=97, radiuskm=7000, parent=p_earth)
        p_asia.save()
        p_sea = Place(name="Southeast Asia", latitude=10.1,
                      longitude=106.75, radiuskm=1300, parent=p_asia)
        p_sea.save()
        p_thailand = Place(name="Thailand", latitude=13.75,
                           longitude=100.4833, radiuskm=500, parent=p_sea, iscountry=True)
        p_thailand.save()
        pa = PlaceAlias(place=p_thailand, name="thaithai")
        pa.save()
        p_norththai = Place(name="Northern Thailand", latitude=18.35,
                            longitude=99.5, radiuskm=250, parent=p_thailand)
        p_norththai.save()
        p_souththai = Place(name="Southern Thailand", latitude=9.08,
                            longitude=100.28, radiuskm=250, parent=p_thailand)
        p_souththai.save()

        p = Place(name="Krabi", latitude=9.08, longitude=100.28,
                  radiuskm=10, parent=p_souththai)
        p.save()
        rat = Ratings(history=1, budget=3, nature=4, social=1,
                      relaxing=3, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(
            place=p, user=self.rev1p, ratings=rat, comment="Kinda boring")
        rev.save()
        rat = Ratings(history=1, budget=1, nature=5, social=1,
                      relaxing=1, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(place=p, user=self.rev2p, ratings=rat,
                     comment="A little stressful, just hung out here a day or so en route to Andaman side.")
        rev.save()

        p = Place(name="Chiang Rai", latitude=19.50,
                  longitude=100, radiuskm=10, parent=p_norththai)
        p.save()
        # no ratings

        p = Place(name="Chiang Mai", latitude=18.50,
                  longitude=99, radiuskm=10, parent=p_norththai)
        p.save()
        rat = Ratings(history=4, budget=3, nature=4, social=4,
                      relaxing=3, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(place=p, user=self.rev1p, ratings=rat,
                     comment="Traveler hub of northern Thailand")
        rev.save()
        rat = Ratings(history=3, budget=3, nature=3, social=3,
                      relaxing=3, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(
            place=p, user=self.rev2p, ratings=rat, comment="Massages!")
        rev.save()

        p = Place(name="Ko Tao", latitude=10.08, longitude=99.83,
                  radiuskm=6, parent=p_souththai)
        p.save()
        rat = Ratings(history=1, budget=3, nature=4, social=5,
                      relaxing=4, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(
            place=p, user=self.rev1p, ratings=rat, comment="diving and debauchery")
        rev.save()
        rat = Ratings(history=0, budget=3, nature=5, social=4,
                      relaxing=3, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(
            place=p, user=self.rev2p, ratings=rat, comment="island wonder.")
        rev.save()

        p = Place(name="Ko Pha Ngan", latitude=9.75,
                  longitude=100.0, radiuskm=6, parent=p_souththai)
        p.save()
        rat = Ratings(history=1, budget=4, nature=5, social=5,
                      relaxing=4, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(place=p, user=self.rev1p, ratings=rat,
                     comment="partying on the beach and serene hiking")
        rev.save()
        rat = Ratings(history=0, budget=5, nature=5, social=6,
                      relaxing=3, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(
            place=p, user=self.rev2p, ratings=rat, comment="everything you need.")
        rev.save()

        p = Place(name="Ko Lanta", latitude=7.6, longitude=99.07,
                  radiuskm=15, parent=p_souththai)
        p.save()
        rat = Ratings(history=2, budget=3, nature=3, social=1,
                      relaxing=4, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(
            place=p, user=self.rev1p, ratings=rat, comment="beauty and beaches")
        rev.save()
        rat = Ratings(history=3, budget=4, nature=3, social=2,
                      relaxing=5, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(
            place=p, user=self.rev2p, ratings=rat, comment="get away from it all")
        rev.save()

        p = Place(name="Ko Phi Phi", latitude=7.74,
                  longitude=98.77, radiuskm=6, parent=p_souththai)
        p.save()
        rat = Ratings(history=2, budget=3, nature=5, social=5,
                      relaxing=3, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(
            place=p, user=self.rev1p, ratings=rat, comment="beauty and beaches")
        rev.save()
        rat = Ratings(history=1, budget=2, nature=5, social=5,
                      relaxing=4, touristy=2, active=3, modern=2)
        rat.save()
        rev = Review(place=p, user=self.rev2p, ratings=rat,
                     comment="tourist paradise, and the beach from the beach")
        rev.save()
        transaction.commit()
        connection.commit()