def test_schema(fake): address = Address(point=Point(1, 2), neighborhood="Some neighborhood", street=fake.street_address(), city=fake.city(), state=fake.state(), zip=fake.zipcode(), creator_user_id="some id", last_updated_user_id="some id", owner_name=fake.first_name(), owner_email=fake.safe_email(), tenant_name=fake.name(), tenant_email=fake.safe_email(), follow_up_owner_needed=True, land_bank_property=True, type_of_property=1) address.save() address.refresh_from_db() tag = Tag( address=address, creator_user_id="some id", last_updated_user_id="some id", date_taken=timezone.now(), description=fake.text(), ) tag.save() tag.refresh_from_db() data = TagSerializer(tag).data TAG_SCHEMA.validate(dict(data))
def test_post_request_creates_tag(client, fake): address = Address(point=Point(1, 2), neighborhood="Some neighborhood", street=fake.street_address(), city=fake.city(), state=fake.state(), zip=fake.zipcode(), creator_user_id="some id", last_updated_user_id="some id", owner_name=fake.first_name(), owner_email=fake.safe_email(), tenant_name=fake.name(), tenant_email=fake.safe_email(), follow_up_owner_needed=True, land_bank_property=True, type_of_property=1) address.save() address.refresh_from_db() data = { "address": address.id, "creator_user_id": "some id", "last_updated_user_id": "some id", "description": fake.text(), "date_taken": timezone.now().strftime("%Y-%m-%d %H:%M:%S"), } response = client.post(reverse("tag-list"), json.dumps(data), content_type="application/json") assert response.status_code == status.HTTP_201_CREATED, response.content assert Tag.objects.filter(description=data["description"]).exists() is True
def test_schema(fake): address = Address( point=Point(1, 2), neighborhood="Some neighborhood", street=fake.street_address(), city=fake.city(), state=fake.state(), zip=fake.zipcode(), creator_user_id="some id", last_updated_user_id="some id", owner_name=fake.first_name(), owner_email=fake.safe_email(), tenant_name=fake.name(), tenant_email=fake.safe_email(), follow_up_owner_needed=True, land_bank_property=True, type_of_property=1 ) address.save() data = AddressSerializer(address).data ADDRESS_SCHEMA.validate(dict(data))
def test_longitude_returns_x(fake): address = Address(point=Point(1, 2), neighborhood="Some neighborhood", street=fake.street_address(), city=fake.city(), state=fake.state(), zip=fake.zipcode(), creator_user_id="some id", last_updated_user_id="some id", owner_name=fake.first_name(), owner_email=fake.safe_email(), tenant_name=fake.name(), tenant_email=fake.safe_email(), follow_up_owner_needed=True, land_bank_property=True, type_of_property=1) assert address.longitude == 1
def test_put_method_updates_tag(client, fake): address = Address(point=Point(1, 2), neighborhood="Some neighborhood", street=fake.street_address(), city=fake.city(), state=fake.state(), zip=fake.zipcode(), creator_user_id="some id", last_updated_user_id="some id", owner_name=fake.first_name(), owner_email=fake.safe_email(), tenant_name=fake.name(), tenant_email=fake.safe_email(), follow_up_owner_needed=True, land_bank_property=True, type_of_property=1) address.save() address.refresh_from_db() tag = Tag(address=address, creator_user_id="some id", last_updated_user_id="some id", date_taken=timezone.now(), description="some description", img="something goes here", neighborhood="some neighborhood", square_footage="some sq ft", surface="concrete", tag_words="some words", tag_initials="someones initial") tag.save() tag.refresh_from_db() updated = { "address": address.id, "creator_user_id": tag.creator_user_id, "last_updated_user_id": tag.last_updated_user_id, "date_taken": tag.date_taken.strftime("%Y-%m-%d %H:%M:%S"), "description": tag.description, "neighborhood": "new neighborhood" } response = client.put(reverse("tag", kwargs={"pk": tag.id}), json.dumps(updated), content_type="application/json") assert response.status_code == status.HTTP_200_OK, response.content tag.refresh_from_db() assert tag.neighborhood == updated["neighborhood"]
def test_get_address_tags(client, fake): address = Address( point=Point(1, 2), neighborhood="Some neighborhood", street=fake.street_address(), city=fake.city(), state=fake.state(), zip=fake.zipcode(), creator_user_id="some id", last_updated_user_id="some id", owner_name=fake.first_name(), owner_email=fake.safe_email(), tenant_name=fake.name(), tenant_email=fake.safe_email(), follow_up_owner_needed=True, land_bank_property=True, type_of_property=1 ) address.save() address.refresh_from_db() tag_one = Tag( address=address, creator_user_id="some id", last_updated_user_id="some id", date_taken=timezone.now(), description=fake.text(), ) tag_one.save() tag_one.refresh_from_db() tag_two = Tag( address=address, creator_user_id="some id", last_updated_user_id="some id", date_taken=timezone.now(), description=fake.text(), ) tag_two.save() tag_two.refresh_from_db() response = client.get(reverse("address-tags", kwargs={"pk": address.id})) assert response.status_code == status.HTTP_200_OK response_data = json.loads(response.content) assert [tag_one.id, tag_two.id] == sorted([t["id"] for t in response_data])
def test_export_tags(client, fake): address = Address(point=Point(1, 2), neighborhood="Some neighborhood", street=fake.street_address(), city=fake.city(), state=fake.state(), zip=fake.zipcode(), creator_user_id="some id", last_updated_user_id="some id", owner_name=fake.first_name(), owner_email=fake.safe_email(), tenant_name=fake.name(), tenant_email=fake.safe_email(), follow_up_owner_needed=True, land_bank_property=True, type_of_property=1) address.save() address.refresh_from_db() tag_one = Tag( address=address, creator_user_id="some id", last_updated_user_id="some id", date_taken=timezone.now(), description=fake.text(), ) tag_one.save() tag_one.refresh_from_db() tag_two = Tag( address=address, creator_user_id="some id", last_updated_user_id="some id", date_taken=timezone.now(), description=fake.text(), ) tag_two.save() tag_two.refresh_from_db() response = client.get(reverse("tags-download")) assert response.status_code == status.HTTP_200_OK headers = response._headers assert headers["content-type"] == ('Content-Type', 'text/csv')
def test_get_address_exists_returned(client, fake): address = Address( point=Point(1, 2), neighborhood="Some neighborhood", street=fake.street_address(), city=fake.city(), state=fake.state(), zip=fake.zipcode(), creator_user_id="some id", last_updated_user_id="some id", owner_name=fake.first_name(), owner_email=fake.safe_email(), tenant_name=fake.name(), tenant_email=fake.safe_email(), follow_up_owner_needed=True, land_bank_property=True, type_of_property=1 ) address.save() address.refresh_from_db() response = client.get(reverse("address", kwargs={"pk": address.id})) assert response.status_code == status.HTTP_200_OK, response.data
def test_get_method_retrieves_existing_tag(client, fake): address = Address(point=Point(1, 2), neighborhood="Some neighborhood", street=fake.street_address(), city=fake.city(), state=fake.state(), zip=fake.zipcode(), creator_user_id="some id", last_updated_user_id="some id", owner_name=fake.first_name(), owner_email=fake.safe_email(), tenant_name=fake.name(), tenant_email=fake.safe_email(), follow_up_owner_needed=True, land_bank_property=True, type_of_property=1) address.save() address.refresh_from_db() tag = Tag(address=address, creator_user_id="some id", last_updated_user_id="some id", date_taken=timezone.now(), description="some description", img="something goes here", neighborhood="some neighborhood", square_footage="some sq ft", surface="concrete", tag_words="some words", tag_initials="someones initial") tag.save() tag.refresh_from_db() response = client.get(reverse("tag", kwargs={"pk": tag.id})) assert response.status_code == status.HTTP_200_OK assert json.loads(response.content)["id"] == tag.id
def store_address(property): (number, street) = get_number_street(property) address = Address(property = property, number = number, street = street) address.save()
def post(self, *args, **kwargs): form = CheckOutForm(self.request.POST) try: order = Order.objects.get(user=self.request.user, is_ordered=False) if form.is_valid(): # Shipping form actions ------------------------------------------- use_default_shipping = form.cleaned_data.get( 'use_default_shipping_address') # check if default address is marked if use_default_shipping: address_query = Address.objects.filter( user=self.request.user, address_type='S', default=True) if address_query.exists(): shipping_address = address_query[0] order.shipping_address = shipping_address order.save() else: messages.info( self.request.user, "You don't have a default shipping address") return redirect('backend:checkout') else: shipping_address1 = form.cleaned_data.get( 'shipping_address') shipping_address2 = form.cleaned_data.get( 'shipping_address2') shipping_country = form.cleaned_data.get( 'shipping_country') shipping_state = form.cleaned_data.get('shipping_state') shipping_zip_code = form.cleaned_data.get( 'shipping_zip_code') if is_valid_form([ shipping_address1, shipping_country, shipping_state, shipping_zip_code ]): shipping_address = Address( user=self.request.user, street_address=shipping_address1, apartment_address=shipping_address2, country=shipping_country, state=shipping_state, zip_code=shipping_zip_code, address_type='S', ) shipping_address.save() # display notification messages.success(self.request, 'Shipping address added successful') order.shipping_address = shipping_address order.save() # set new default address set_default_shipping_address = form.cleaned_data.get( 'set_default_shipping_address') if set_default_shipping_address: shipping_address.default = True shipping_address.save() else: messages.info( self.request, 'Please fill in the required shipping address') return redirect('backend:checkout') # Shipping form action ends -------------------------------------------- # Billing form actions ------------------------------------------------- use_default_billing_address = form.cleaned_data.get( 'use_default_billing_address') same_billing_address = form.cleaned_data.get( 'same_billing_address') if same_billing_address: billing_address = shipping_address billing_address.pk = None billing_address.save() billing_address.address_type = 'B' billing_address.save() order.billing_address = billing_address order.save() # check if default address is true elif use_default_billing_address: address_query = Address.objects.filter( user=self.request.user, address_type='B', default=True) if address_query.exists(): billing_address = address_query[0] order.billing_address = billing_address order.save() else: messages.info( self.request.user, "You don't have a default shipping address fields") return redirect('backend:checkout') else: billing_address1 = form.cleaned_data.get('billing_address') billing_address2 = form.cleaned_data.get( 'billing_address2') billing_country = form.cleaned_data.get('billing_country') billing_state = form.cleaned_data.get('billing_state') billing_zip_code = form.cleaned_data.get( 'billing_zip_code') if is_valid_form([ billing_address1, billing_country, billing_state, billing_zip_code ]): billing_address = Address( user=self.request.user, street_address=billing_address1, apartment_address=billing_address2, country=billing_country, state=billing_state, zip_code=billing_zip_code, address_type='B', ) billing_address.save() # display notification messages.success(self.request, 'Shipping address added successful') order.billing_address = billing_address order.save() # set new default address set_default_billing_address = form.cleaned_data.get( 'set_default_billing_address') if set_default_billing_address: billing_address.default = True billing_address.save() else: messages.info( self.request, 'Please fill in the required billing address fields' ) return redirect('backend:checkout') # billing form action ends ----------------------------------------------------------- # Check payment method payment = form.cleaned_data.get('payment_method') if payment == 'str': return redirect('backend:payment', payment_method='stripe') elif payment == 'bks': return redirect('backend:payment', payment_method='bkash') elif payment == 'con': return redirect('backend:checkout', payment_method='cash-on-delivery') else: messages.warning(self.request, 'Payment option invalid!') return redirect('backend:checkout') else: messages.warning( 'Form received invalid data. Please try again') return redirect('backend:checkout') except ObjectDoesNotExist: messages.warning(self.request, 'You have no orders!!') return redirect('backend:orders')
def test_list_addresses(client, fake): address_one = Address( point=Point(1, 2), neighborhood="Some neighborhood", street=fake.street_address(), city=fake.city(), state=fake.state(), zip=fake.zipcode(), creator_user_id="some id", last_updated_user_id="some id", owner_name=fake.first_name(), owner_email=fake.safe_email(), tenant_name=fake.name(), tenant_email=fake.safe_email(), follow_up_owner_needed=True, land_bank_property=True, type_of_property=1 ) address_one.save() address_one.refresh_from_db() address_two = Address( point=Point(1, 2), neighborhood="Some neighborhood", street=fake.street_address(), city=fake.city(), state=fake.state(), zip=fake.zipcode(), creator_user_id="some id", last_updated_user_id="some id", owner_name=fake.first_name(), owner_email=fake.safe_email(), tenant_name=fake.name(), tenant_email=fake.safe_email(), follow_up_owner_needed=True, land_bank_property=True, type_of_property=1 ) address_two.save() address_two.refresh_from_db() response = client.get(reverse("address-list")) assert response.status_code == status.HTTP_200_OK response_data = json.loads(response.content) observed_data = response_data["features"] assert [address_one.id, address_two.id] == sorted([a["id"] for a in observed_data])