ephraimbuddy commented on a change in pull request #14735:
URL: https://github.com/apache/airflow/pull/14735#discussion_r596026874



##########
File path: tests/api_connexion/endpoints/test_user_endpoint.py
##########
@@ -0,0 +1,225 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+import pytest
+from flask_appbuilder.security.sqla.models import User
+from parameterized import parameterized
+
+from airflow.api_connexion.exceptions import EXCEPTIONS_LINK_MAP
+from airflow.security import permissions
+from airflow.utils import timezone
+from tests.test_utils.api_connexion_utils import assert_401, create_user, 
delete_user
+from tests.test_utils.config import conf_vars
+
+DEFAULT_TIME = "2020-06-11T18:00:00+00:00"
+
+
[email protected](scope="module")
+def configured_app(minimal_app_for_api):
+    app = minimal_app_for_api
+    create_user(
+        app,  # type: ignore
+        username="test",
+        role_name="Test",
+        permissions=[
+            (permissions.ACTION_CAN_LIST, 
permissions.RESOURCE_USER_DB_MODELVIEW),
+            (permissions.ACTION_CAN_SHOW, 
permissions.RESOURCE_USER_DB_MODELVIEW),
+        ],
+    )
+    create_user(app, username="test_no_permissions", 
role_name="TestNoPermissions")  # type: ignore
+
+    yield app
+
+    delete_user(app, username="test")  # type: ignore
+    delete_user(app, username="test_no_permissions")  # type: ignore
+
+
+class TestUserEndpoint:
+    @pytest.fixture(autouse=True)
+    def setup_attrs(self, configured_app) -> None:
+        self.app = configured_app
+        self.client = self.app.test_client()  # type:ignore
+        self.session = self.app.appbuilder.get_session
+
+    def teardown_method(self) -> None:
+        # Delete users that have our custom default time
+        users = self.session.query(User).filter(User.changed_on == 
timezone.parse(DEFAULT_TIME)).all()
+        for user in users:
+            self.session.delete(user)
+        self.session.commit()
+
+    def _create_users(self, count, roles=None):
+        # create users with defined created_on and changed_on date
+        # for easy testing
+        if roles is None:
+            roles = []
+        return [
+            User(
+                first_name=f'test{i}',
+                last_name=f'test{i}',
+                username=f'TEST_USER{i}',
+                email=f'mytest@test{i}.org',
+                roles=roles or [],
+                created_on=timezone.parse(DEFAULT_TIME),
+                changed_on=timezone.parse(DEFAULT_TIME),
+            )
+            for i in range(1, count + 1)
+        ]
+
+
+class TestGetUser(TestUserEndpoint):
+    def test_should_respond_200(self):
+        users = self._create_users(1)
+        self.session.add_all(users)
+        self.session.commit()
+        response = self.client.get("/api/v1/users/TEST_USER1", 
environ_overrides={'REMOTE_USER': "test"})
+        assert response.status_code == 200
+        assert response.json == {
+            'active': None,
+            'changed_on': DEFAULT_TIME,
+            'created_on': DEFAULT_TIME,
+            'email': '[email protected]',
+            'fail_login_count': None,

Review comment:
       This is because of the DB model, it doesn't specify a default value. 
https://github.com/dpgaspar/Flask-AppBuilder/blob/302e4abe32d9d2403f2ce52e4abb31beb59bb252/flask_appbuilder/security/sqla/models.py#L104-L105
   So, count comes out as None. I think that, they are updated the first time 
user signs in
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to