Skip to content

Commit

Permalink
added new test file- api/auth/remove.py (#196)
Browse files Browse the repository at this point in the history
* unit tests

test_fixtures.py - Exports the database as a pytest fixture that can be used for testing

* Add files via upload

* New api test files

* Fixed test_api_accounts_describe
Changes to be committed:
	modified:   api/apps.py
	modified:   api/model/groups.py
	modified:   api/model/prefix.py
	deleted:    api/tests/test_bcos.json
	deleted:    api/tests/test_forms.py
	deleted:    api/tests/test_group_post_api.py
	deleted:    api/tests/test_model_bco.py
	deleted:    api/tests/test_model_groups.py
	deleted:    api/tests/test_model_prefix.py
	deleted:    api/tests/test_model_user.py
	deleted:    api/tests/test_prefix_post_api.py
	deleted:    api/tests/test_views.py
	deleted:    api/tests_automated.py
	modified:   api/views.py
	modified:   bcodb/settings.py
	renamed:    api/tests/__init__.py -> tests/__init__.py
	new file:   tests/fixtures/test_data.json
	modified:   tests/test_fixtures.py
	new file:   tests/test_views/__init__.py
	modified:   tests/test_views/test_api_accounts_describe.py

* Fix Bulk Publish function

Changes to be committed:
	modified:   api/scripts/method_specific/POST_api_objects_publish.py
	modified:   api/scripts/utilities/JsonUtils.py

* Add reset_token API

Issue #158

* Formatting for Add/Remove ORCID

updated dev DB
Related to biocompute-objects/portal_userdb#90
Changes to be committed:
	modified:   admin_only/db.sqlite3.dev
	modified:   authentication/apis.py

* Fix #134
Changes to be committed:
	modified:   authentication/services.py

* Bump django from 3.2.10 to 3.2.13

Bumps [django](https://github.com/django/django) from 3.2.10 to 3.2.13.
- [Release notes](https://github.com/django/django/releases)
- [Commits](django/django@3.2.10...3.2.13)

---
updated-dependencies:
- dependency-name: django
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* new test - auth/remove

* conflicts solved and merged

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Hadley King <[email protected]>
Co-authored-by: hadleyking <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Jul 27, 2023
1 parent a73c897 commit 5ee98b4
Show file tree
Hide file tree
Showing 29 changed files with 7,291 additions and 1,351 deletions.
Binary file added admin_only/db.sqlite3
Binary file not shown.
7 changes: 5 additions & 2 deletions api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Source: https://docs.djangoproject.com/en/3.2/ref/applications/#django.apps.AppConfig.ready
"""

import sys
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from api.signals import populate_models
Expand All @@ -15,7 +16,9 @@ class ApiConfig(AppConfig):

default_auto_field = "django.db.models.AutoField"
name = "api"

def ready(self):
"""Create the anonymous user if they don't exist."""
post_migrate.connect(populate_models, sender=self)

if not 'test' in sys.argv:
post_migrate.connect(populate_models, sender=self)
25 changes: 14 additions & 11 deletions api/model/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Functions for operations with groups
"""

import sys
from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import Group, User
Expand Down Expand Up @@ -430,14 +431,16 @@ def associate_user_group(sender, instance, created, **kwargs):
if the user isn't anon or the already existent bco_drafter or bco_publisher.
"""

if created:
Group.objects.create(name=instance)
group = Group.objects.get(name=instance)
group.user_set.add(instance)
if instance.username not in ["anon", "bco_drafter", "bco_publisher", "AnonymousUser"]:
User.objects.get(username=instance).groups.add(
Group.objects.get(name="bco_drafter")
)
User.objects.get(username=instance).groups.add(
Group.objects.get(name="bco_publisher")
)
if not 'test' in sys.argv:
if created:
print(instance)
Group.objects.create(name=instance)
group = Group.objects.get(name=instance)
group.user_set.add(instance)
if instance.username not in ["anon", "bco_drafter", "bco_publisher", "AnonymousUser"]:
User.objects.get(username=instance).groups.add(
Group.objects.get(name="bco_drafter")
)
User.objects.get(username=instance).groups.add(
Group.objects.get(name="bco_publisher")
)
57 changes: 30 additions & 27 deletions api/model/prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


import re
import sys
from django.db import models
from django.contrib.auth.models import Group, Permission, User
from django.db.models.signals import post_save, post_delete, pre_save
Expand Down Expand Up @@ -689,30 +690,32 @@ def create_permissions_for_prefix(sender, instance=None, **kwargs):
# max_n_members=-1,
# owner_user=User.objects.get(username='wheel')
# )
owner_user = User.objects.get(username=instance.owner_user)
owner_group = Group.objects.get(name=instance.owner_group_id)
drafters = Group.objects.get(name=instance.prefix.lower() + "_drafter")
publishers = Group.objects.get(name=instance.prefix.lower() + "_publisher")

try:
for perm in ["add", "change", "delete", "view", "draft", "publish"]:
Permission.objects.create(
name="Can " + perm + " BCOs with prefix " + instance.prefix,
content_type=ContentType.objects.get(app_label="api", model="bco"),
codename=perm + "_" + instance.prefix,
)
new_perm = Permission.objects.get(codename=perm + "_" + instance.prefix)
owner_user.user_permissions.add(new_perm)
owner_group.permissions.add(new_perm)
publishers.permissions.add(new_perm)
if perm == "publish":
pass
else:
drafters.permissions.add(new_perm)

except PermErrors.IntegrityError:
# The permissions already exist.
pass

if not 'test' in sys.argv:
owner_user = User.objects.get(username=instance.owner_user)
owner_group = Group.objects.get(name=instance.owner_group_id)
drafters = Group.objects.get(name=instance.prefix.lower() + "_drafter")
publishers = Group.objects.get(name=instance.prefix.lower() + "_publisher")

try:
for perm in ["add", "change", "delete", "view", "draft", "publish"]:
Permission.objects.create(
name="Can " + perm + " BCOs with prefix " + instance.prefix,
content_type=ContentType.objects.get(app_label="api", model="bco"),
codename=perm + "_" + instance.prefix,
)
new_perm = Permission.objects.get(codename=perm + "_" + instance.prefix)
owner_user.user_permissions.add(new_perm)
owner_group.permissions.add(new_perm)
publishers.permissions.add(new_perm)
if perm == "publish":
pass
else:
drafters.permissions.add(new_perm)

except PermErrors.IntegrityError:
# The permissions already exist.
pass


@receiver(post_save, sender=Prefix)
Expand All @@ -727,9 +730,9 @@ def create_counter_for_prefix(sender, instance=None, created=False, **kwargs):
instance: api.model.prefix.Prefix
created: bool
"""

if created:
prefix_table.objects.create(n_objects=1, prefix=instance.prefix)
if not 'test' in sys.argv:
if created:
prefix_table.objects.create(n_objects=1, prefix=instance.prefix)


@receiver(post_delete, sender=Prefix)
Expand Down
Loading

0 comments on commit 5ee98b4

Please sign in to comment.