Esempio n. 1
0
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()
    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_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"]
Esempio n. 4
0
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])
Esempio n. 5
0
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')
Esempio n. 7
0
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