1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00
Files
peeringdb-peeringdb/tests/test_api_cache.py
Matt Griswold ba6f9b6432 Qu1003 (#621)
* use new peeringdb client (1.0.0) for pdb_load_data sync (#599)

* drop django-mobi for lack of py3/dj2 support (#492)
remove django-forms-bootstrap for lack of py3/dj2 support (#492)

* black formatted

* django2.2 and py3 upgrade (#492)

* drop ixlans (#21) ui and api changes

* drop local_asn (#168)

* org search (#193)

* phone number validation (#50)

* implement help text tooltips (#228)

* Mark own ASN as transit-free (#394)

* py3 fix for `pdb_migrate_ixlans` command when writing migration report

* pdb_migrate_ixlans: properly handle py3 Runtime error if ixlan dict changes during iteration

* set rest DEFAULT_SCHEMA_CLASS to coreapi to fix swagger apidocs
fix migration 0027 missing from facsimile manifest

* fix swagger doc strings

* fix tests that were broken from api doc fixes

* fix UniqueFieldValidator for netixlan ipaddress validation that broke during django/drf upgrade

* fix org merge tool layout issues

* travis config

* update pipfile and lock

* black formatting

* update travis dist

* beta mode banner (#411)

* add beta banner template (#411)

* automatically scheduled sync may not always be on, add a flag that lets us reflect that state in the beta banner message
clean up beta banner implementation (#411)

* add tests for beta banner (#411)
2020-01-08 13:29:58 -06:00

105 lines
3.2 KiB
Python

import pytest
import json
import tempfile
import os
import datetime
import re
from django.test import TestCase
from django.contrib.auth.models import Group
from django.core.management import call_command
from django.conf import settings
import peeringdb_server.models as models
import peeringdb_server.management.commands.pdb_api_test as api_test
from . import test_api as api_tests
import django_namespace_perms as nsp
def setup_module(module):
api_tests.setup_module(module)
def teardown_module(module):
api_tests.teardown_module(module)
class APICacheTests(TestCase, api_test.TestJSON, api_test.Command):
"""
Runs the api test after generating cache files and enabling
api cache
You can find the logic / definition of those tests in
peeringdb_server.manangement.commands.pdb_api_test
This simply extends the command and testcase defined for it
but uses a special RestClient that sends requests to the
rest_framework testing api instead of a live server.
"""
# we want to use this rest-client for our requests
rest_client = api_tests.DummyRestClient
# The db will be empty and at least one of the tests
# requires there to be >100 organizations in the database
# this tells the test to create them
create_extra_orgs = 110
@classmethod
def setUpTestData(cls):
# create user and guest group
guest_group = Group.objects.create(name="guest")
user_group = Group.objects.create(name="user")
guest_user = models.User.objects.create_user(
"guest", "guest@localhost", "guest"
)
guest_group.user_set.add(guest_user)
nsp.models.GroupPermission.objects.create(
group=guest_group, namespace="peeringdb.organization", permissions=0x01
)
nsp.models.GroupPermission.objects.create(
group=user_group, namespace="peeringdb.organization", permissions=0x01
)
nsp.models.GroupPermission.objects.create(
group=user_group,
namespace="peeringdb.organization.{}".format(settings.SUGGEST_ENTITY_ORG),
permissions=0x04,
)
nsp.models.GroupPermission.objects.create(
group=user_group,
namespace="peeringdb.organization.*.network.*.poc_set.users",
permissions=0x01,
)
# prepare api test data
cls.prepare()
settings.API_CACHE_ROOT = tempfile.mkdtemp()
settings.API_CACHE_LOG = os.path.join(settings.API_CACHE_ROOT, "log.log")
super_user = models.User.objects.create_user(
"admin", "admin@localhost", "admin"
)
super_user.is_superuser = True
super_user.is_staff = True
super_user.save()
# generate cache files
now = datetime.datetime.now() + datetime.timedelta(days=1)
call_command("pdb_api_cache", date=now.strftime("%Y%m%d"))
def setUp(self):
settings.API_CACHE_ALL_LIMITS = True
settings.API_CACHE_ENABLED = True
super(APICacheTests, self).setUp()
def tearDown(self):
settings.API_CACHE_ALL_LIMITS = False
settings.API_CACHE_ENABLED = False
super(APICacheTests, self).tearDown()