Skip to content

feat: better multipart tests #989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
21c6902
feat: specs validation test
loks0n Sep 26, 2024
53442dc
fix: complied -> compiled typo
loks0n Sep 26, 2024
40db59e
feat: to_string and to_json tests for payload
loks0n Sep 26, 2024
ae14970
chore: typo
loks0n Sep 26, 2024
5ce29b3
fix: deno, php, ruby, web tests
loks0n Sep 26, 2024
7f2100a
fix: python
loks0n Sep 26, 2024
36c6329
fix: dart, php, deno
loks0n Sep 26, 2024
01a5a79
fix: dart type
loks0n Sep 26, 2024
e80b39f
chore: composer update
loks0n Sep 26, 2024
061c943
chore: composer fmt
loks0n Sep 26, 2024
da583b6
fix: web
loks0n Sep 26, 2024
09f1445
fix: web
loks0n Sep 26, 2024
d4336a4
fix: indentation
loks0n Sep 26, 2024
95887bb
chore: lint
loks0n Sep 26, 2024
700e23e
feat: multipart echo tests
loks0n Sep 26, 2024
59b1572
fix: deno
loks0n Sep 26, 2024
7a6d16e
fix: ruby
loks0n Sep 26, 2024
bd53120
fix: python
loks0n Sep 26, 2024
497c6ab
fix: python
loks0n Sep 27, 2024
246f3b5
fix: php
loks0n Sep 27, 2024
76c09f2
fix: php
loks0n Sep 27, 2024
766f420
fix: cli
loks0n Sep 27, 2024
d43080b
feat: better error
loks0n Sep 27, 2024
7efc532
fix: web
loks0n Sep 27, 2024
d65ac93
fix: ruby
loks0n Sep 27, 2024
462fe32
fix: ruby
loks0n Sep 27, 2024
6637cda
fix: deno
loks0n Sep 27, 2024
c56a3fe
fix: deno
loks0n Sep 27, 2024
77984be
fix(ruby): add mime-types dep
loks0n Sep 30, 2024
fb4f87f
fix(kotlin): multipart tests
loks0n Sep 30, 2024
0612d4a
fix(ruby): downgrade mime-types
loks0n Sep 30, 2024
6b43960
fix(go): multipart tests
loks0n Sep 30, 2024
df0c356
fix(go): multipart tests
loks0n Sep 30, 2024
55ddcd3
fix(deno): multipart test syntax
loks0n Sep 30, 2024
a652eba
fix(dart): multipart tests
loks0n Sep 30, 2024
46336ba
fix(dart): multipart tests
loks0n Sep 30, 2024
b030e06
test: use tmp for file_copy.png
loks0n Sep 30, 2024
e19401e
test: fix tmp path
loks0n Sep 30, 2024
0bd2e39
fix(ruby,python): create dir if not exists payload.tofile
loks0n Sep 30, 2024
4896fa8
fix(ruby): require fileutils
loks0n Sep 30, 2024
c122aff
fix(flutter): multipart tests
loks0n Sep 30, 2024
b1739b9
fix(dart): fake test
loks0n Sep 30, 2024
155f72f
fix(android): multipart tests
loks0n Sep 30, 2024
0c10b69
fix(deno): fake test
loks0n Sep 30, 2024
f930df5
fix(dotnet): path
loks0n Sep 30, 2024
6e58220
fix(kotlin): type
loks0n Sep 30, 2024
beda039
fix(kotlin): tests
byawitz Sep 30, 2024
a97b595
fix(android): multipart tests
loks0n Sep 30, 2024
4a24baf
Merge branch 'feat-multipart' of https://github.com/appwrite/sdk-gene…
loks0n Sep 30, 2024
8396704
Merge branch 'feat-multipart' of https://github.com/appwrite/sdk-gene…
loks0n Oct 1, 2024
392dc35
Merge branch 'feat-multipart' of https://github.com/appwrite/sdk-gene…
loks0n Oct 1, 2024
d9f30e9
Merge branch 'feat-multipart' of https://github.com/appwrite/sdk-gene…
loks0n Oct 1, 2024
734523d
fix(android): multipart tests
loks0n Oct 1, 2024
a796ccc
fix(go): compile error
loks0n Oct 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,23 @@ jobs:

- name: Lint
run: composer lint

specs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: curl

- name: Install
run: composer install

- name: Validate specs
run: composer test tests/SpecsTest.php

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"ext-mbstring": "*",
"ext-json": "*",
"twig/twig": "3.14.*",
"matthiasmullie/minify": "1.3.*"
"matthiasmullie/minify": "1.3.*",
"utopia-php/fetch": "^0.2.1"
},
"require-dev": {
"phpunit/phpunit": "11.*",
Expand Down
41 changes: 40 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion mock-server/app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
});

App::get('/v1/mock/tests/general/multipart')
->alias('/v1/mock/tests/general/multipartcomplied')
->alias('/v1/mock/tests/general/multipart-compiled')
->desc('Multipart')
->groups(['mock'])
->label('scope', 'public')
Expand All @@ -410,6 +410,31 @@
]);
});

App::get('/v1/mock/tests/general/multipart-json')
->desc('Multipart')
->groups(['mock'])
->label('scope', 'public')
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
->label('sdk.namespace', 'general')
->label('sdk.method', 'multipartJson')
->label('sdk.description', 'Mock a multipart request.')
->label('sdk.response.code', Response::STATUS_CODE_OK)
->label('sdk.response.type', Response::CONTENT_TYPE_MULTIPART)
->label('sdk.response.model', Response::MODEL_MULTIPART)
->label('sdk.mock', true)
->inject('response')
->action(function (Response $response) {

$response->multipart([
'x' => 'abc',
'y' => 123,
'responseBody' => [
'key' => 'value',
'key2' => 'value2',
],
]);
});

App::get('/v1/mock/tests/general/redirect')
->desc('Redirect')
->groups(['mock'])
Expand Down
2 changes: 1 addition & 1 deletion mock-server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
mockapi:
container_name: mockapi
ports:
- 8080:80
- 3175:80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's annoying, 8080 conflicts with appwrite/appwrite

build:
context: .
args:
Expand Down
2 changes: 1 addition & 1 deletion templates/php/src/Client.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class Client
$data['duration'] = ((float) ($data['duration'] ?? ''));
}
if(isset($data['responseBody'])) {
$data['responseBody'] = Payload::fromString($data['responseBody'] ?? '');
$data['responseBody'] = Payload::fromBinary($data['responseBody'] ?? '');
}

return $data;
Expand Down
4 changes: 2 additions & 2 deletions templates/python/package/payload.py.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Payload:

return self._data[offset:offset + length]

def to_string(self) -> str:
return str(self.to_binary())
def to_string(self, encoding='utf-8') -> str:
return self.to_binary().decode(encoding)

def to_json(self) -> Dict[str, Any]:
return json.loads(self.to_string())
Expand Down
4 changes: 3 additions & 1 deletion tests/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ abstract class Base extends TestCase

protected const MULTIPART_RESPONSES = [
'abc',
'd80e7e6999a3eb2ae0d631a96fe135a4' #
'd80e7e6999a3eb2ae0d631a96fe135a4',
'{"key": "value", "key2": "value2"}',
'value',
];

protected const QUERY_HELPER_RESPONSES = [
Expand Down
27 changes: 27 additions & 0 deletions tests/SpecsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use PHPUnit\Framework\TestCase;
use Utopia\Fetch\Client;

class SpecsTest extends TestCase
{
public function testSpecs()
{
$specsPath = dirname(__FILE__) . '/resources/spec.json';
$specs = json_decode(file_get_contents($specsPath), true);

$client = new Client();
$client->addHeader('content-type', 'application/json');

$response = $client->fetch(
url: 'https://validator.swagger.io/validator/debug',
method: Client::METHOD_POST,
body: $specs
);

$this->assertEquals(200, $response->getStatusCode(), 'Failed to validate specs: ' . $response->getBody());

$body = $response->json();
$this->assertEmpty($body['schemaValidationMessages'], 'Schema validation failed: ' . json_encode($body['schemaValidationMessages'], JSON_PRETTY_PRINT));
}
}
2 changes: 1 addition & 1 deletion tests/languages/android/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class ServiceTest {
general.empty()

// Multipart tests
val mp = general.multipartComplied()
val mp = general.multipartCompiled()

writeToFile((mp as Map<String, Any>)["x"] as String)
writeToFile(md5(((mp as Map<String, Any>)["responseBody"] as Payload).toBinary()))
Expand Down
4 changes: 4 additions & 0 deletions tests/languages/dart/tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ void main() async {
final hash = md5.convert(responseMultipart.responseBody.toBinary()).toString();
print(hash);

responseMultipart = await general.multipartJson();
print(responseMultipart.responseBody.toString());
print(responseMultipart.responseBody.toJson()['key']);

// Query helper tests
print(Query.equal('released', [true]));
print(Query.equal('title', ['Spiderman', 'Dr. Strange']));
Expand Down
4 changes: 4 additions & 0 deletions tests/languages/deno/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ async function start() {
const binary = await response['responseBody'].toBinary();
console.log(createHash("md5").update(binary).toString('hex'));

response = await general.multipartJson();
console.log(response.responseBody.toString());
console.log(response.responseBody.toJson<{ key: string, key2: string}>()["key"]);

// Query helper tests
console.log(Query.equal("released", [true]));
console.log(Query.equal("title", ["Spiderman", "Dr. Strange"]));
Expand Down
2 changes: 1 addition & 1 deletion tests/languages/dotnet/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public async Task Test1()
);
TestContext.WriteLine(url);
// Multipart tests
var response = await general.MultipartComplied();
var response = await general.MultipartCompiled();
var res = (response as Dictionary<string, object>);
TestContext.WriteLine(res["x"]);
var pl = res["responseBody"] as Payload;
Expand Down
4 changes: 4 additions & 0 deletions tests/languages/flutter/tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ void main() async {
final hash = md5.convert(responseMultipart.responseBody.toBinary()).toString();
print(hash);

responseMultipart = await general.multipartJson();
print(responseMultipart.responseBody.toString());
print(responseMultipart.responseBody.toJson()['key']);

// Query helper tests
print(Query.equal('released', [true]));
print(Query.equal('title', ['Spiderman', 'Dr. Strange']));
Expand Down
2 changes: 1 addition & 1 deletion tests/languages/go/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func testLargeUpload(client client.Client, stringInArray []string) {

func testMultipart(client client.Client){
g := general.New(client)
mp, err := g.MultipartComplied()
mp, err := g.MultipartCompiled()

if err != nil { return }

Expand Down
2 changes: 1 addition & 1 deletion tests/languages/kotlin/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ServiceTest {
writeToFile(url)

// Multipart tests
val mp = general.multipartComplied()
val mp = general.multipartCompiled()

writeToFile((mp as Map<String, Any>)["x"] as String)
writeToFile(md5(((mp as Map<String, Any>)["responseBody"] as Payload).toBinary()))
Expand Down
4 changes: 4 additions & 0 deletions tests/languages/node/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ async function start() {
const responseBodyBinary = response.responseBody.toBinary();
const hash = crypto.createHash('md5').update(responseBodyBinary).digest('hex');
console.log(hash); // should be d80e7e6999a3eb2ae0d631a96fe135a4

response = await general.multipartJson();
console.log(response.responseBody.toString());
console.log(response.responseBody.toJson()['key']);
}

start().catch((err) => {
Expand Down
4 changes: 4 additions & 0 deletions tests/languages/php/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
$hash = md5($response['responseBody']->toBinary());
echo "{$hash}\n";

$response = $general->multipartJson();
echo "{$response['responseBody']->toString()}\n";
echo "{$response['responseBody']->toJson()['key']}\n";

// Query helper tests
echo Query::equal('released', [true]) . "\n";
echo Query::equal('title', ['Spiderman', 'Dr. Strange']) . "\n";
Expand Down
4 changes: 4 additions & 0 deletions tests/languages/python/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
print(response['x']) # should be "abc"
print(md5(response['responseBody'].to_binary()).hexdigest()) # should be d80e7e6999a3eb2ae0d631a96fe135a4

response = general.multipart_json()
print(response['responseBody'].to_string())
print(response['responseBody'].to_json()['key'])

# Query helper tests
print(Query.equal("released", [True]))
print(Query.equal("title", ["Spiderman", "Dr. Strange"]))
Expand Down
9 changes: 9 additions & 0 deletions tests/languages/ruby/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@
puts e
end

begin
response = general.multipart_json()

puts response.response_body.to_string
puts response.response_body.to_json()['key']
rescue => e
puts e
end

# Query helper tests
puts Query.equal('released', [true])
puts Query.equal('title', ['Spiderman', 'Dr. Strange'])
Expand Down
Loading
Loading