File size: 4,588 Bytes
ef1ad9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from io import BytesIO

import pytest

from .test_payloads.payload_document_router import *


# upload file for consumer
@pytest.mark.parametrize("file, form_data", upload_document_payload)
def test_upload_document(file, form_data, test_client, consumer_header):
    file_data = BytesIO(file["file_content"])
    file_name = file["file_name"]
    content_type = file["content_type"]

    file = {"file": (file_name, file_data, content_type)}

    data = {
        "userId": form_data["user_id"],
        "applicationId": form_data["application_id"],
        "userProfileId": form_data["user_profile_id"],
        "documentTypeId": form_data["document_type_id"],
        "documentSubTypeId": form_data["document_sub_type_id"],
        "documentTitle": form_data["document_title"],
    }

    url = "/file/upload_file"
    response = test_client.post(url, data=data, files=file, headers=consumer_header)
    assert response.status_code == 200

    response = response.json()
    assert response["status"] == 200
    assert response["message"] == "File uploaded succesfully!"


# update existing file for consumer
@pytest.mark.parametrize("file, form_data", update_document_payload)
def test_update_document(file, form_data, test_client, consumer_header):
    document_id = 495
    file_data = BytesIO(file["file_content"])
    file_name = file["file_name"]
    content_type = file["content_type"]

    file = {"file": (file_name, file_data, content_type)}

    data = {
        "userId": form_data["user_id"],
        "applicationId": form_data["application_id"],
        "documentTitle": form_data["document_title"],
    }

    url = f"/file/update_file/{document_id}"
    response = test_client.put(url, data=data, files=file, headers=consumer_header)
    assert response.status_code == 200

    response = response.json()
    assert response["status"] == 200
    assert response["message"] == "File updated succesfully!"


# read file
def test_read_file(test_client, consumer_header):
    document_id = 495
    url = f"/file/read_file/{document_id}"
    response = test_client.get(url, headers=consumer_header)
    if response.status_code == 200:
        assert response.status_code == 200
    elif response.status_code == 500:
        response = response.json()
        assert response["message"] == "404: Document does not exist!"


# fetch users document list
def test_list_documents(test_client, consumer_header, application_id):
    url = f"/file/documents/{application_id}"
    response = test_client.get(url, headers=consumer_header)
    assert response.status_code == 200

    response = response.json()
    assert response["status"] == 200
    assert response["message"] == "Document types retrieved successfully"


# fetch users document list
def test_list_internal_documents(test_client, consumer_header, application_id):
    user_id = 425
    url = f"/file/documents/internal/{application_id}?user_id={user_id}"
    response = test_client.get(url, headers=consumer_header)
    assert response.status_code == 200

    response = response.json()
    assert response["status"] == 200
    assert response["message"] == "Document types retrieved successfully"


# delete existing document
def test_delete_document(test_client, consumer_header):
    document_id = 495
    url = f"/file/document/{document_id}"
    response = test_client.delete(url, headers=consumer_header)
    if response.status_code == 200:
        response = response.json()
        assert response["status"] == 200
        assert response["message"] == "User Document deleted successfully"
    elif response.status_code == 404:
        response = response.json()
        assert response["status"] == 200
        assert response["message"] == "No documents found"


# fetch logged-in user information
def test_get_user_info(test_client, consumer_header):
    url = "/file/user_info"
    response = test_client.get(url, headers=consumer_header)
    assert response.status_code == 200

    response = response.json()
    assert response["status"] == 200
    assert response["message"] == "User info fetched successfully"


# fetch document status
def test_get_document_status(test_client, consumer_header):
    url = "/file/document_status"
    response = test_client.get(url, headers=consumer_header)
    assert response.status_code == 200

    response = response.json()
    assert response["status"] == 200
    assert response["message"] == "Document status fetched successfully!"