1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00
Files
peeringdb-peeringdb/tests/test_stats.py
Matt Griswold abe3e78d50 Dotf fixes (#781)
* fix issue where ix-f import would raise suggestions ipaddresses not that ixlan (#764)

* IX-F Suggestions: Leaving the editor and returning to it via back button issues (#765)

* IX-F importer: Clicking "Preview" (IXP Update Tools) on /net/ page resulted in 170 ticket resolutions (#769)
More robust testing

* black formatting (was lost after pyupgrade)

* Add regex searching to deskpro ticket subjects

* Change operational error

* IX-F suggestions: consolidate delete+add (#770)

* Add reset functions to commandline tool

* Fix commandline tool bugs

* Fix reset commandline tool bugs

* add commandline tool

* Ixlan needs to be set for import commandline tool

* Add email model

* Add admin view to emails

* Allow network and ix to be null

* save emails as part of ixf import

* Add email model

* Add email delete

* add iregex search and better comments

* fix ixlan selection for import

* redefine migration dependencies for this branch

* only enable search w start and end char

* Add caption to regex search

* Remove delete all ixfmemberdata option

* [beta] IX-F importer: don't bother about missing IPv{4,6} address when network is not doing IPv{4,6} (#771)

* Add cmdline tests

* Resolve email conflicts

* Add cmd tool reset tests

* add autocomplete to commandline tool

* Fix email bugs

* Fix email migrations

* Fix typos

* [beta] IX-F importer: prevent Admin Committee overload by initially limiting importer to IXes enabled by AC (#772)

* Finalize regex search for emails and deskprotickets

* Fix keyword bug

* fix typo

* protocol-conflict will now be handled in the notification consolidation

771 changes where if the network indicates neither ipv4 nor ipv6 support, it is handled as supporting both (eg the network didnt configure these at all)

realised that the importer command re instantiates the `Importer` class for each ixlan it processes, so moved the sending of consolidated notifications (#772) out of the `update` function and into the command itself after its done processing all the ixlans. This means for tests you will need to call `importer.notify_proposals` after `importer.update` to test the consolidated notifications.

fixed several MultipleObjectsReturned errors when network switch protocol support in between imports

* should be checking for "ix" in the form data (#773)

* Fix cmd ixf tests

* fix issue in log_peer

* Add commit check for reset tool

* fix importer bugs

* remove dupe IXFImportEmail definition

* ixfimportemail support ix__name and net__name searching

* ticket resolution responses

* Add commit to command ixf import changes

* fix modify entry header

* remove whitespace in notification about remote data changes

* Begin updating tests

* ixf-import command line tool to queue

* refactor conflict inserts

* Update import protocol tests, including tests for 770

* More test edits

* Change cmd tests

* better ixfmemberdata error handling and fix some test data

* dont reset the same ixfmemberdata requirement

* fix many bugs add many tests

* remove debug message

* fix bug during import when consolidating delete+add

* fix perfomance issue in IXFMemberData listing

* dont show reset flags on prod env

* Add regex search tests

* Add 772 tests

* remove debug output

* fix `test_resolve_deskpro_ticket` test

* black formatting

* remove dupe import

* fix issue with unique constraint error handling

* add test for ixp / network ip protocol notification

* add missing test data

Co-authored-by: Stefan Pratter <stefan@20c.com>
Co-authored-by: Elliot Frank <elliot@20c.com>
2020-07-27 04:36:27 +00:00

77 lines
2.0 KiB
Python

import io
import datetime
import pytest
from .util import ClientCase, Group
from django.core.management import call_command
from django.conf import settings
from django.contrib.auth import get_user_model
from peeringdb_server.models import REFTAG_MAP, UTC, Network
from peeringdb_server.stats import stats
DATE_PAST = datetime.datetime(year=2019, month=11, day=1)
def setup_data():
call_command("pdb_generate_test_data", limit=3, commit=True)
date_past = DATE_PAST.replace(tzinfo=UTC())
# one object of each type moved to the past
for tag in ["fac", "net", "org", "ix"]:
for obj in REFTAG_MAP[tag].objects.all():
obj.created = obj.updated = date_past
obj.save()
break
# create users
User = get_user_model()
for i in range(1, 7):
User.objects.create_user(f"user_{i}", f"user_{i}@localhost", "secret")
# move users 4, 5, 6 to the past
User.objects.filter(pk__in=[4, 5, 6]).update(created=date_past)
# verify all users except 1 and 4
for user in User.objects.exclude(pk__in=[1, 4]):
user.set_verified()
@pytest.mark.django_db
def test_generate_for_past_date(db, data_stats_past):
output = io.StringIO()
setup_data()
call_command("pdb_stats", date=DATE_PAST.strftime("%Y%m%d"), stdout=output)
assert output.getvalue() == data_stats_past.txt
@pytest.mark.django_db
def test_generate_for_current_date(db, data_stats_current):
output = io.StringIO()
setup_data()
call_command("pdb_stats", stdout=output)
assert data_stats_current.txt in output.getvalue()
@pytest.mark.django_db
def test_global_stats(db, data_stats_global):
setup_data()
# test_automated_network_count shows that "automated networks" counts
# networks w allow_ixp_update=True
if data_stats_global.name == "test_automated_network_count":
network = Network.objects.first()
network.allow_ixp_update = False
network.save()
global_stats = stats()
assert global_stats == data_stats_global.expected