コード例 #1
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
 def test_non_nullable_empty_fields_invalid(self):
     some_user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
     data = getData.getModelData(self, some_user)
     data["surname"] = None
     with self.assertRaises(ValidationError):
         b = Booking(**data)
         b.full_clean()
コード例 #2
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
    def test_email_send_reservation_order_to_all_contacts(self):
        admin_user = User.objects.create_superuser("myuser", "*****@*****.**", "flobble")
        self.client.login(username=admin_user.username, password="******")
        b = Booking(**getData.getModelData(self))
        villa1 = Villa.objects.create(sleeps=9, name="Villa Fabuloso", calendar="somecalendarid")
        b.house = villa1
        manager1 = BookingContact(initial="S", surname="Aardvark", email="*****@*****.**")
        manager2 = BookingContact(initial="S", surname="Tennisball", email="*****@*****.**")
        manager1.save()
        manager2.save()

        manager1.villas.add(villa1)
        manager2.villas.add(villa1)
        b.save()

        data = {
            "csrfmiddlewaretoken": ["L7AuiXeExZJRmqdvPe4HgxlUXbpZorJp"],
            "emails": ["*****@*****.**", "*****@*****.**"],
            "id": b.id,
        }

        response = self.client.post("/bookings_sys/sendresorder/%s/" % b.id, data)
        self.assertEqual(len(mail.outbox), 1)
        # One email to 2 recipients
        self.assertEqual(mail.outbox[0].to, ["*****@*****.**", "*****@*****.**"])
コード例 #3
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
    def test_email_send_invoice(self):
        admin_user = User.objects.create_superuser("myuser", "*****@*****.**", "flobble")
        self.client.login(username=admin_user.username, password="******")
        b = Booking(**getData.getModelData(self))
        b.save()

        response = self.client.post("/bookings_sys/sendinvoice/%s/" % b.id)
        self.assertEqual(len(mail.outbox), 1)
        # Only one of the managers has been ticked in the form
        self.assertEqual(mail.outbox[0].to, [b.email])
コード例 #4
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
 def test_GET_confirm_empty_booking_form_has_correct_number_pax_forms_for_beds_in_villa(self):
     data = getData.getModelData(self, self.some_user)
     v = Villa.objects.create(name="small house", sleeps=3)
     data["house"] = v
     unconfirmed_booking = Booking(**data)
     unconfirmed_booking.save()
     url = "/bookings_sys/confirm_booking/%d/" % (unconfirmed_booking.id)
     response = self.client.get(url)
     self.assertContains(response, "id_passenger_set-2-surname")  # 3rd one is there.  zero-based
     self.assertNotContains(response, "id_passenger_set-3-surname")
コード例 #5
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
    def set_up_post_with_booking_and_all_pax(self):
        data = getData.getModelData(self, self.some_user)
        v = Villa.objects.create(name="small house", sleeps=8)
        data["house"] = v

        unconfirmed_booking = Booking(**data)
        unconfirmed_booking.save()
        booking_id = unconfirmed_booking.id

        booking_data = getData.getPOSTData(self, self.some_user)

        pass_data = self.get_all_pax_form_data(booking_id)
        booking_data.update(pass_data)
        return (booking_data, unconfirmed_booking.id)
コード例 #6
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
    def test_displays_passengers_for_that_booking_not_other_bookings(self):
        correct_booking = Booking(**getData.getModelData(self, self.some_user))
        correct_booking.save()
        Passenger.objects.create(surname="Mr A", booking=correct_booking)
        Passenger.objects.create(surname="Mr B", booking=correct_booking)

        villa = Villa.objects.create(sleeps=8, name="a villa")
        other_booking = Booking.objects.create(house=villa)
        Passenger.objects.create(surname="Mr X", booking=other_booking)
        Passenger.objects.create(surname="Mr Y", booking=other_booking)

        response = self.client.get("/bookings_sys/booking_form_report/%d/" % (correct_booking.id,))

        self.assertContains(response, "Mr A")
        self.assertContains(response, "Mr B")
        self.assertNotContains(response, "Mr X")
        self.assertNotContains(response, "Mr Y")
コード例 #7
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
    def test_GET_confirm_booking_form_with_some_number_pax_forms_for_beds_in_villa(self):
        v = Villa.objects.create(name="medium house", sleeps=8)
        data = getData.getModelData(self, self.some_user)
        data["house"] = v

        unconfirmed_booking = Booking(**data)
        unconfirmed_booking.save()

        Passenger.objects.create(
            title="Mr",
            initial="J",
            surname="pax1",
            dob=datetime.datetime.strptime("2000-01-01", "%Y-%m-%d"),
            booking=unconfirmed_booking,
        )
        Passenger.objects.create(
            title="Mr",
            initial="J",
            surname="pax2",
            dob=datetime.datetime.strptime("2000-01-01", "%Y-%m-%d"),
            booking=unconfirmed_booking,
        )
        Passenger.objects.create(
            title="Mr",
            initial="J",
            surname="pax3",
            dob=datetime.datetime.strptime("2000-01-01", "%Y-%m-%d"),
            booking=unconfirmed_booking,
        )

        response = self.client.get("/bookings_sys/confirm_booking/%d/" % (unconfirmed_booking.id))

        self.assertNotContains(response, "pax0")
        self.assertContains(response, "pax1")
        self.assertContains(response, "pax3")
        self.assertNotContains(response, "pax4")

        self.assertContains(response, "id_passenger_set-0-surname")  # zero-based
        self.assertContains(response, "id_passenger_set-7-surname")

        self.assertNotContains(response, "id_passenger_set-8-surname")
コード例 #8
0
ファイル: test.py プロジェクト: sebp999/pp-booking
	def test_confirm_booking_wrong_BOOKING (self):
		d=self.setUpBooking()
		booking=Booking(**d)
		booking.save()
		#logout
		self.browser.delete_all_cookies()

		self.browser.get(self.live_server_url+"/bookings_sys/confirm_booking/%d/" % (booking.id))

		assert ('Log in' in self.browser.title)
		self.fill_in_box('username','john')
		self.fill_in_box('password','johnpassword')
		self.browser.find_element_by_id('id_submit').click()

		assert ('Confirm' in self.browser.title)
		self.fill_in_box('title','Mr')
		self.fill_in_box('initial','S')
		self.fill_in_box('surname','')
		#NO SURNAME SET
		self.fill_in_box('add1','john')
		self.fill_in_box('add2','john')
		self.fill_in_box('town','john')
		self.fill_in_box('passenger_set-0-title','Mrs')
		self.fill_in_box('passenger_set-0-initial','F')
		self.fill_in_box('passenger_set-0-surname','Smith')
		self.fill_in_box('passenger_set-1-title','Mr')
		self.fill_in_box('passenger_set-1-initial','J')
		self.fill_in_box('passenger_set-1-surname','J')
		self.fill_in_box('passenger_set-2-title','Mr')
		self.fill_in_box('passenger_set-2-initial','J')
		self.fill_in_box('passenger_set-2-surname','Franks2')
		self.fill_in_box('passenger_set-4-title','Mr')
		self.fill_in_box('passenger_set-4-initial','J')
		self.fill_in_box('passenger_set-4-surname','Franks3')
		self.browser.find_element_by_id('id_submit').click()
		error=self.browser.find_element_by_class_name('errorlist')
		self.assertEquals(error.text,"This field is required.")
		new_url = self.browser.current_url
		self.assertRegex(new_url, '/bookings_sys/confirm_booking/')
		self.assertEquals(Passenger.objects.count(), 0)
		self.assertEquals(Booking.objects.count(), 1)
コード例 #9
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
    def test_contacts_right(self):
        admin_user = User.objects.create_superuser("myuser", "*****@*****.**", "flobble")
        self.client.login(username=admin_user.username, password="******")
        b = Booking(**getData.getModelData(self))
        villa1 = Villa.objects.create(sleeps=9, name="Villa Fabuloso", calendar="somecalendarid")
        b.house = villa1
        c1 = BookingContact(initial="S", surname="Aardvark", email="*****@*****.**")
        c2 = BookingContact(initial="S", surname="Tennisball", email="*****@*****.**")
        c1.save()
        c2.save()

        c1.villas.add(villa1)
        c2.villas.add(villa1)
        b.save()
        # print('/bookings_sys/documents/%s/' % (b.id))
        response = self.client.get("/bookings_sys/sendresorder/%s/" % (b.id))

        self.assertContains(response, "Aardvark")
        self.assertContains(response, "*****@*****.**")
        self.assertContains(response, "Tennisball")
        self.assertContains(response, "*****@*****.**")
        self.assertNotContains(response, "Irrelevant")
コード例 #10
0
ファイル: test.py プロジェクト: sebp999/pp-booking
	def test_process_booking(self):
		d=self.setUpBooking()
		booking=Booking(**d)
		booking.save()

		##I go to the confirmation page.
		# I have to be logged in
		#self.browser.delete_all_cookies()
		self.browser.get(self.live_server_url+"/bookings_sys/process_booking/%d/" % (booking.id))

		self.fill_in_box('username','admin')
		self.fill_in_box('password','superpassword')
		self.browser.find_element_by_id('id_submit').click()

		## Page title is Process Booking.

		assert 'Process Booking' in self.browser.title

		##I see the booking details, including
		# name of customer
		cont=self.browser.find_element_by_class_name('container')
		body_text=cont.text
		assert "Villa Name: Villa Fabuloso" in body_text
		assert "Holiday Dates: 01 July 2015 to 08 July 2015" in body_text
		assert "Duration: 7 nights" in body_text


		# passengers
		# Money details
		# If somebody has chosen some extras I can fill them in and update the booking
		# When happy, I can send to Xero
		self.browser.find_element_by_id('id_xero_button')
		# And send to Google Cal
		self.browser.find_element_by_id('id_update_calendar_button')
		## (but I won't click them)

		# Download invoice and reservation order as pdf for printing
		self.browser.find_element_by_id('id_reservation_order')
		invoice_button=self.browser.find_element_by_id('id_invoice')
コード例 #11
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
 def test_save_to_db(self):
     v = Villa.objects.create(name="a", sleeps=2)
     user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
     user2 = User.objects.create_user("seb", "*****@*****.**", "sebpassword")
     first_booking = Booking(house=v, authorised_user=user)
     first_booking.save()
     sec_booking = Booking(house=v, authorised_user=user2)
     sec_booking.save()
     self.assertEqual(Booking.objects.count(), 2)
コード例 #12
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
    def test_email_security_resorder(self):
        admin_user = User.objects.create_superuser("myuser", "*****@*****.**", "flobble")
        self.client.login(username=admin_user.username, password="******")
        b = Booking(**getData.getModelData(self))
        villa1 = Villa.objects.create(sleeps=9, name="Villa Fabuloso", calendar="somecalendarid")
        b.house = villa1
        c1 = BookingContact(initial="S", surname="Aardvark", email="*****@*****.**")
        c2 = BookingContact(initial="S", surname="Tennisball", email="*****@*****.**")
        c1.save()
        c2.save()

        c1.villas.add(villa1)
        c2.villas.add(villa1)
        b.save()

        # somebody is posting unrelated email addresses to us maliciously
        data = {
            "csrfmiddlewaretoken": ["L7AuiXeExZJRmqdvPe4HgxlUXbpZorJp"],
            "emails": ["*****@*****.**"],
            "id": b.id,
        }
        response = self.client.post("/bookings_sys/sendresorder/%s/" % b.id, data)
        # nothing is sent
        self.assertEqual(len(mail.outbox), 0)
コード例 #13
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
    def test_bookings_appear(self):
        admin_user = User.objects.create_superuser("myuser", "*****@*****.**", "flobble")
        self.client.login(username=admin_user.username, password="******")
        some_user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
        ## A BOOKING IN NAME PALMER
        first_booking = Booking(**getData.getModelData(self, some_user))
        first_booking.save()

        ##A BOOKING IN NAME SUMMER
        second_booking = Booking(**getData.getModelData(self, some_user))
        second_booking.surname = "summer"
        second_booking.save()

        ##GET THE LIST
        response = self.client.get("/bookings_sys/index/")

        ##ENSURE IT CONTAINS SURNAMES AND CHANGE LINKS
        self.assertContains(response, "Palmer")
        self.assertContains(response, 'a href="/bookings_sys/process_booking/%s/">Change booking' % (first_booking.id))

        self.assertContains(response, 'a href="/bookings_sys/documents/%s/">Send' % (first_booking.id))
        self.assertContains(response, "summer")
コード例 #14
0
ファイル: tests.py プロジェクト: sebp999/pp-booking
 def test_confirmation_page(self):
     b = Booking(**getData.getModelData(self))
     b.save()
     response = self.client.post("/bookings_sys/confirmation/%s/" % b.id)
     self.assertTemplateUsed(response, "showbooking.html")
     self.assertContains(response, "07947003829")
コード例 #15
0
ファイル: test.py プロジェクト: sebp999/pp-booking
	def test_confirm_booking (self):
		d=self.setUpBooking()
		booking=Booking(**d)
		booking.save()
		#logout
		self.browser.delete_all_cookies()

		self.browser.get(self.live_server_url+"/bookings_sys/confirm_booking/%d/" % (booking.id))

		assert ('Log in' in self.browser.title)
		self.fill_in_box('username','admin')
		self.fill_in_box('password','superpassword')
		self.browser.find_element_by_id('id_submit').click()

		#YOu can only fill it in if you are the right user
		assert ('Log in' in self.browser.title)
		self.fill_in_box('username','john')
		self.fill_in_box('password','johnpassword')
		self.browser.find_element_by_id('id_submit').click()

		assert ('Confirm' in self.browser.title)
		self.fill_in_box('title','Mr')
		self.fill_in_box('initial','S')
		self.fill_in_box('surname','john')
		self.fill_in_box('add1','john')
		self.fill_in_box('add2','john')
		self.fill_in_box('town','john')
		self.fill_in_box('country','')
		##NON-COMPULSORY FIELD##
		self.fill_in_box('passenger_set-0-title','Mrs')
		self.fill_in_box('passenger_set-0-initial','F')
		self.fill_in_box('passenger_set-0-surname','Smith')
		self.fill_in_box('passenger_set-0-dob','2000-06-01')
		self.fill_in_box('passenger_set-1-title','Mr')
		self.fill_in_box('passenger_set-1-initial','J')
		self.fill_in_box('passenger_set-1-surname','Franks1')
		self.fill_in_box('passenger_set-2-title','Mr')
		self.fill_in_box('passenger_set-2-initial','J')
		self.fill_in_box('passenger_set-2-surname','Franks2')
		self.fill_in_box('passenger_set-4-title','Mr')
		self.fill_in_box('passenger_set-4-initial','J')
		self.fill_in_box('passenger_set-4-surname','Franks3')
		self.browser.find_element_by_id('id_submit').click()

		new_url = self.browser.current_url
		self.assertRegex(new_url, '/bookings_sys/confirm_booking2/')

		#Don't tick the box
		self.browser.find_element_by_id('id_submit').click()

		#Should be rejected
		new_url = self.browser.current_url
		self.assertRegex(new_url, '/bookings_sys/confirm_booking2/')
		#self.assertRegex(error.text, "Please tick to indicate agreement of the booking")

		#Tick the box
		self.browser.find_element_by_id('id_agreed').click()

		#submit the form
		self.browser.find_element_by_id('id_submit').click()

		#make sure we ended up on next page
		new_url = self.browser.current_url

		self.assertRegex(new_url, '/bookings_sys/confirm_booking3/')
		self.assertEquals(Passenger.objects.count(), 4) # 0,1,2,4
		self.assertEquals(Booking.objects.count(), 1)