#1644 Checking uniqueness of the display_name before creating a group
Merged by pingou. Opened by rahulbajaj.
rahulbajaj/pagure UniqueNames  into  master

Download 1644.patch

We have an unique constraint on the display name of a group, however,
if you try creating a group with a display_name that is already taken,
we do not inform you of this, making it hard to guess.
This patch checks for the uniqueness of the display_name :)

Also added the required unit-tests :)

Fixes: https://pagure.io/pagure/issue/1633

I am just thinking out loud , I guess this message sounds a little weird , how about
The group name is already taken please select a different name or something on those lines.

Hey, so for same group name we already have a message that says : " There is already a group with created". I have changed the message for same display_name. To keep consistency i have written such a message, but if it sounds very weird to all then i shall change it :)

@pingou 's call :smile:

The issue is that the error you catch here can be due to a group with the same display name or anything related to the DB, so you actually do not know why it failed.

So before discussing the error message, we should fix the logic. This section of the code should remain as is, what we need to do basically is adding a check before the group is created for the uniqueness of the display_group. Maybe having it raise a PagureException which would contain the error message.

Agreed sounds really good and organized !

rebased

rebased

@pingou corrected the logic :) all looks good ?

rebased

rebased

The idea looks good but I can tell, just looking at the change, that while it works as is, there is an entire section of code you added that is never being used :)

We should also really look at adding unit-tests for this kind of changes, do you want to do it?

The idea looks good but I can tell, just looking at the change, that while it works as is, there is an entire section of code you added that is never being used :)

That is a good thing right ?

We should also really look at adding unit-tests for this kind of changes, do you want to do it?

So, I have never written an unit test earlier and I am really keen to learn. Can you guide me, how to write unit tests. Can you provide me with some reference links that would help me do the same ?

an entire section of code you added that is never being used :)

That is a good thing right ?

How would code never being used a good thing? :)

Regarding the unit-tests, they are all in the tests/ folder, you probably want to look at: test_add_group in tests/test_pagure_lib.py :)

rebased

That one won't please pep8 :)

rebased

rebased

1 new commit added

  • Adding unit-test for checking uniqueness of the display_name

rebased

rebased

rebased

@pingou , the test is looking good ?

It does :)

Let's rebase and merge :)

rebased

Pull-Request has been merged by pingou

Metadata