def test_create_returns_valid_response_structure_when_valid_data(
        monkeypatch, http_event, config):
    monkeypatch.setenv("AWS_DEFAULT_REGION", config["aws"]["region"])
    monkeypatch.setenv("DYNAMODB_TABLE", config["aws"]["dynamodb"]["table"])

    response = create(http_event, {})
    payload = json.loads(response["body"])

    assert "isBase64Encoded" in response and response[
        "isBase64Encoded"] == False
    assert "statusCode" in response and response["statusCode"] == 201
    assert "headers" in response
    assert "body" in response

    assert "noteId" in payload
    assert "userId" in payload
    assert "notebook" in payload
    assert "text" in payload

    assert "createdAt" in payload and val.is_now(int(payload["createdAt"]))
    assert "updatedAt" in payload and val.is_now(int(payload["updatedAt"]))

    test_globals["note_id"] = payload["noteId"]
    test_globals["user_id"] = payload["userId"]
    test_globals["notebook"] = payload["notebook"]
    test_globals["text"] = payload["text"]
    test_globals["created_at"] = payload["createdAt"]
    test_globals["updated_at"] = payload["updatedAt"]
def test_create_returns_valid_structure_when_valid_data(dynamodb_table):
    model = NoteModel(dynamodb_table)
    item = model.save(user_id=test_globals["user_id"],
                      notebook=test_globals["notebook"],
                      text=test_globals["text"])

    assert "noteId" in item
    assert "userId" in item and item["userId"] == test_globals["user_id"]
    assert "notebook" in item and item["notebook"] == test_globals["notebook"]
    assert "text" in item and item["text"] == test_globals["text"]

    assert "createdAt" in item and val.is_now(int(item["createdAt"]))
    assert "updatedAt" in item and val.is_now(int(item["updatedAt"]))
def test_create_returns_valid_note_values_when_valid_data(api_notes_url):
    res = requests.post(api_notes_url, json={
                        "userId": test_globals["user_id"], "notebook": test_globals["notebook"],
                        "text": test_globals["text"]})
    payload = res.json()

    assert res.status_code == 201

    assert "noteId" in payload
    assert "userId" in payload and payload["userId"] == test_globals["user_id"]
    assert "notebook" in payload and payload["notebook"] == test_globals["notebook"]
    assert "text" in payload and payload["text"] == test_globals["text"]

    assert "createdAt" in payload and val.is_now(int(payload["createdAt"]))
    assert "updatedAt" in payload and val.is_now(int(payload["updatedAt"]))

    test_globals["note_id"] = payload["noteId"]
    test_globals["user_id"] = payload["userId"]
    test_globals["notebook"] = payload["notebook"]
    test_globals["text"] = payload["text"]
    test_globals["created_at"] = payload["createdAt"]
    test_globals["updated_at"] = payload["updatedAt"]
Exemplo n.º 4
0
def test_now_timestamp_returns_false_when_stale_or_future():
    past = int(time.time() * 1000) - 20000 # Make 10 seconds old.
    future = int(time.time() * 1000) + 20000 # Make 6 seconds future.

    assert val.is_now(past) == False
    assert val.is_now(future) == False
Exemplo n.º 5
0
def test_now_timestamp_returns_true_when_current():
    now = int(time.time() * 1000) # +/- 5 seconds of now.
    
    assert val.is_now(now) == True