Repository: Cloud-CV/EvalAI
Issue: Add test cases for model string functions where ever missing.
GitHub labels: easy_to_fix

backend

Each model has a `__unicode__` function. This function is present in many of the models. 

Presently test cases are missing for some model's `unicode` functions. This task addresses the same issue.

It first involves figuring out a list of all the models where its `__unicode__` function is present and its corresponding test case is not written. Then multiple PR can be raised per app which adds the tests for the same.

One such example of `unicode` function test is in `tests/unit/challenges/test_models.py`,  with the snippet

```
def test__str__(self):
        self.assertEqual(self.challenge.title, self.challenge.__str__())
```

@isht3 :  Are you willing to work on this ? This will give you a fair idea of how the models are organised and placed in apps.

@TroJan I would love to! 


@isht3 : Sure, go ahead. Let me know if you need any help

@TroJan A PR for each app would suffice, right?

If we haven't declared a `__str__()` method in the class, then how does `self.challenge.__str__()` work?

@isht3 : yeah a PR for each app would do.

So there are three functions namely `str`, `unicode` and `repr`. First str is looked(infact str is the first choice for python 3), then `unicode`(in python 2 this is the first choice) and then `repr`.

So in our case when `__str__` is called, python fallbacks to pickup `unicode`.

I hope this clears your doubt



Thanks, now its cleared! :+1: 

@isht3 : Can you list down all the apps where these changes are required. challenges app is done.

@TroJan In `Challenges`, `Leaderboard` model is to be completed, I found that a little hard because a lot of things like `Submission` and other classes had to be set up to test that data, and I'm working on it now.

On `Accounts`, there's this one small issue which is bothering me, while setting up `ProfileTestCase` and running the tests, this piece of code, 
```
    def setUp(self):
        super(ProfileTestCase, self).setUp()
        self.profile = Profile.objects.create(
                user=self.user,
                contact_number="2983191839",
                affiliation="testing"
            )
```

throws the following error.
```
IntegrityError: duplicate key value violates unique constraint "user_profile_user_id_key"
DETAIL:  Key (user_id)=(3) already exists.

```
 I suspect it has something to do with the test database entries. I have end sem coming up next week. Ill throw PR's in between. :+1: 

I didn't get your point of setting up classes. If you want to load your database with some values, we have a management command which does that job. You can invoke it by
```
python manage.py seed --settings=settings.dev
```

Regarding error, you are trying to create Profile object for a user whose Profile object already exists. Remember that profile object is a one to one mapping to user model, hence the unique constraint is throwing that error.

@TroJan This can be closed, yeah? Ill see if there's some other thing I can work on. By the way is there any prospect that I can intern for CloudCV?

@isht3 : thanks for the fix. You are doing good. I will get back to you in a day regarding the intern prospect. 

@TroJan Okay, thanks for considering. :)