You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/01/03 18:07:53 UTC

[GitHub] BasPH closed pull request #4382: [AIRFLOW-3469] Move KnownEvent out of models.py

BasPH closed pull request #4382: [AIRFLOW-3469] Move KnownEvent out of models.py
URL: https://github.com/apache/incubator-airflow/pull/4382
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/models/__init__.py b/airflow/models/__init__.py
index cbcf586ac2..9d0784b0a7 100755
--- a/airflow/models/__init__.py
+++ b/airflow/models/__init__.py
@@ -4344,27 +4344,6 @@ def __repr__(self):
         return self.know_event_type
 
 
-class KnownEvent(Base):
-    __tablename__ = "known_event"
-
-    id = Column(Integer, primary_key=True)
-    label = Column(String(200))
-    start_date = Column(UtcDateTime)
-    end_date = Column(UtcDateTime)
-    user_id = Column(Integer(), ForeignKey('users.id'),)
-    known_event_type_id = Column(Integer(), ForeignKey('known_event_type.id'),)
-    reported_by = relationship(
-        "User", cascade=False, cascade_backrefs=False, backref='known_events')
-    event_type = relationship(
-        "KnownEventType",
-        cascade=False,
-        cascade_backrefs=False, backref='known_events')
-    description = Column(Text)
-
-    def __repr__(self):
-        return self.label
-
-
 class Variable(Base, LoggingMixin):
     __tablename__ = "variable"
 
diff --git a/airflow/models/knownevent.py b/airflow/models/knownevent.py
new file mode 100644
index 0000000000..54ab651ed2
--- /dev/null
+++ b/airflow/models/knownevent.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+#
+# 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.
+
+from sqlalchemy import Column, Integer, String, ForeignKey, Text
+from sqlalchemy.orm import relationship
+
+from airflow.models.base import Base
+from airflow.utils.sqlalchemy import UtcDateTime
+
+
+class KnownEvent(Base):
+    __tablename__ = "known_event"
+
+    id = Column(Integer, primary_key=True)
+    label = Column(String(200))
+    start_date = Column(UtcDateTime)
+    end_date = Column(UtcDateTime)
+    user_id = Column(Integer(), ForeignKey('users.id'),)
+    known_event_type_id = Column(Integer(), ForeignKey('known_event_type.id'),)
+    reported_by = relationship(
+        "User", cascade=False, cascade_backrefs=False, backref='known_events')
+    event_type = relationship(
+        "KnownEventType",
+        cascade=False,
+        cascade_backrefs=False, backref='known_events')
+    description = Column(Text)
+
+    def __repr__(self):
+        return self.label
diff --git a/airflow/www/app.py b/airflow/www/app.py
index d7f102249b..583297f422 100644
--- a/airflow/www/app.py
+++ b/airflow/www/app.py
@@ -31,6 +31,7 @@
 from airflow import configuration as conf
 from airflow import models, LoggingMixin
 from airflow.models.connection import Connection
+from airflow.models.knownevent import KnownEvent
 from airflow.settings import Session
 
 from airflow.www.blueprints import routes
@@ -90,7 +91,7 @@ def create_app(config=None, testing=False):
             av(vs.ChartModelView(
                 models.Chart, Session, name="Charts", category="Data Profiling"))
         av(vs.KnownEventView(
-            models.KnownEvent,
+            KnownEvent,
             Session, name="Known Events", category="Data Profiling"))
         av(vs.SlaMissModelView(
             models.SlaMiss,
diff --git a/tests/www/test_views.py b/tests/www/test_views.py
index a0d86ac54a..2a10b6bed6 100644
--- a/tests/www/test_views.py
+++ b/tests/www/test_views.py
@@ -34,6 +34,7 @@
 from airflow import models, configuration
 from airflow.config_templates.airflow_local_settings import DEFAULT_LOGGING_CONFIG
 from airflow.models import DAG, DagRun, TaskInstance
+from airflow.models.knownevent import KnownEvent
 from airflow.operators.dummy_operator import DummyOperator
 from airflow.settings import Session
 from airflow.utils.timezone import datetime
@@ -177,7 +178,7 @@ class TestKnownEventView(unittest.TestCase):
     def setUpClass(cls):
         super(TestKnownEventView, cls).setUpClass()
         session = Session()
-        session.query(models.KnownEvent).delete()
+        session.query(KnownEvent).delete()
         session.query(models.User).delete()
         session.commit()
         user = models.User(username='airflow')
@@ -203,7 +204,7 @@ def setUp(self):
         }
 
     def tearDown(self):
-        self.session.query(models.KnownEvent).delete()
+        self.session.query(KnownEvent).delete()
         self.session.commit()
         self.session.close()
         super(TestKnownEventView, self).tearDown()
@@ -223,7 +224,7 @@ def test_create_known_event(self):
             follow_redirects=True,
         )
         self.assertEqual(response.status_code, 200)
-        self.assertEqual(self.session.query(models.KnownEvent).count(), 1)
+        self.assertEqual(self.session.query(KnownEvent).count(), 1)
 
     def test_create_known_event_with_end_data_earlier_than_start_date(self):
         self.known_event['end_date'] = '2017-06-05 11:00:00'
@@ -236,7 +237,7 @@ def test_create_known_event_with_end_data_earlier_than_start_date(self):
             'Field must be greater than or equal to Start Date.',
             response.data.decode('utf-8'),
         )
-        self.assertEqual(self.session.query(models.KnownEvent).count(), 0)
+        self.assertEqual(self.session.query(KnownEvent).count(), 0)
 
 
 class TestPoolModelView(unittest.TestCase):


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services