#!/usr/bin/python
# Copyright 2022 Northern.tech AS
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
from common import (
    api_client_int,
    mongo,
    clean_db,
    clean_db_f,
    clean_migrated_db,
    clean_migrated_db_f,
    make_auth,
    api_client_mgmt,
    migrate,
    cli,
)
import mender_client
import pytest


class TestInternalApiTenantCreate:
    def test_create_ok(self, api_client_int, clean_db):
        r = api_client_int.create_tenant("foobar")
        assert r.status_code == 201

    def test_create_twice(self, api_client_int, clean_db):

        r = api_client_int.create_tenant("foobar")
        assert r.status_code == 201

        # creating once more should not fail
        r = api_client_int.create_tenant("foobar")
        assert r.status_code == 201

    def test_create_empty(self, api_client_int):
        try:
            r = api_client_int.create_tenant("")
        except mender_client.ApiException as e:
            assert e.status == 400
