interfasys / mediametadata

A cloud application which provides CRUD access to the metadata stored in images
GNU Affero General Public License v3.0
5 stars 1 forks source link

[In Progress] Added API Test for Metadata retrieval #43

Open imjalpreet opened 8 years ago

imjalpreet commented 8 years ago

@oparoz I have written the code for the API test.

Can you please check it?

imjalpreet commented 8 years ago

@oparoz I am facing the following error: [InvalidArgumentException]

oparoz commented 8 years ago

I'll take a look, but don't forget to enable the api suite in travis or it won't be able to test use your tests.

oparoz commented 8 years ago

I'm not even getting that error. It stops at " [PHPUnit_Framework_Exception] getimagesize(): Read error!"

imjalpreet commented 8 years ago

@oparoz I am not getting any error like that.

Also, can you explain how does the metadata get stored in database of these test images?

oparoz commented 8 years ago

Also, can you explain how does the metadata get stored in database of these test images?

The same way it does when a user uploads images, the hook is triggered and the data extracted.

oparoz commented 8 years ago

Looking at the image path, it's not an image path, it's a folder path, so that won't work. But it seems there is a bigger problem as the user tester doesn't seem to have any files in his account.

"app":"MediaMetadata","message":"Image Path: \/public_html\/data\/tester"

oparoz commented 8 years ago

I have an idea of why it fails, give me a few minutes

oparoz commented 8 years ago

OK, you'll need to also include the CheckTestUsersCest class. That's where users are actually created. We should improve that in the future, if possible.

Now I ran into another error, but you should be able to fix it:

[PHPUnit_Framework_Exception] array_key_exists() expects parameter 2 to be array, null given

That's in this method

//Date Created
        if(array_key_exists('EXIFData', $metadata) && array_key_exists('dateCreated', $metadata['EXIFData'])) {
            $imageDimension->setDateCreated($metadata['EXIFData']['dateCreated']);
        }
oparoz commented 8 years ago

In codeception.yml, you need to enable the test server.

See Gallery+ for the example.

imjalpreet commented 8 years ago

I have enabled it but now it is giving an error in Travis.

imjalpreet commented 8 years ago

@oparoz It is showing error in the .nomedia test file that we have used. What can be done regarding this?

oparoz commented 8 years ago

Easy, you need to upload it ;)

imjalpreet commented 8 years ago

Phew! Sorry. Uploaded it now.

imjalpreet commented 8 years ago

@oparoz The error that is currently shown in Travis now is that Class(ImageDimension) cannot be redeclared in storeMetadata class, but it is necessary for that test to pass. How can that be corrected?

imjalpreet commented 8 years ago

@oparoz Any idea from your side on how to resolve this issue?

oparoz commented 8 years ago

I don't have that error. You route doesn't seem to work. Have you tested your API with a browser?

oparoz commented 8 years ago

You don't have a route to the API

oparoz commented 8 years ago

And you don't have the correct phpdoc set for your API controller

oparoz commented 8 years ago

You need to understand how the PHPdoc system is working https://docs.nextcloud.com/server/10/developer_manual/app/controllers.html https://docs.nextcloud.com/server/10/developer_manual/app/api.html

imjalpreet commented 8 years ago

@oparoz,

I don't have that error. You route doesn't seem to work. Have you tested your API with a browser?

Sorry, I forgot to test it with a browser while trying to write the tests.
But as you have pointed out that I don't have the route to API, I will add the route and update the PHPDoc and then test it in the browser.

imjalpreet commented 8 years ago

@oparoz Will this route be correct for the API?

[
    'name' => 'metadata_api#get_metadata',
    'url'  => '/api/metadata/{fileList}',
    'verb' => 'GET'
],
oparoz commented 8 years ago

Yes, but it's incomplete. Look at the API example in the doc.

imjalpreet commented 8 years ago

@oparoz Okay, I will check and get back to you

imjalpreet commented 8 years ago

@oparoz Are you talking about the requirements?

imjalpreet commented 8 years ago

Also, what is wrong with the PHPDoc of the API controller? Do I have to add @CORS and @NoCSRFRequired?

imjalpreet commented 8 years ago

@oparoz I am getting this message when I am trying to test in the browser: {"message":"CORS requires basic auth"}

oparoz commented 8 years ago

Also, what is wrong with the PHPDoc of the API controller? Do I have to add @CORS and @NoCSRFRequired?

I think the documentation is quite clear and you have a working example with Gallery+

Everything you need is on this page: https://docs.nextcloud.com/server/10/developer_manual/app/api.html

imjalpreet commented 8 years ago

@oparoz,

I think the documentation is quite clear and you have a working example with Gallery+

Everything you need is on this page: https://docs.nextcloud.com/server/10/developer_manual/app/api.html

Do I have to modify any of the CORS header?

oparoz commented 8 years ago

Do I have to modify any of the CORS header?

No, but you need to follow the rest of the instructions.

imjalpreet commented 8 years ago

No, but you need to follow the rest of the instructions.

The PHPdoc on your method does not follow the guidelines

Sorry, I thought I followed them. I will look at it again.

Your routes file is missing the CORS entry

I will look into this also.

I will try to correct them and push the code soon

imjalpreet commented 8 years ago

@oparoz I have looked at the Gallery App. I found out one thing:

Is this the CORS entry you were talking about? 'name' => 'author_api#preflighted_cors', 'url' => '/api/1.0/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+')

Also, if this is that , then do I have to include configcontroller or configapicontroller, which is the case with gallery?

imjalpreet commented 8 years ago

Or I can add that route to metadata api?

oparoz commented 8 years ago

Is this the CORS entry you were talking about?

Yes.

Make it match the URL in the 1st route you're going to use.

oparoz commented 8 years ago

Did you manage to get it to work?

imjalpreet commented 8 years ago

I am working on it. I will get back to you with the code by today evening. Actually, it got a little delayed due to some university assignments.

oparoz commented 8 years ago

No worries. On the positive side, once fixed, the process works. Unfortunately, the data returned is wrong (0,0 for the size), so we'll still have to investigate why that happens

imjalpreet commented 8 years ago

That's great. Once, I am able to fix it, I will look into the size issue.

imjalpreet commented 8 years ago

@oparoz I am getting some errors in travis, can you check why?

Also, since yesterday, I am getting [InvalidArgumentException] error when I am trying to run API tests on my system.

imjalpreet commented 8 years ago

@oparoz I think I have written the correct URL but still its wrong somewhere. Can you check it?

imjalpreet commented 8 years ago

@oparoz I am not getting the error in unit tests that is being displayed on travis. All the unit tests are passing on my system. And there hasn't been any change in the unit tests that they have started to fail now. Its surprising to me.

oparoz commented 8 years ago

Yeah, I don't understand... I've now cleared the caches to see if it helps.

Make sure you pull my changes before adding new commits. But if it works on your setup now, then you can see the problem with the test. There is no metadata stored in the DB.

oparoz commented 8 years ago

OK the failed tests are because of ownCloud master. We're targeting 9.1 for now and we'll see what to do once this works properly.

imjalpreet commented 8 years ago

Okay.

imjalpreet commented 8 years ago

@oparoz But now the error in API tests is that the JSON did not match. But I don't understand how it is getting the height and width as 100, 100 after extracting from the image whereas the size is 379, 300.

oparoz commented 8 years ago

Well, it's 100 on Travis, but here it's 0, so there is something not working properly with the hook or the test setup

oparoz commented 8 years ago

Any progress?

imjalpreet commented 8 years ago

@oparoz I could not do much the last 3-4 days, as I had exams till today evening. I will give an update by tomorrow.

oparoz commented 8 years ago

OK, take some rest and let's try to get this done early next week

imjalpreet commented 8 years ago

@oparoz I am sorry for the delay. I will try to complete it soon.

oparoz commented 8 years ago

Any news?