This repository has been archived by the owner on May 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from kpn/feature/credentials-model
NEW - Added Credential model/view
- Loading branch information
Showing
10 changed files
with
229 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Generated by Django 2.1.5 on 2019-02-11 02:52 | ||
|
||
import uuid | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
import katka.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('katka', '0002_add_project_and_slug'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Credential', | ||
fields=[ | ||
('created', models.DateTimeField(auto_now_add=True)), | ||
('created_username', katka.fields.AutoUsernameField(max_length=50)), | ||
('modified', models.DateTimeField(auto_now=True)), | ||
('modified_username', katka.fields.AutoUsernameField(max_length=50)), | ||
('status', models.CharField(choices=[('active', 'active'), ('inactive', 'inactive')], default='active', max_length=50)), | ||
('public_identifier', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('slug', katka.fields.KatkaSlugField(max_length=10)), | ||
('name', models.CharField(max_length=100)), | ||
('credential_type', models.CharField(max_length=50)), | ||
('team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='katka.Team')), | ||
], | ||
), | ||
migrations.AlterField( | ||
model_name='project', | ||
name='slug', | ||
field=katka.fields.KatkaSlugField(max_length=10), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='project', | ||
unique_together={('team', 'slug')}, | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='credential', | ||
unique_together={('team', 'slug')}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Django>=2.1,<3.0 | ||
#Django>=2.1,<3.0 | ||
Django==2.1.5 # pin to this version because 2.1.6 has a missing migration which breaks the build: https://code.djangoproject.com/ticket/30174#ticket | ||
djangorestframework>=3.9.0,<4.0.0 | ||
django-encrypted-model-fields>=0.5.8,<1.0.0 | ||
drf-nested-routers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
from uuid import UUID | ||
|
||
import pytest | ||
from katka import models | ||
from katka.constants import STATUS_INACTIVE | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestCredentialViewSetUnauthenticated: | ||
""" | ||
When a user is not logged in, no group information is available, so nothing is returned. | ||
For listing, that would be an empty list for other operations, an error like the object could | ||
not be found, except on create (you need to be part of a group and anonymous users do not have any) | ||
""" | ||
|
||
def test_list(self, client, team, credential): | ||
response = client.get(f'/team/{team.public_identifier}/credential/') | ||
assert response.status_code == 200 | ||
parsed = response.json() | ||
assert len(parsed) == 0 | ||
|
||
def test_list_unknown_team(self, client, team, credential): | ||
response = client.get('/team/00000000-0000-0000-0000-000000000000/credential/') | ||
assert response.status_code == 200 | ||
parsed = response.json() | ||
assert len(parsed) == 0 | ||
|
||
def test_get(self, client, team, credential): | ||
response = client.get(f'/team/{team.public_identifier}/credential/{credential.public_identifier}/') | ||
assert response.status_code == 404 | ||
|
||
def test_delete(self, client, team, credential): | ||
response = client.delete(f'/team/{team.public_identifier}/credential/{credential.public_identifier}/') | ||
assert response.status_code == 404 | ||
|
||
def test_update(self, client, team, credential): | ||
url = f'/team/{team.public_identifier}/credential/{credential.public_identifier}/' | ||
data = {'name': 'B-Team', 'group': 'group1'} | ||
response = client.put(url, data, content_type='application/json') | ||
assert response.status_code == 404 | ||
|
||
def test_partial_update(self, client, team, credential): | ||
url = f'/team/{team.public_identifier}/credential/{credential.public_identifier}/' | ||
response = client.patch(url, {'name': 'B-Team'}, content_type='application/json') | ||
assert response.status_code == 404 | ||
|
||
def test_create(self, client, team): | ||
url = f'/team/{team.public_identifier}/credential/' | ||
data = {'name': 'System User Y', 'slug': 'SUY'} | ||
response = client.post(url, data, content_type='application/json') | ||
assert response.status_code == 403 | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestCredentialViewSet: | ||
def test_list(self, client, logged_in_user, team, credential): | ||
response = client.get(f'/team/{team.public_identifier}/credential/') | ||
assert response.status_code == 200 | ||
parsed = response.json() | ||
assert len(parsed) == 1 | ||
assert parsed[0]['name'] == 'System user X' | ||
parsed_team = parsed[0]['team'] | ||
assert UUID(parsed_team['public_identifier']) == team.public_identifier | ||
assert parsed_team['slug'] == 'ATM' | ||
|
||
def test_get(self, client, logged_in_user, team, credential): | ||
response = client.get(f'/team/{team.public_identifier}/credential/{credential.public_identifier}/') | ||
assert response.status_code == 200 | ||
parsed = response.json() | ||
assert parsed['name'] == 'System user X' | ||
assert parsed['team']['slug'] == 'ATM' | ||
assert UUID(parsed['team']['public_identifier']) == team.public_identifier | ||
|
||
def test_get_excludes_inactive(self, client, logged_in_user, deactivated_team): | ||
response = client.get(f'/team/{deactivated_team.public_identifier}/') | ||
assert response.status_code == 404 | ||
|
||
def test_delete(self, client, logged_in_user, team, credential): | ||
response = client.delete(f'/team/{team.public_identifier}/credential/{credential.public_identifier}/') | ||
assert response.status_code == 204 | ||
p = models.Credential.objects.get(pk=credential.public_identifier) | ||
assert p.status == STATUS_INACTIVE | ||
|
||
def test_update(self, client, logged_in_user, team, credential): | ||
url = f'/team/{team.public_identifier}/credential/{credential.public_identifier}/' | ||
data = {'name': 'System user Y', 'slug': 'SUY'} | ||
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'/team/00000000-0000-0000-0000-000000000000/credential/{credential.public_identifier}/' | ||
data = {'name': 'System User Y', 'slug': 'SUY'} | ||
response = client.put(url, data, content_type='application/json') | ||
assert response.status_code == 404 | ||
|
||
def test_partial_update(self, client, logged_in_user, team, credential): | ||
url = f'/team/{team.public_identifier}/credential/{credential.public_identifier}/' | ||
data = {'name': 'System User Y'} | ||
response = client.patch(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_create(self, client, logged_in_user, team, credential): | ||
url = f'/team/{team.public_identifier}/credential/' | ||
response = client.post(url, {'name': 'System User Y', 'slug': 'SUY'}, content_type='application/json') | ||
assert response.status_code == 201 | ||
models.Credential.objects.get(name='System User Y') | ||
assert models.Credential.objects.count() == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters