<commit_before>def test_create_tensor(client):
    result = client.post("/dcfl/tensors", data={"tensor": "{serialized_tensor}"})
    assert result.status_code == 200
    assert result.get_json() == {"msg": "tensor created succesfully!"}


def test_get_all_tensors(client):
    result = client.get("/dcfl/tensors")
    assert result.status_code == 200
    assert result.get_json() == {
        "tensors": [
            {
                "id": "35654sad6ada",
                "tags": ["tensor-a"],
                "description": "tensor sample",
            },
            {
                "id": "adfarf3f1af5",
                "tags": ["tensor-b"],
                "description": "tensor sample",
            },
            {
                "id": "fas<PASSWORD>",
                "tags": ["tensor-c"],
                "description": "tensor sample",
            },
        ]
    }


def test_get_specific_tensor(client):
    result = client.get("/dcfl/tensors/5484626")
    assert result.status_code == 200
    assert result.get_json() == {
        "tensor": {
            "id": "5484626",
            "tags": ["tensor-a"],
            "description": "tensor sample",
        }
    }


def test_update_tensor(client):
    result = client.put(
        "/dcfl/tensors/546313", data={"tensor": "new_serialized_tensor"}
    )
    assert result.status_code == 200
    assert result.get_json() == {"msg": "tensor changed succesfully!"}


def test_delete_tensor(client):
    result = client.delete("/dcfl/tensors/546313")
    assert result.status_code == 200
    assert result.get_json() == {"msg": "tensor deleted succesfully!"}<commit_msg>Update integration tests for /dcfl/tensors endpoints<commit_after>from json import dumps, loads

import jwt
import pytest
from flask import current_app as app

from src.main.core.database import *

JSON_DECODE_ERR_MSG = (
    "Expecting property name enclosed in " "double quotes: line 1 column 2 (char 1)"
)
owner_role = ("Owner", True, True, True, True, True, True, True)
user_role = ("User", False, False, False, False, False, False, False)
admin_role = ("Administrator", True, True, True, True, False, False, True)

user1 = (
    "<EMAIL>",
    "BDEB6E8EE39B6C70835993486C9E65DC",
    "]GBF[R>GX[9Cmk@DthFT!mhloUc%[f",
    "fd062d885b24bda173f6aa534a3418bcafadccecfefe2f8c6f5a8db563549ced",
    1,
)
user2 = (
    "<EMAIL>",
    "2amt5MXKdLhEEL8FiQLcl8Mp0FNhZI6",
    "$2b$12$rj8MnLcKBxAgL7GUHrYn6O",
    "acfc10d15d7ec9f7cd05a312489af2794619c6f11e9af34671a5f33da48c1de2",
    2,
)
user3 = (
    "<EMAIL>",
    "2amt5MXKdLhEEL8FiQLcl8Mp0FNhZI6",
    "$2b$12$rj8MnLcKBxAgL7GUHrYn6O",
    "acfc10d15d7ec9f7cd05a312489af2794619c6f11e9af34671a5f33da48c1de2",
    3,
)
user4 = (
    "<EMAIL>",
    "2amt5MXKdLhEEL8FiQLcl8Mp0FNhZI6",
    "$2b$12$tufn64/0gSIAdprqBrRzC.",
    "fd062d885b24bda173f6aa534a3418bcafadccecfefe2f8c6f5a8db563549ced",
    2,
)


@pytest.fixture
def cleanup(database):
    yield
    try:
        database.session.query(User).delete()
        database.session.query(Role).delete()
        database.session.query(Group).delete()
        database.session.query(UserGroup).delete()
        database.session.commit()
    except:
        database.session.rollback()


def test_create_tensor(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_user = create_user(*user1)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "token": token.decode("UTF-8"),
    }

    result = client.post(
        "/dcfl/tensors", data={"tensor": "{serialized_tensor}"}, headers=headers
    )
    assert result.status_code == 200
    assert result.get_json() == {"msg": "tensor created succesfully!"}


def test_get_all_tensors(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_user = create_user(*user1)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "token": token.decode("UTF-8"),
    }

    result = client.get("/dcfl/tensors", headers=headers)
    assert result.status_code == 200
    assert result.get_json() == {
        "tensors": [
            {
                "id": "35654sad6ada",
                "tags": ["tensor-a"],
                "description": "tensor sample",
            },
            {
                "id": "adfarf3f1af5",
                "tags": ["tensor-b"],
                "description": "tensor sample",
            },
            {
                "id": "fas4e6e1fas",
                "tags": ["tensor-c"],
                "description": "tensor sample",
            },
        ]
    }


def test_get_specific_tensor(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_user = create_user(*user1)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "token": token.decode("UTF-8"),
    }

    result = client.get("/dcfl/tensors/5484626", headers=headers)
    assert result.status_code == 200
    assert result.get_json() == {
        "tensor": {
            "id": "5484626",
            "tags": ["tensor-a"],
            "description": "tensor sample",
        }
    }


def test_update_tensor(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_user = create_user(*user1)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "token": token.decode("UTF-8"),
    }

    result = client.put(
        "/dcfl/tensors/546313",
        data={"tensor": "new_serialized_tensor"},
        headers=headers,
    )
    assert result.status_code == 200
    assert result.get_json() == {"msg": "tensor changed succesfully!"}


def test_delete_tensor(client, database, cleanup):
    new_role = create_role(*admin_role)
    database.session.add(new_role)
    new_user = create_user(*user1)
    database.session.add(new_user)

    database.session.commit()

    token = jwt.encode({"id": 1}, app.config["SECRET_KEY"])
    headers = {
        "token": token.decode("UTF-8"),
    }

    result = client.delete("/dcfl/tensors/546313", headers=headers)
    assert result.status_code == 200
    assert result.get_json() == {"msg": "tensor deleted succesfully!"}
{'fraction_non_alphanumeric': 0.1459608323133415, 'fraction_numerical': 0.04911260709914321, 'mean_word_length': 2.720546385885031, 'pattern_counts': {'":': 48, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2226060', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2235, 'n_words': 369}