Exemplo n.º 1
0
    def testFilteredHouse(self):
        user = User.objects.get(username='******')

        title, address, description1 = "PisoTest", "Bami", "Piso muy guay"
        create_flat(title, address, description1, '', user)
        flatSaved = Flat.objects.get(title=title)
        flatSavedProps = FlatProperties.objects.create(flat=flatSaved,
                                                       elevator=True,
                                                       washdisher=True)

        description2, price, belong_to = "buena habitacion", 150, flatSaved
        roomSaved = Room.objects.create(description=description2,
                                        price=price,
                                        picture='',
                                        temporal_owner=None,
                                        belong_to=belong_to)
        roomSavedProps = RoomProperties.objects.create(room=roomSaved,
                                                       balcony=True,
                                                       window=True,
                                                       air_conditioner=True)

        flats = get_flats_filtered("PisoTest", True, True, True, True, True)

        for flat in flats:

            self.assertEqual(flat, flatSaved)
            self.assertEqual(FlatProperties.objects.get(flat=flat),
                             flatSavedProps)
            roomToCheckList = Room.objects.filter(belong_to=flat)
            roomToCheck = roomToCheckList[0]
            self.assertEqual(roomToCheck, roomSaved)
            self.assertEqual(RoomProperties.objects.get(room=roomToCheck),
                             roomSavedProps)
Exemplo n.º 2
0
    def testShowPayments(self):
        user1 = User.objects.get(username='******')
        user2 = User.objects.get(username='******')
        text = 'An example agreement'
        data = localtime(now()).date()

        title, address, description = 'Piso', 'Bami', 'Piso luminoso'
        create_flat(title, address, description, '', user1)
        flat_saved = Flat.objects.get(title=title)

        description, price = 'Bien', '500.5'
        create_room(description, price, '', user1, flat_saved)
        room_saved = Room.objects.get(description=description)

        create_contract(text, data, user1, user2, room_saved.id)
        contract_saved = Contract.objects.get(room=room_saved)

        amount = 300.0
        data1 = localtime(now()).date()

        create_payment(amount, data1, contract_saved.id)
        payment_saved = Payment.objects.get(contract=contract_saved)

        self.assertEqual(payment_saved.amount, amount)
        self.assertEqual(payment_saved.date, data1)
        self.assertEqual(payment_saved.contract, contract_saved)
Exemplo n.º 3
0
    def testShowFlatsPositive(self):
        user = User.objects.get(username='******')

        title, address, description = 'Piso', 'Calle betis', 'pisito en calle betis'

        create_flat(title, address, description, '', user)
        flat_saved = Flat.objects.get(title=title)

        flats2 = Flat.objects.all()

        self.assertTrue(flat_saved in flats2)
Exemplo n.º 4
0
    def testCreateFlatNegativeDescription(self):
        exception = False
        user = User.objects.get(username='******')

        try:
            title, description, address, owner = 'Titulo', '', 'Calle pal pozo', user

            create_flat(title, description, address, owner)
        except:
            exception = True

        self.assertEqual(exception, True)
Exemplo n.º 5
0
    def testRegisterReviewFlatNegativeTitle(self):
        user = User.objects.get(username='******')
        title, address, description = 'Piso', 'Bami', 'Piso luminoso'

        create_flat(title, address, description, '', user)
        flat_saved = Flat.objects.get(title=title)

        title, description, date, rating, flat = '', 'Bien', localtime(
            now()).date(), '3', flat_saved
        flatReview_saved = create_flatreview(title, description, date, rating,
                                             flat)
        self.assertIsNone(flatReview_saved)
Exemplo n.º 6
0
    def testCreateFlat(self):
        user = User.objects.get(username='******')
        profile = Profile.objects.get(user=user)

        title, address, description = 'Piso', 'Bami', 'Piso luminoso'

        create_flat(title, address, description, '', user)
        flat_saved = Flat.objects.get(title=title)

        self.assertEqual(flat_saved.title, title)
        self.assertEqual(flat_saved.address, address)
        self.assertEqual(flat_saved.description, description)
        self.assertEqual(flat_saved.owner, profile)
Exemplo n.º 7
0
    def testDeleteFlatPositive(self):
        user = User.objects.get(username='******')

        title, address, description = 'Piso', 'Calle betis', 'piso calle'

        create_flat(title, address, description, '', user)
        flat_saved = Flat.objects.get(title=title)

        delete_flat(flat_saved.id)

        flat_alls = Flat.objects.all()

        self.assertTrue(flat_saved not in flat_alls)
Exemplo n.º 8
0
    def testShowRoomsPositive(self):
        user = User.objects.get(username='******')
        title, address, description = 'Piso', 'Bami', 'Piso luminoso'

        create_flat(title, address, description, '', user)
        flat_saved = Flat.objects.get(title=title)

        description, price = 'Bien', '500.5'
        create_room(description, price, '', user, flat_saved)
        room_saved = Room.objects.get(description=description)

        rooms2 = Room.objects.all().filter(belong_to=flat_saved)

        self.assertTrue(room_saved in rooms2)
Exemplo n.º 9
0
    def testRegisterReviewRoomNegativeTitle(self):

        user = User.objects.get(username='******')
        title, address, description = 'Piso', 'Bami', 'Piso luminoso'

        create_flat(title, address, description, '', user)
        flat_saved = Flat.objects.get(title=title)

        description, price = 'Bien', '500.5'
        create_room(description, price, '', user, flat_saved)
        room_saved = Room.objects.get(description=description)

        title, description, date, rating, room = '', 'Bien', localtime(
            now()).date(), '3', room_saved

        roomReview_saved = create_roomreview(title, description, date, rating,
                                             room)
        self.assertIsNone(roomReview_saved)
Exemplo n.º 10
0
    def testRegisterReviewFlatNegativeRating(self):
        exception = False

        user = User.objects.get(username='******')
        title, address, description = 'Piso', 'Bami', 'Piso luminoso'

        create_flat(title, address, description, '', user)
        flat_saved = Flat.objects.get(title=title)

        try:
            title, description, date, rating, flat = 'Titulo', 'Bien', localtime(
                now()).date(), '-3', flat_saved

            create_flatreview(title, description, date, rating, flat)
        except:
            exception = True

        self.assertEqual(exception, True)
Exemplo n.º 11
0
    def testRegisterReviewFlatPositive(self):
        user = User.objects.get(username='******')
        title, address, description = 'Piso', 'Bami', 'Piso luminoso'

        create_flat(title, address, description, '', user)
        flat_saved = Flat.objects.get(title=title)

        title, description, date, rating, flat = 'Bien', 'Bien', localtime(
            now()).date(), '2', flat_saved

        create_flatreview(title, description, date, rating, flat)
        review_saved = FlatReview.objects.get(title=title)

        self.assertEqual(review_saved.title, title)
        self.assertEqual(review_saved.description, description)
        self.assertEqual(review_saved.date, date)
        self.assertEqual(review_saved.rating, rating)
        self.assertEqual(review_saved.flat, flat_saved)
Exemplo n.º 12
0
    def testRegisterReviewFlatNegativeTitleLong(self):
        exception = False

        user = User.objects.get(username='******')
        title, address, description = 'Piso', 'Bami', 'Piso luminoso'

        create_flat(title, address, description, '', user)
        flat_saved = Flat.objects.get(title=title)

        try:
            title, description, date, rating, flat = \
                'El titulo es demasiado largo porque supera los 50 caracteres maximos', 'Bien', \
                localtime(now()).date(), '3', flat_saved

            create_flatreview(title, description, date, rating, flat)
        except:
            exception = True

        self.assertEqual(exception, True)
Exemplo n.º 13
0
    def testRegisterReviewRoomNegativeTitleLong(self):
        exception = False

        user = User.objects.get(username='******')
        title, address, description = 'Piso', 'Bami', 'Piso luminoso'

        create_flat(title, address, description, '', user)
        flat_saved = Flat.objects.get(title=title)

        description, price = 'Bien', '500.5'
        create_room(description, price, '', user, flat_saved)
        room_saved = Room.objects.get(description=description)

        try:
            title, description, date, rating, room = 'El titulo es demasiado largo porque supera los 50 caracteres maximos', 'Bien', localtime(
                now()).date(), '3', room_saved

            create_roomreview(title, description, date, rating, room)
        except:
            exception = True

        self.assertEqual(exception, True)
Exemplo n.º 14
0
    def testRegisterReviewRoomPositive(self):
        user = User.objects.get(username='******')
        title, address, description = 'Piso', 'Bami', 'Piso luminoso'

        create_flat(title, address, description, '', user)
        flat_saved = Flat.objects.get(title=title)

        description, price = 'Bien', '500.5'
        create_room(description, price, '', user, flat_saved)
        room_saved = Room.objects.get(description=description)

        title, description, date, rating, room = 'Bien', 'Bien', localtime(
            now()).date(), '2', room_saved

        create_roomreview(title, description, date, rating, room)
        review_saved = RoomReview.objects.get(description=description)

        self.assertEqual(review_saved.title, title)
        self.assertEqual(review_saved.description, description)
        self.assertEqual(review_saved.date, date)
        self.assertEqual(review_saved.rating, rating)
        self.assertEqual(review_saved.room, room_saved)
Exemplo n.º 15
0
def flatCreate(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = FlatForm(request.POST, request.FILES)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            flat = create_flat(
                form_title=form.cleaned_data.get("title"),
                form_address=form.cleaned_data.get("address"),
                form_description=form.cleaned_data.get("description"),
                form_picture=form.cleaned_data['picture'],
                user=request.user)

            return HttpResponseRedirect('/flats/' + str(flat.id))

    # if a GET (or any other method) we'll create a blank form
    else:
        form = FlatForm()

    return render(request, 'flat/create.html', {'form': form})