-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SK-1308 Fix bug in Get method in Python SDK
- Fix bug when calling Get method with options tokens as true. - Remove redundant import statements from client file. - Add missing validation case for Get method.
- Loading branch information
1 parent
295f0ce
commit 19d9668
Showing
5 changed files
with
85 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,14 @@ | |
import unittest | ||
import os | ||
|
||
from skyflow.errors._skyflow_errors import SkyflowError, SkyflowErrorCodes, SkyflowErrorMessages | ||
from skyflow.vault import Client, Configuration, RedactionType, GetOptions | ||
from skyflow.vault._get_by_id import encrypt_data | ||
from skyflow.service_account import generate_bearer_token | ||
from dotenv import dotenv_values | ||
import warnings | ||
import asyncio | ||
import json | ||
from cryptography.fernet import Fernet | ||
|
||
from dotenv import dotenv_values | ||
from skyflow.service_account import generate_bearer_token | ||
from skyflow.vault import Client, Configuration, RedactionType, GetOptions | ||
from skyflow.vault._get import getGetRequestBody | ||
from skyflow.errors._skyflow_errors import SkyflowError, SkyflowErrorCodes, SkyflowErrorMessages | ||
|
||
class TestGet(unittest.TestCase): | ||
|
||
|
@@ -169,7 +167,6 @@ def testGetByIdInvalidColumnValues(self): | |
self.assertEqual( | ||
e.message, SkyflowErrorMessages.INVALID_COLUMN_VALUE.value % (str) ) | ||
|
||
|
||
def testGetByTokenAndRedaction(self): | ||
invalidData = {"records": [ | ||
{"ids": ["123","456"], | ||
|
@@ -184,8 +181,7 @@ def testGetByTokenAndRedaction(self): | |
e.message, SkyflowErrorMessages.REDACTION_WITH_TOKENS_NOT_SUPPORTED.value) | ||
|
||
def testGetByNoOptionAndRedaction(self): | ||
invalidData = {"records":[ | ||
{"ids":["123","456"],"table":"newstripe"}]} | ||
invalidData = {"records":[{"ids":["123", "456"], "table":"newstripe"}]} | ||
options = GetOptions(False) | ||
try: | ||
self.client.get(invalidData,options=options) | ||
|
@@ -196,10 +192,13 @@ def testGetByNoOptionAndRedaction(self): | |
e.message,SkyflowErrorMessages.REDACTION_KEY_ERROR.value) | ||
|
||
def testGetByOptionAndUniqueColumnRedaction(self): | ||
invalidData ={"records":[ | ||
{"table":"newstripe","columnName":"card_number","columnValues":["456","980"],} | ||
]} | ||
|
||
invalidData ={ | ||
"records":[{ | ||
"table":"newstripe", | ||
"columnName":"card_number", | ||
"columnValues":["456","980"], | ||
}] | ||
} | ||
options = GetOptions(True) | ||
try: | ||
self.client.get(invalidData, options=options) | ||
|
@@ -210,9 +209,13 @@ def testGetByOptionAndUniqueColumnRedaction(self): | |
e.message, SkyflowErrorMessages.TOKENS_GET_COLUMN_NOT_SUPPORTED.value) | ||
|
||
def testInvalidRedactionTypeWithNoOption(self): | ||
invalidData = {"records": [ | ||
{"ids": ["123","456"], | ||
"table": "stripe", "redaction": "invalid_redaction"}]} | ||
invalidData = { | ||
"records": [{ | ||
"ids": ["123","456"], | ||
"table": "stripe", | ||
"redaction": "invalid_redaction" | ||
}] | ||
} | ||
options = GetOptions(False) | ||
try: | ||
self.client.get(invalidData, options=options) | ||
|
@@ -221,36 +224,36 @@ def testInvalidRedactionTypeWithNoOption(self): | |
self.assertEqual(e.code, SkyflowErrorCodes.INVALID_INPUT.value) | ||
self.assertEqual(e.message, SkyflowErrorMessages.INVALID_REDACTION_TYPE.value % (str)) | ||
|
||
def test_encrypt_data_with_token(self): | ||
data = { | ||
def testBothSkyflowIdsAndColumnDetailsPassed(self): | ||
invalidData = { | ||
"records": [ | ||
{ | ||
"fields": { | ||
"ids": ["123","456"], | ||
"table": "stripe", | ||
} | ||
"ids": ["123", "456"], | ||
"table": "stripe", | ||
"redaction": RedactionType.PLAIN_TEXT, | ||
"columnName": "email", | ||
"columnValues": ["[email protected]", "[email protected]"] | ||
} | ||
] | ||
} | ||
token = "secret_token" | ||
encrypted_bytes = encrypt_data(data, token) | ||
self.assertIsNotNone(encrypted_bytes) | ||
|
||
def test_encrypt_data_without_token(self): | ||
data = { | ||
"records": [ | ||
{ | ||
"fields": { | ||
"ids": ["123", "456"], | ||
"table": "stripe", | ||
} | ||
} | ||
] | ||
options = GetOptions(False) | ||
try: | ||
self.client.get(invalidData, options=options) | ||
self.fail('Should have thrown an error') | ||
except SkyflowError as e: | ||
self.assertEqual(e.code, SkyflowErrorCodes.INVALID_INPUT.value) | ||
self.assertEqual(e.message, SkyflowErrorMessages.BOTH_IDS_AND_COLUMN_DETAILS_SPECIFIED.value) | ||
|
||
def testGetRequestBodyReturnsRequestBodyWithIds(self): | ||
validData = { | ||
"records": [{ | ||
"ids": ["123", "456"], | ||
"table": "stripe", | ||
}] | ||
} | ||
token = None | ||
encrypted_data, key = encrypt_data(data, token) | ||
self.assertEqual(encrypted_data, data) | ||
self.assertIsNone(key) | ||
|
||
|
||
|
||
options = GetOptions(True) | ||
try: | ||
requestBody = getGetRequestBody(validData["records"][0], options) | ||
self.assertTrue(requestBody["tokenization"]) | ||
except SkyflowError as e: | ||
self.fail('Should not have thrown an error') |