unicef / kindly

GNU Affero General Public License v3.0
24 stars 17 forks source link

[Outreachy] Write Python Tests for Kindly API #59

Closed nathanfletcher closed 2 years ago

nathanfletcher commented 2 years ago

There should be at least a unit test especially for the API endpoints - /detect Anyone can feel free to pick this up.

sabinevidal commented 2 years ago

Hey @nathanfletcher ! I'd like to take this on. Will be able to get started on it tomorrow morning (GMT +2).

lacabra commented 2 years ago

Thanks @sabinevidal, this issue has been assigned to you

Ashara-kosi commented 2 years ago

Hi @sabinevidal

Would you like some assistance on this task? I would like to collaborate with you on this.

sabinevidal commented 2 years ago

Hi @Ashara-kosi That sounds amazing! ☺️ I've already started setting the tests up, but I'm about to log off for the night. I will publish what I've done first thing tomorrow morning so then you can jump into the new branch and we can collaborate! What time zone are you in? I'm GMT + 2 (South Africa).

Ashara-kosi commented 2 years ago

Alright, that is cool! @sabinevidal I'm GMT +1(Nigeria)

sabinevidal commented 2 years ago

Hey @Ashara-kosi I've just published my branch! https://github.com/sabinevidal/kindly/tree/api-unit-tests

You will need to run pip install pytest in your env, then in the main folder you can just run pytest and it will work. Ran across a problem, so hopefully you'll be able to help! When I run the tests as is they fail because they can't find the right model folder at this point in api.py (around line 108)

def process(inputText):
  ...
  model = AutoModelForSequenceClassification.from_pretrained("./model")

It's looking for the 'https://huggingface.co/models' url which isn't correct, it should be 'https://huggingface.co/cardiffnlp/twitter-roberta-base-offensive'. I managed to create a work around to at least get the tests working by replacing ./model with the correct endpoint... but obviously it shouldn't be like this πŸ˜… Any ideas?

Also any other tests you can think of? πŸ€”

Ashara-kosi commented 2 years ago

Hi @sabinevidal

I am unable to access your branch in your repo. Please send in a draft pr so I can access it on the main kindly repository

Thanks.

Ashara-kosi commented 2 years ago

Hello @sabinevidal

I have been able to resolve the error..apparently, the model was not referenced correctly.

The tests now pass!!!

sabinevidal commented 2 years ago

Hey @Ashara-kosi That's great! 😁 How did you change the reference?

@lacabra @nathanfletcher should we create unittests for the other endpoints at this point?

And what's best practice for the amount of examples to pass to the test? I've done manual for now testing one for offensive and one for not-offensive.

lacabra commented 2 years ago

@sabinevidal: Yes, it would be great to have tests for all available endpoints.

I would say that a best practice is to have one test that catches the expected behavior, and other tests that catch the various possible errors.

sabinevidal commented 2 years ago

@lacabra Ok, thought so - I'll finish creating the rest! Thanks!