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
def test_update(client): company = CompanyFactory() client_login(client, company=company) company.name = 'New name' payload = payload_from_form(CompanyViewForm(instance=company)) payload['color'] = payload['color'][1:] response = client.post(reverse('company_index'), payload) assert response.status_code == 200
def test_update_other_company(client): company = CompanyFactory() client_login(client, company=company) other_company = CompanyFactory() other_company.name = 'New name' payload = payload_from_form(CompanyViewForm(instance=other_company)) response = client.post(reverse('company_index'), payload) assert response.status_code == 403
def test_logo_fallback(): company = CompanyFactory.build() assert company.logo assert company.logo_url_or_default() == company.logo.url company = CompanyFactory.build(logo=None) assert not company.logo assert company.logo_url_or_default() == '/static/mysign_app/logo-fallback.png'
def test_image_fallback(): company = CompanyFactory.build() assert company.image assert company.image_url_or_default() == company.image.url company = CompanyFactory.build(image=None) assert not company.image assert company.image_url_or_default() == '/static/mysign_app/image-fallback.png'
def test_website(): company = CompanyFactory.build(website='no-site') with pytest.raises(ValidationError): company.full_clean() company = CompanyFactory.build(website='http://example.com') company.full_clean() company = CompanyFactory.build(website='example.com') company.full_clean()
def test_door_devices(): company = CompanyFactory() assert company.door_devices.count() == 0 door_device = DoorDeviceFactory.build() door_device.company = company door_device.save() assert company.door_devices.count() == 1 assert company.door_devices.first() == door_device
def test_login_company(client): company = CompanyFactory() user = create_user(company=company) response = client.post(reverse('login'), { 'username': '******', 'password': '******' }) assert response.status_code == 302 assert response.url == reverse('company_index') assert int(client.session.get('_auth_user_id')) == user.id
def test_company_delete(client): client_login(client, is_admin=True) company = CompanyFactory() user = UserFactory(company=company) payload = payload_from_form(CompanyForm(instance=company), delete=True) response = client.post(reverse('admin_companies'), payload) assert response.status_code == 200 assert Company.objects.filter(id=company.id).count() == 0 assert User.objects.filter(id=user.id).count() == 0
def test_door_device_update(client): client_login(client, is_admin=True) door_device = DoorDeviceFactory() company = CompanyFactory() door_device.company = company payload = payload_from_form(DoorDeviceForm(instance=door_device)) response = client.post(reverse('admin_door_devices'), payload) assert response.status_code == 200 assert DoorDevice.objects.get( id=door_device.id).company.name == company.name
def test_door_device_delete(client): client_login(client, is_admin=True) company = CompanyFactory() door_device = DoorDeviceFactory(company=company) payload = payload_from_form(DoorDeviceForm(instance=door_device), delete=True) response = client.post(reverse('admin_door_devices'), payload) assert response.status_code == 200 assert DoorDevice.objects.filter(id=door_device.id).count() == 0 assert Company.objects.filter(id=company.id).count() == 1
def is_company_route(client, route): """ Test that the route is only accessible with a company user """ _test_unauthenticated(client, route) client_login(client) response = client.get(route) assert response.status_code == 403 company = CompanyFactory() client_login(client, company=company) response = client.get(route) assert response.status_code == 200
def test_company_add(client): is_admin_route(client, reverse('admin_company_add')) client_login(client, is_admin=True) company_payload = payload_from_form( CompanyForm(instance=CompanyFactory.build()), prefix='company') user_payload = payload_from_form( AddCompanyUserForm(instance=UserFactory.build()), prefix='user') payload = {**company_payload, **user_payload} response = client.post(reverse('admin_company_add'), payload) assert response.status_code == 302 assert response.url == reverse('admin_companies') assert Company.objects.count() == 1 assert len(mail.outbox) == 1 assert mail.outbox[0].subject == 'Welkom' assert User.objects.count( ) == 2 # One is logged in user, other created user
def setup_test(selenium, live_server): company = CompanyFactory(name="Mindhash", email="*****@*****.**") authenticate_selenium(selenium, live_server, company=company) selenium.maximize_window() selenium.get(live_server.url + "/company/")
def test_company_create(): company = CompanyFactory() UserFactory(company=company) assert User.objects.count() == 1 assert User.objects.first().company_id == company.id
def test_company_and_admin(): company = CompanyFactory() user = UserFactory.build(company=company, is_admin=True) with pytest.raises(ValidationError): user.save()
def test_create(): company = CompanyFactory() company.full_clean() assert Company.objects.count() == 1 assert Company.objects.first().name == company.name
def test_phone_number(): company = CompanyFactory.build(phone_number='belmij!') with pytest.raises(ValidationError): company.full_clean()
def test_str(): company = CompanyFactory.build(name="test") assert str(company) == "test"