Skip to content
This repository has been archived by the owner on May 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #24 from rodgomes/master
Browse files Browse the repository at this point in the history
OPT remove slug from credential
  • Loading branch information
rodgomes authored Mar 18, 2019
2 parents d754fb0 + 577fe3f commit fa99289
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion katka/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ApplicationAdmin(WithUsernameAdminModel):

@admin.register(Credential)
class CredentialAdmin(WithUsernameAdminModel):
fields = ('name', 'slug', 'credential_type', 'team')
fields = ('name', 'credential_type', 'team')


@admin.register(CredentialSecret)
Expand Down
21 changes: 21 additions & 0 deletions katka/migrations/0011_auto_20190318_0806.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.1.7 on 2019-03-18 08:06

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('katka', '0010_rename_scmtype'),
]

operations = [
migrations.AlterUniqueTogether(
name='credential',
unique_together=set(),
),
migrations.RemoveField(
model_name='credential',
name='slug',
),
]
4 changes: 0 additions & 4 deletions katka/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ def __str__(self): # pragma: no cover

class Credential(AuditedModel):
public_identifier = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
slug = KatkaSlugField()
name = models.CharField(max_length=100)
credential_type = models.CharField(max_length=50)
team = models.ForeignKey(Team, on_delete=models.CASCADE)

class Meta:
unique_together = ('team', 'slug')

def __str__(self): # pragma: no cover
return f'{self.credential_type}/{self.name}'

Expand Down
2 changes: 1 addition & 1 deletion katka/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CredentialSerializer(serializers.ModelSerializer):

class Meta:
model = Credential
fields = ('public_identifier', 'name', 'slug', 'team')
fields = ('public_identifier', 'name', 'team')


class CredentialSecretSerializer(serializers.ModelSerializer):
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def deactivated_project(team, project):

@pytest.fixture
def my_credential(team):
credential = models.Credential(name='System user X', slug='SUX', team=team)
credential = models.Credential(name='System user X', team=team)
with username_on_model(models.Credential, 'initial'):
credential.save()

Expand All @@ -93,7 +93,7 @@ def my_credential(team):

@pytest.fixture
def my_other_credential(team):
credential = models.Credential(name='System user other', slug='SUO', team=team)
credential = models.Credential(name='System user other', team=team)
with username_on_model(models.Credential, 'initial'):
credential.save()

Expand All @@ -102,7 +102,7 @@ def my_other_credential(team):

@pytest.fixture
def not_my_credential(not_my_team):
credential = models.Credential(name='System user D', slug='SUD', team=not_my_team)
credential = models.Credential(name='System user D', team=not_my_team)
with username_on_model(models.Credential, 'initial'):
credential.save()

Expand All @@ -111,7 +111,7 @@ def not_my_credential(not_my_team):

@pytest.fixture
def deactivated_credential(team):
credential = models.Credential(name='System user deactivated', slug='SUDA', team=team)
credential = models.Credential(name='System user deactivated', team=team)
credential.deleted = True
with username_on_model(models.Credential, 'initial'):
credential.save()
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_credential_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_partial_update(self, client, team, credential):

def test_create(self, client, team):
url = f'/credentials/'
data = {'name': 'System User Y', 'slug': 'SUY', 'team': team.public_identifier}
data = {'name': 'System User Y', 'team': team.public_identifier}
response = client.post(url, data, content_type='application/json')
assert response.status_code == 403

Expand Down Expand Up @@ -83,15 +83,15 @@ def test_delete(self, client, logged_in_user, team, credential):

def test_update(self, client, logged_in_user, team, credential):
url = f'/credentials/{credential.public_identifier}/'
data = {'name': 'System user Y', 'slug': 'SUY', 'team': team.public_identifier}
data = {'name': 'System user Y', 'team': team.public_identifier}
response = client.put(url, data, content_type='application/json')
assert response.status_code == 200
p = models.Credential.objects.get(pk=credential.public_identifier)
assert p.name == 'System user Y'

def test_update_nonexistent_team(self, client, logged_in_user, team, credential):
url = f'/credentials/{credential.public_identifier}/'
data = {'name': 'System User Y', 'slug': 'SUY', 'team': '00000000-0000-0000-0000-000000000000'}
data = {'name': 'System User Y', 'team': '00000000-0000-0000-0000-000000000000'}
response = client.put(url, data, content_type='application/json')
assert response.status_code == 403

Expand All @@ -106,7 +106,7 @@ def test_partial_update(self, client, logged_in_user, team, credential):
def test_create(self, client, logged_in_user, team, credential):
before_count = models.Credential.objects.count()
url = f'/credentials/'
data = {'name': 'System User Y', 'slug': 'SUY', 'team': team.public_identifier}
data = {'name': 'System User Y', 'team': team.public_identifier}
response = client.post(url, data=data, content_type='application/json')
assert response.status_code == 201
models.Credential.objects.get(name='System User Y')
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_save_stores_username(self, mock_request, project, scm_repository):
class TestCredentialAdmin:
def test_save_stores_username(self, mock_request, team):
c = CredentialAdmin(Credential, AdminSite())
obj = Credential(name='Credential D', slug='CRED', team=team)
obj = Credential(name='Credential D', team=team)
c.save_model(mock_request, obj, None, None)

assert obj.created_username == 'mock1'
Expand Down

0 comments on commit fa99289

Please sign in to comment.