from pytest import mark

from mysign_app.management.commands.seed import Command
from mysign_app.models import Company, DoorDevice, User
from mysign_app.tests.factories import CompanyFactory


@mark.django_db
def test_objects_are_seeded():
    # Run seeds
    Command().handle()

    assert Company.objects.count() == 20
    assert DoorDevice.objects.count() == 20

    assert User.objects.filter(email='<EMAIL>').count() == 1
    assert User.objects.filter(email='<EMAIL>').first().check_password('<PASSWORD>')

    assert User.objects.filter(email='<EMAIL>').count() == 1
    assert User.objects.filter(email='<EMAIL>').first().check_password('<PASSWORD>')
    assert User.objects.filter(email='<EMAIL>').first().company_id

    assert User.objects.filter(email='<EMAIL>').count() == 1
    assert User.objects.filter(email='<EMAIL>').first().check_password('<PASSWORD>')
    assert User.objects.filter(email='<EMAIL>').first().is_staff
    assert User.objects.filter(email='<EMAIL>').first().is_superuser


@mark.django_db
def test_database_is_cleared():
    CompanyFactory.create(name="really awesome company")

    # Run seeds
    Command().handle()

    assert Company.objects.filter(name="really awesome company").count() == 0


@mark.django_db
def test_production_seed():
    Command().handle(production=True)

    assert Company.objects.count() == 0
    assert DoorDevice.objects.count() == 0

    assert User.objects.count() == 1
    assert User.objects.first().check_password('<PASSWORD>')

from pytest import mark

from mysign_app.management.commands.seed import Command
from mysign_app.models import Company, DoorDevice, User
from mysign_app.tests.factories import CompanyFactory


@mark.django_db
def test_objects_are_seeded():
    # Run seeds
    Command().handle()

    assert Company.objects.count() == 20
    assert DoorDevice.objects.count() == 20

    assert User.objects.filter(email='<EMAIL>').count() == 1
    assert User.objects.filter(email='<EMAIL>').first().check_password('<PASSWORD>')

    assert User.objects.filter(email='<EMAIL>').count() == 1
    assert User.objects.filter(email='<EMAIL>').first().check_password('<PASSWORD>')
    assert User.objects.filter(email='<EMAIL>').first().company_id

    assert User.objects.filter(email='<EMAIL>').count() == 1
    assert User.objects.filter(email='<EMAIL>').first().check_password('<PASSWORD>')
    assert User.objects.filter(email='<EMAIL>').first().is_staff
    assert User.objects.filter(email='<EMAIL>').first().is_superuser


@mark.django_db
def test_database_is_cleared():
    CompanyFactory.create(name="really awesome company")

    # Run seeds
    Command().handle()

    assert Company.objects.filter(name="really awesome company").count() == 0


@mark.django_db
def test_production_seed():
    Command().handle(production=True)

    assert Company.objects.count() == 0
    assert DoorDevice.objects.count() == 0

    assert User.objects.count() == 1
    assert User.objects.first().check_password('<PASSWORD>')

# Run seeds # Run seeds