def test_query(self):
        task = QueryLastCountryPerCourseTask(**self._get_kwargs())
        query = task.query()
        expected_query = textwrap.dedent(
            """
            USE default;
            DROP TABLE IF EXISTS course_enrollment_location_current;
            CREATE EXTERNAL TABLE course_enrollment_location_current (
                date STRING,
                course_id STRING,
                country_code STRING,
                count INT,
                cumulative_count INT
            )
            ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
            LOCATION 's3://output/path';

            INSERT OVERWRITE TABLE course_enrollment_location_current
            SELECT
                sce.dt,
                sce.course_id,
                uc.country_code,
                sum(if(sce.is_active, 1, 0)),
                count(sce.user_id)
            FROM student_courseenrollment sce
            LEFT OUTER JOIN auth_user au on sce.user_id = au.id
            LEFT OUTER JOIN last_country_of_user uc on au.username = uc.username
            GROUP BY sce.dt, sce.course_id, uc.country_code;
            """
        )
        self.assertEquals(query, expected_query)
    def test_query(self):
        task = QueryLastCountryPerCourseTask(**self._get_kwargs())
        query = task.query()
        expected_query = textwrap.dedent("""
            USE default;
            DROP TABLE IF EXISTS course_enrollment_location_current;
            CREATE EXTERNAL TABLE course_enrollment_location_current (
                date STRING,
                course_id STRING,
                country_code STRING,
                count INT,
                cumulative_count INT
            )
            ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
            LOCATION 's3://fake/warehouse/course_enrollment_location_current';

            INSERT OVERWRITE TABLE course_enrollment_location_current
            SELECT
                sce.dt,
                sce.course_id,
                uc.country_code,
                sum(if(sce.is_active, 1, 0)),
                count(sce.user_id)
            FROM student_courseenrollment sce
            LEFT OUTER JOIN auth_user au on sce.user_id = au.id
            LEFT OUTER JOIN last_country_of_user uc on au.username = uc.username
            GROUP BY sce.dt, sce.course_id, uc.country_code;
            """)
        self.assertEquals(query, expected_query)
 def test_requires(self):
     task = QueryLastCountryPerCourseTask(**self._get_kwargs())
     required_tasks = list(task.requires())
     self.assertEquals(len(required_tasks), 1)
     self.assertEquals(len(required_tasks[0]), 3)
 def test_output(self):
     task = QueryLastCountryPerCourseTask(**self._get_kwargs())
     self.assertEquals(task.output().path, 's3://output/path')
 def test_requires(self):
     task = QueryLastCountryPerCourseTask(**self._get_kwargs())
     required_tasks = list(task.requires())
     self.assertEquals(len(required_tasks), 1)
     self.assertEquals(len(required_tasks[0]), 3)
 def test_output(self):
     task = QueryLastCountryPerCourseTask(**self._get_kwargs())
     self.assertEquals(
         task.output().path,
         's3://fake/warehouse/course_enrollment_location_current')
 def test_output(self):
     task = QueryLastCountryPerCourseTask(**self._get_kwargs())
     self.assertEquals(task.output().path, 's3://output/path')
 def test_output(self):
     task = QueryLastCountryPerCourseTask(**self._get_kwargs())
     self.assertEquals(task.output().path, 's3://fake/warehouse/course_enrollment_location_current')