Skip to content

Commit

Permalink
Tests for authentication
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   .gitignore
	modified:   authentication/apis.py
	modified:   authentication/migrations/0001_initial.py
	deleted:    authentication/migrations/0002_newuser.py
	modified:   authentication/services.py
	new file:   biocompute/migrations/0001_initial.py
	modified:   docs/refactor.md
	new file:   prefix/migrations/0001_initial.py
	modified:   search/selectors.py
	new file:   test.json
	new file:   tests/fixtures/old_test_data.json
	modified:   tests/fixtures/test_data.json
	deleted:    tests/test_database.py
	deleted:    tests/test_fixtures.py
	deleted:    tests/test_models
	modified:   tests/test_views/test_api_account_activate.py
	renamed:    tests/test_views/test_api_accounts_describe.py -> tests/test_views/test_api_account_describe.py
	modified:   tests/test_views/test_api_auth_add.py
	modified:   tests/test_views/test_api_auth_reset_token.py
	deleted:    tests/test_views/test_api_groups_group_info.py
	deleted:    tests/test_views/test_api_groups_modify.py
	deleted:    tests/test_views/test_api_objects.py
	deleted:    tests/test_views/test_api_objects_drafts_create.py
	deleted:    tests/test_views/test_api_objects_drafts_modify.py
	deleted:    tests/test_views/test_api_objects_drafts_publish.py
	deleted:    tests/test_views/test_api_objects_search.py
	deleted:    tests/test_views/test_api_objects_validate.py
	deleted:    tests/test_views/test_api_prefixes_create.py
	deleted:    tests/test_views/test_api_prefixes_token.py
	deleted:    tests/test_views/test_get_object_id_draft.py
	deleted:    tests/test_views/test_get_objectid.py
	deleted:    tests/test_views/test_published_object_by_id.py
	modified:   token.json
  • Loading branch information
HadleyKing committed Mar 14, 2024
1 parent b0c2d6e commit 6366b0b
Show file tree
Hide file tree
Showing 33 changed files with 8,258 additions and 6,380 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ server.conf
static/
# JetBrains IDEs
.idea/
backups
3 changes: 1 addition & 2 deletions authentication/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from api.scripts.utilities.UserUtils import UserUtils
from authentication.models import Authentication, NewUser
from authentication.selectors import (
check_user_email,
Expand Down Expand Up @@ -534,7 +533,7 @@ def post(self, request):
Token.objects.create(user=request.user)
return Response(
status=status.HTTP_200_OK,
data=UserUtils().get_user_info(username=request.user)
data=get_user_info(user=request.user)
)

except Exception as error:
Expand Down
14 changes: 13 additions & 1 deletion authentication/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by Django 3.2.10 on 2023-03-27 20:46
# Generated by Django 3.2.13 on 2024-03-14 13:52

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):
Expand All @@ -14,6 +15,17 @@ class Migration(migrations.Migration):
]

operations = [
migrations.CreateModel(
name='NewUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email', models.EmailField(max_length=254)),
('temp_identifier', models.TextField(max_length=100)),
('token', models.TextField(blank=True, null=True)),
('hostname', models.TextField(blank=True, null=True)),
('created', models.DateTimeField(default=django.utils.timezone.now)),
],
),
migrations.CreateModel(
name='Authentication',
fields=[
Expand Down
25 changes: 0 additions & 25 deletions authentication/migrations/0002_newuser.py

This file was deleted.

7 changes: 4 additions & 3 deletions authentication/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.contrib.auth.models import User, Group
from django.core.mail import send_mail
from rest_framework import exceptions, status, serializers
from rest_framework.authtoken.models import Token
from rest_framework.response import Response
from rest_framework_jwt.authentication import BaseAuthentication
from rest_framework_jwt.settings import api_settings
Expand Down Expand Up @@ -173,6 +174,7 @@ def send_new_user_email(user_info: dict) -> 0:
print("Email signal sent")
return 0

@transaction.atomic
def create_bcodb_user(email: str) -> User:
"""Create BCODB user
"""
Expand All @@ -183,10 +185,9 @@ def create_bcodb_user(email: str) -> User:
)
user.set_unusable_password()
user.full_clean()
Token.objects.create(user=user)
user.save()
user.groups.add(Group.objects.get(name="bco_drafter"))
user.groups.add(Group.objects.get(name="bco_publisher"))


return user


Expand Down
33 changes: 33 additions & 0 deletions biocompute/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.13 on 2024-03-14 13:52

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
('prefix', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Bco',
fields=[
('object_id', models.TextField(primary_key=True, serialize=False)),
('contents', models.JSONField()),
('state', models.CharField(choices=[('REFERENCED', 'referenced'), ('PUBLISHED', 'published'), ('DRAFT', 'draft'), ('DELETE', 'delete')], default='DRAFT', max_length=20)),
('last_update', models.DateTimeField()),
('access_count', models.IntegerField(default=0)),
('authorized_groups', models.ManyToManyField(blank=True, to='auth.Group')),
('authorized_users', models.ManyToManyField(blank=True, related_name='authorized_bcos', to=settings.AUTH_USER_MODEL)),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owned_bcos', to=settings.AUTH_USER_MODEL)),
('prefix', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='prefix.prefix')),
],
),
]
8 changes: 8 additions & 0 deletions docs/refactor.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@
## Items to look at later
- `authentication.apis.RegisterUserNoVerificationAPI` has no swagger or tests
- fix email and secrets
<<<<<<< Local Changes
- install a `test_template` for Swagger responses
- provide example values that are usable for testing APIs.
- certifying key for prefix as a JWT?
- owner = models.ForeignKey(
User,
on_delete=models.CASCADE,

- need tests for token
30 changes: 30 additions & 0 deletions prefix/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.2.13 on 2024-03-14 13:14

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Prefix',
fields=[
('prefix', models.CharField(max_length=5, primary_key=True, serialize=False)),
('certifying_key', models.TextField(blank=True, null=True)),
('created', models.DateTimeField(blank=True, default=django.utils.timezone.now, null=True)),
('description', models.TextField(blank=True, null=True)),
('authorized_groups', models.ManyToManyField(blank=True, related_name='authorized_prefix', to='auth.Group')),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, to_field='username')),
],
),
]
5 changes: 1 addition & 4 deletions search/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
Set of selector functions to handle searching the BCODB
"""

from api.models import BCO
from biocompute.models import Bco
from django.db.models import QuerySet
from django.db.models.query import QuerySet
from django.contrib.auth.models import User
from guardian.shortcuts import get_objects_for_user
from itertools import chain
from api.scripts.utilities.UserUtils import UserUtils

return_values = [
"contents",
Expand Down
Loading

0 comments on commit 6366b0b

Please sign in to comment.