Exemplo n.º 1
0
def test_set_history_doc_refs_empty_final_url_w_uuid():
    """Creating a new document, without a final_url should raise an error"""
    db = fc.new_connection(project=TEST_PROJECT)
    # TODO: Use it as soon as firestore-connector will raise a proper Error
    # with pytest.raises(KeyError, match=r"'final_url'"):
    res = fc.set_history_doc_refs(db, {"dealroom_uuid": uuid()})
    assert res == StatusCode.ERROR
Exemplo n.º 2
0
def test_set_history_doc_refs_existing_by_url_with_wrong_dealroom_uuid():
    """Create a new document, using a valid but already used final_url (with another dealroom_id), should be ok"""
    db = fc.new_connection(project=TEST_PROJECT)
    wrong_dr_uuid = uuid()
    res = fc.set_history_doc_refs(db, {"final_url": "foo33.bar"},
                                  wrong_dr_uuid)
    assert res == StatusCode.CREATED
Exemplo n.º 3
0
def test_set_history_doc_refs_existing_by_url():
    """Update an existing document with dealroom_id=-1 and dealroom_uuid=-1, using the final_url"""
    db = fc.new_connection(project=TEST_PROJECT)
    random_field = _get_random_string(10)
    res = fc.set_history_doc_refs(db, {"test_field": random_field},
                                  finalurl_or_dealroomid="foo4.bar")
    assert res == StatusCode.UPDATED
Exemplo n.º 4
0
def test_set_history_doc_refs_wrong_final_url_w_uuid():
    """Creating a new document, with invalid final_url should raise an error"""
    db = fc.new_connection(project=TEST_PROJECT)
    # TODO: Use it as soon as firestore-connector will raise a proper Error
    # with pytest.raises(Exception):
    res = fc.set_history_doc_refs(db, {
        "final_url": "asddsadsdsd",
        "dealroom_uuid": uuid()
    })
    assert res == StatusCode.ERROR
Exemplo n.º 5
0
def test_set_history_doc_refs_wrong_dealroom_uuid():
    """Creating a new document, with invalid dealroom uuid should raise an error"""
    db = fc.new_connection(project=TEST_PROJECT)
    # TODO: Use it as soon as firestore-connector will raise a proper Error
    # with pytest.raises(ValueError, match=r"'dealroom_id'"):
    res = fc.set_history_doc_refs(db, {
        "final_url": f"{_get_random_string(10)}.com",
        "dealroom_uuid": "foobar"
    })
    assert res == StatusCode.ERROR
Exemplo n.º 6
0
def test_set_history_doc_refs_empty_final_url_valid_uuid():
    """Updating an existing document, using a valid dealroom_uuid, should be ok"""
    db = fc.new_connection(project=TEST_PROJECT)
    random_field = _get_random_string(10)
    EXISTING_DOC_DR_UUID = "ef314e25-4543-4636-a5b7-c428886e3dd3"

    res = fc.set_history_doc_refs(db, {"test_field": random_field},
                                  EXISTING_DOC_DR_UUID)

    assert res == StatusCode.UPDATED
Exemplo n.º 7
0
def test_set_history_doc_refs_new_valid_url_id_as_uuid():
    """Creating a new document, with valid final_url & id given for uuid should raise an error"""
    db = fc.new_connection(project=TEST_PROJECT)
    res = fc.set_history_doc_refs(
        db,
        {
            "final_url": f"{_get_random_string(10)}.com",
            "dealroom_uuid": randint(1e5, 1e8),
        },
    )

    assert res == StatusCode.ERROR
Exemplo n.º 8
0
def test_set_history_doc_refs_new_valid_url_id():
    """Creating a new document, with valid final_url & valid dealroom id should be ok"""
    db = fc.new_connection(project=TEST_PROJECT)
    res = fc.set_history_doc_refs(
        db,
        {
            "final_url": f"{_get_random_string(10)}.com",
            "dealroom_id": randint(1e5, 1e8),
        },
    )

    assert res == StatusCode.CREATED
Exemplo n.º 9
0
def test_set_history_doc_refs_as_deleted_on_uuid():
    """Marking an entity as deleted (dealroom_uuid = -2), should be ok"""
    db = fc.new_connection(project=TEST_PROJECT)
    FINAL_URL = "foo77.bar"
    fc.set_history_doc_refs(db, {
        "dealroom_uuid": uuid(),
        "final_url": FINAL_URL
    })
    res = fc.set_history_doc_refs(db, {"dealroom_uuid": -2}, FINAL_URL)

    assert res == StatusCode.UPDATED
    doc_ref = fc.get_history_doc_refs(db, final_url=FINAL_URL)["final_url"][0]
    doc_ref.delete()
Exemplo n.º 10
0
def test_set_history_doc_refs_existing_by_url_with_new_dealroom_id():
    """Update a new document, using a valid but already used final_url (with another dealroom_id=-1), should be ok"""
    db = fc.new_connection(project=TEST_PROJECT)
    new_dr_id = randint(1e5, 1e8)
    fc.set_history_doc_refs(db, {"final_url": "foo9.bar", "dealroom_id": -1})
    res = fc.set_history_doc_refs(db, {
        "final_url": "foo9.bar",
        "dealroom_id": new_dr_id
    }, new_dr_id)
    assert res == StatusCode.UPDATED
    doc_ref = fc.get_history_doc_refs(db,
                                      dealroom_id=new_dr_id)["dealroom_id"][0]
    doc_ref.delete()
Exemplo n.º 11
0
def test_set_history_doc_refs_as_deleted_on_uuid_0():
    """Marking an entity with dealroom_uuid = 0, should raise an error"""
    db = fc.new_connection(project=TEST_PROJECT)
    FINAL_URL = "foo77.bar"
    fc.set_history_doc_refs(db, {
        "dealroom_uuid": uuid(),
        "final_url": FINAL_URL
    })
    res = fc.set_history_doc_refs(db, {"dealroom_uuid": "0"}, FINAL_URL)

    assert res == StatusCode.ERROR
    doc_ref = fc.get_history_doc_refs(db, final_url=FINAL_URL)["final_url"][0]
    doc_ref.delete()
Exemplo n.º 12
0
def test_set_history_doc_refs_existing_by_url_using_payload_w_id():
    """Update an existing document with dealroom_id=-1, using the final_url from the payload"""
    db = fc.new_connection(project=TEST_PROJECT)
    fc.set_history_doc_refs(db, {"final_url": "foo5.bar", "dealroom_id": -1})
    dealroom_id = randint(1e5, 1e8)
    res = fc.set_history_doc_refs(db, {
        "final_url": "foo5.bar",
        "dealroom_id": dealroom_id
    })

    assert res == StatusCode.UPDATED
    doc_ref = fc.get_history_doc_refs(
        db, dealroom_id=dealroom_id)["dealroom_id"][0]
    doc_ref.delete()
Exemplo n.º 13
0
def test_set_history_doc_refs_for_deleted_company_w_uuid_2():
    """Update a document for a new company that appears previously as deleted (uuid) should be ok."""
    db = fc.new_connection(project=TEST_PROJECT)

    # fixed dealroom_uuid_old in firestore
    dealroom_uuid = "49ada2cf-e234-4fa5-937d-1d65a9bbe2b0"
    random_value = _get_random_string(10)
    res = fc.set_history_doc_refs(db, {"test_field": random_value},
                                  dealroom_uuid)
    assert res == StatusCode.UPDATED

    # fixed url in firestore
    final_url = "foo88.bar"
    random_value = _get_random_string(10)
    res = fc.set_history_doc_refs(db, {"test_field": random_value}, final_url)
    assert res == StatusCode.UPDATED
Exemplo n.º 14
0
def test_set_history_doc_refs_for_deleted_company_w_uuid():
    """Create a document for a new company that appears previously as deleted should be ok."""
    # Tests this bug https://dealroom.atlassian.net/browse/DS2-154
    db = fc.new_connection(project=TEST_PROJECT)
    dealroom_uuid = uuid()
    print(dealroom_uuid)
    res = fc.set_history_doc_refs(db, {
        "final_url": "foo66.bar",
        "dealroom_uuid": dealroom_uuid
    }, dealroom_uuid)
    doc_ref = fc.get_history_doc_refs(
        db, dealroom_id=dealroom_uuid)["dealroom_uuid"][0]
    doc_ref.delete()
    # NOTE: if the call doesn't have the dealroom_id as a parameter this fails. Since we removed
    # the logic to extract the dealroom_id from the payload here: https://dealroom.atlassian.net/browse/DS2-104
    assert res == StatusCode.CREATED
Exemplo n.º 15
0
import sys

import dealroom_firestore_connector as fc

# Connect to staging Firestore
db = fc.new_connection(
    project="sustained-hold-288413",
    credentials_path="cred.json",
)
if db == -1:
    # Error. Do something else
    sys.exit()

# Go to desired collection
collection_ref = db.collection(u"firestore_connector_test")

# Create a document
doc_ref = collection_ref.document(u"test_file")
if fc.set(doc_ref, {u"website": u"abc.com", u"index": u"123123"}) == -1:
    # Error. Do something else (i.e. continue to next doc)
    sys.exit()
else:
    pass

# Get a document
doc_ref = collection_ref.document(u"test_file")
doc = fc.get(doc_ref)
if doc != -1:
    print(doc.id)
    print(doc.to_dict())
Exemplo n.º 16
0
def test_set_history_doc_refs_new_empty():
    """Creating a new document, with empty final_url & dealroom_id, should raise an error"""
    db = fc.new_connection(project=TEST_PROJECT)
    empty_doc_payload = {}
    res = fc.set_history_doc_refs(db, empty_doc_payload)
    assert res == StatusCode.ERROR
Exemplo n.º 17
0
def test_set_history_doc_refs_empty_dealroom_id_valid_url():
    """Updating a new document, using a valid final_url, should be ok"""
    db = fc.new_connection(project=TEST_PROJECT)
    random_field = _get_random_string(10)
    res = fc.set_history_doc_refs(db, {"test_field": random_field}, "foo2.bar")
    assert res == StatusCode.UPDATED
Exemplo n.º 18
0
def test_collection_exists():
    db = fc.new_connection(project=TEST_PROJECT)
    col_ref = db.collection("NOT_EXISTING_COLLECTION")
    assert fc.collection_exists(col_ref) == False