Exemplo n.º 1
0
 def test_parse_in_list(self):
     table_name = 'testing'
     c_1 = Column(str, 'column_1')
     c_2 = Column(str, 'column_2')
     q = Query([c_1, c_2], table_name)
     response = q._parse_in_list(['v1', 'v2'])
     self.assertEqual('(\'v1\', \'v2\')', response)
Exemplo n.º 2
0
 def test_first_2(self):
     table_name = 'testing'
     c_1 = Column(str, 'column_1')
     c_2 = Column(str, 'column_2')
     q = Query([c_1, c_2], table_name)
     response = q.first(fakeSessionValidData)
     self.assertEqual({'a': 10}, response)
Exemplo n.º 3
0
 def test_all_1(self):
     table_name = 'testing'
     c_1 = Column(str, 'column_1')
     c_2 = Column(str, 'column_2')
     q = Query([c_1, c_2], table_name)
     response = q.all(fakeSessionValidData)
     self.assertEqual([{'a': 10}, {'b': 20}], response)
Exemplo n.º 4
0
 def test_all_2(self):
     table_name = 'testing'
     c_1 = Column(str, 'column_1')
     c_2 = Column(str, 'column_2')
     q = Query([c_1, c_2], table_name)
     response = q.all(fakeSessionEmptyData)
     self.assertEqual({}, response)
Exemplo n.º 5
0
    def test_get_filter_keys(self):
        c_1 = Column(str, 'column_1')
        c_2 = Column(str, 'column_2')
        q = Query([c_1, c_2], "")
        table_name = 'adwords_account_report'
        q.table_name = table_name
        key = q._get_filter_key()
        self.assertEquals(key, 'account_id')

        table_name = 'adwords_campaign_report'
        q.table_name = table_name
        q.table_name = table_name
        key = q._get_filter_key()
        self.assertEquals(key, 'campaign_id')

        table_name = 'adwords_adgroup_report'
        q.table_name = table_name
        key = q._get_filter_key()
        self.assertEquals(key, 'adgroup_id')

        table_name = 'adwords_ad_report'
        q.table_name = table_name
        key = q._get_filter_key()
        self.assertEquals(key, 'ad_id')

        table_name = 'adwords_keyword_report'
        q.table_name = table_name
        key = q._get_filter_key()
        self.assertEquals(key, 'keyword_id')
Exemplo n.º 6
0
 def test_parse_in_list_2(self):
     table_name = 'testing'
     c_1 = Column(str, 'column_1')
     c_2 = Column(str, 'column_2')
     q = Query([c_1, c_2], table_name)
     response = q._parse_in_list([10, 20])
     self.assertEqual('(10, 20)', response)
Exemplo n.º 7
0
 def test_number_of_samples_negative(self):
     c1 = Column(str, 'column_1')
     c2 = Column(str, 'column_2')
     m = MockDataGenerator()
     samples = -10
     response = m.generate_data(samples, [c1, c2])
     self.assertEqual(0, len(response))
Exemplo n.º 8
0
 def basic_test_56(self):
     c_1 = Column(str, 'c1')
     c_2 = Column(int, 'c2')
     r = or_(c_1 == 'test', c_2 == 10)
     self.assertEqual(r, {
         'type': 'or',
         'left_side': c_1 == 'test',
         'right_side': c_2 == 10
     })
Exemplo n.º 9
0
 def test_query_simple_1(self):
     table_name = 'testing'
     c_1 = Column(str, 'column_1')
     c_2 = Column(str, 'column_2')
     q = Query([c_1, c_2], table_name)
     expected_response = 'SELECT column_1, column_2 FROM ' + \
         self.table_date_range
     response = q.assemble()
     self.assertEquals(expected_response, response)
Exemplo n.º 10
0
 def basic_test_2(self):
     c_1 = Column(str, 'c1')
     c_2 = Column(int, 'c2')
     q = Query([c_1, c_2], 'test')
     q.filter(or_(c_1 == 10, c_2 == 10))
     expected_query = 'SELECT c1, c2 FROM ' +\
         '' + DATABASE_NAME + '.test WHERE _PARTITIONTIME BETWEEN ' +\
         'TIMESTAMP(\'2010-01-01\') AND ' +\
         'TIMESTAMP(\'2030-01-01\')'
     self.assertEquals(q.assemble(), expected_query)
Exemplo n.º 11
0
 def test_query_order_3(self):
     table_name = 'testing'
     c_1 = Column(str, 'column_1')
     c_2 = Column(str, 'column_2')
     q = Query([c_1, c_2], table_name)
     q = q.order_by(c_1, desc=True)
     expected_response = 'SELECT column_1, column_2 FROM ' + \
         self.table_date_range + ' ORDER BY column_1 DESC'
     response = q.assemble()
     self.assertEquals(expected_response, response)
Exemplo n.º 12
0
 def test_query_filter_1(self):
     table_name = 'testing'
     c_1 = Column(str, 'column_1')
     c_2 = Column(str, 'column_2')
     q = Query([c_1, c_2], table_name)
     q = q.filter(c_1 == 'test')
     expected_response = 'SELECT column_1, column_2 FROM ' + \
         self.table_date_range + ' AND ' + \
         'column_1 = \'test\''
     response = q.assemble()
     self.assertEquals(expected_response, response)
Exemplo n.º 13
0
 def test_query_filter_2(self):
     table_name = 'testing'
     c_1 = Column(str, 'column_1')
     c_2 = Column(str, 'column_2')
     q = Query([c_1, c_2], table_name)
     # Wrong comparision
     q = q.filter(c_1 == 10)
     expected_response = 'SELECT column_1, column_2 FROM ' + \
         self.table_date_range
     response = q.assemble()
     self.assertEquals(expected_response, response)
Exemplo n.º 14
0
 def test_query_limit_2(self):
     table_name = 'testing'
     c_1 = Column(str, 'column_1')
     c_2 = Column(str, 'column_2')
     q = Query([c_1, c_2], table_name)
     q = q.limit(100)
     q = q.limit(101)
     expected_response = 'SELECT column_1, column_2 FROM ' + \
         self.table_date_range + ' LIMIT 101'
     response = q.assemble()
     self.assertEquals(expected_response, response)
Exemplo n.º 15
0
 def test_number_of_samples_1(self):
     c1 = Column(str, 'column_1')
     c2 = Column(str, 'column_2')
     m = MockDataGenerator()
     samples = 10
     response = m.generate_data(samples, [c1, c2])
     self.assertEqual(samples, len(response))
     samples = 20
     response = m.generate_data(samples, [c1, c2])
     self.assertEqual(samples, len(response))
     for r in response:
         self.assertEqual(str, type(r['column_1']))
         self.assertEqual(str, type(r['column_2']))
Exemplo n.º 16
0
 def test_eq_op_2(self):
     c_1 = Column(int, 'c_1')
     c_2 = Column(int, 'c_2')
     r = c_1 == c_2
     expected_r = {
         'type': 'and',
         'signal': '=',
         'left_value': 'c_1',
         'left_value_type': int,
         'right_value': 'c_2',
         'right_value_type': Column
     }
     self.assertEqual(expected_r, r)
Exemplo n.º 17
0
 def test_in_op(self):
     c_1 = Column(str, 'c_1')
     r = c_1.in_(['t1', 't2'])
     expected_r = {
         'type': 'and',
         'signal': 'IN',
         'left_value': 'c_1',
         'left_value_type': str,
         'right_value': ['t1', 't2'],
         'right_value_type': list
     }
     self.assertEqual(expected_r, r)
Exemplo n.º 18
0
 def test_gt_op(self):
     c_1 = Column(str, 'c_1')
     r = c_1 < 'test'
     expected_r = {
         'type': 'and',
         'signal': '<',
         'left_value': 'c_1',
         'left_value_type': str,
         'right_value': 'test',
         'right_value_type': str
     }
     self.assertEqual(expected_r, r)
Exemplo n.º 19
0
    def test_query_filter_by_date(self):
        begin_date = '2015-12-01'
        end_date = '2016-01-01'

        table_date_range = '' + DATABASE_NAME + '.testing WHERE _PARTITIONTIME BETWEEN ' +\
            'TIMESTAMP(\'' + begin_date + '\') AND TIMESTAMP' +\
            '(\'' + end_date + '\')'

        table_name = 'testing'

        c_1 = Column(str, 'column_1')
        c_2 = Column(str, 'column_2')

        q = Query([c_1, c_2], table_name).filter_by_date(begin_date, end_date)

        expected_response = 'SELECT column_1, column_2 FROM ' + \
            table_date_range

        response = q.assemble()

        self.assertEquals(expected_response, response)
Exemplo n.º 20
0
 def test_query_tablename_none(self):
     b = BaseModel()
     c_1 = Column(str, 'testing')
     response = b.query(c_1)
     self.assertEqual(None, response)
Exemplo n.º 21
0
 def __init__(self):
     self.__tablename__ = 'ad_report'
     self.id = Column(str, 'id')
     self.ad_id = Column(str, 'ad_id')
     self.headline = Column(str, 'headline')
     self.cost_per_converted_click = Column(int, 'cost_per_converted_click')
     self.cost_per_conversion = Column(int, 'cost_per_conversion')
     self.conversions = Column(float, 'conversions')
     self.active_view_average_cpm = Column(int, 'active_view_average_cpm')
     self.active_view_average_ctr = Column(str, 'active_view_average_ctr')
     self.state = Column(str, 'state')
     self.ctr = Column(str, 'ctr')
     self.description = Column(str, 'description')
     self.display_url = Column(str, 'display_url')
     self.image_url = Column(str, 'image_url')
     self.account_id = Column(str, 'account_id')
     self.campaign_id = Column(str, 'campaign_id')
     self.adgroup_id = Column(str, 'adgroup_id')
     self.account_name = Column(str, 'account_name')
     self.created_time = Column(int, 'created_time')
Exemplo n.º 22
0
 def __init__(self):
     self.c_1 = Column(str, 'test_1')
     self.c_2 = Column(str, 'test_2')
Exemplo n.º 23
0
 def test_query_tablename_not_none(self):
     b = BaseModel()
     b.__tablename__ = 'Test'
     c_1 = Column(str, 'testing')
     response = b.query(c_1)
     self.assertEqual(Query, type(response))
Exemplo n.º 24
0
 def basic_test_5(self):
     c_2 = Column(int, 'c2')
     r = or_('test', c_2 == 10)
     self.assertEqual(r, {})
Exemplo n.º 25
0
 def __init__(self):
     self.__tablename__ = 'campaign_report'
     self.id = Column(str, 'id')
     self.created_time = Column(int, 'created_time')
     self.account_id = Column(str, 'account_id')
     self.campaign_id = Column(str, 'campaign_id')
     self.name = Column(str, 'name')
     self.clicks = Column(int, 'clicks')
     self.budget = Column(int, 'budget')
     self.average_cost = Column(int, 'average_cost')
     self.average_cpc = Column(int, 'average_cpc')
     self.average_cpe = Column(int, 'average_cpe')
     self.average_cpm = Column(int, 'average_cpm')
     self.average_cpv = Column(int, 'average_cpv')
     self.conversion_rate = Column(str, 'conversion_rate')
     self.campaign_state = Column(str, 'campaign_state')
     self.cost_per_conversion = Column(int, 'cost_per_conversion')
     self.account_currency_code = Column(str, 'account_currency_code')
     self.active_view_cpm = Column(int, 'active_view_cpm')
     self.active_view_ctr = Column(str, 'active_view_ctr')
     self.active_viewable_impressions = Column(
         float, 'active_viewable_impressions')
     self.network = Column(str, 'network')
     self.average_position = Column(float, 'average_position')
     self.bidding_strategy_name = Column(str, 'bidding_strategy_name')
     self.bounce_rate = Column(str, 'bounce_rate')
     self.mobile_bid_modifier = Column(str, 'mobile_bid_modifier')
     self.content_budget_lost_share = Column(str,
                                             'content_budget_lost_share')
     self.conversions = Column(float, 'conversions')
     self.conversion_total_value = Column(float, 'conversion_total_value')
     self.cost = Column(int, 'cost')
     self.cost_per_all_conversion = Column(int, 'cost_per_all_conversion')
     self.impressions = Column(float, 'impressions')
     self.advertising_channel_type = Column(str, 'advertising_channel_type')
Exemplo n.º 26
0
 def test_in_op_error(self):
     c_1 = Column(str, 'c_1')
     r = c_1.in_('t2')
     expected_r = {}
     self.assertEqual(expected_r, r)
Exemplo n.º 27
0
 def test_eq_op_error(self):
     c_1 = Column(str, 'c_1')
     r = c_1 == 10
     expected_r = {}
     self.assertEqual(expected_r, r)
Exemplo n.º 28
0
 def test_eq_op_error_2(self):
     c_1 = Column(str, 'c_1')
     c_2 = Column(int, 'c_2')
     r = c_1 == c_2
     expected_r = {}
     self.assertEqual(expected_r, r)
Exemplo n.º 29
0
 def __init__(self):
     self.__tablename__ = 'search_terms_report'
     self.id = Column(str, 'id')
     self.adgroup_id = Column(str, 'adgroup_id')
     self.campaign_id = Column(str, 'campaign_id')
     self.account_id = Column(str, 'account_id')
     self.keyword_id = Column(str, 'keyword_id')
     self.search_term = Column(str, 'search_term')
     self.keyword = Column(str, 'keyword')
     self.clicks = Column(int, 'clicks')
     self.all_conversions = Column(float, 'all_conversions')
     self.conversions = Column(float, 'conversions')
     self.conversion_value = Column(float, 'conversion_value')
     self.impressions = Column(int, 'impressions')
     self.cost = Column(int, 'cost')
     self.average_position = Column(float, 'average_position')
     self.created_time = Column(int, 'created_time')
Exemplo n.º 30
0
 def __init__(self):
     self.__tablename__ = 'adgroup_report'
     self.id = Column(str, 'id')
     self.created_time = Column(int, 'created_time')
     self.account_id = Column(str, 'account_id')
     self.campaign_id = Column(str, 'campaign_id')
     self.adgroup_id = Column(str, 'adgroup_id')
     self.name = Column(str, 'name')
     self.state = Column(str, 'state')
     self.average_cost = Column(int, 'average_cost')
     self.average_cpc = Column(int, 'average_cpc')
     self.average_cpe = Column(int, 'average_cpe')
     self.average_cpm = Column(int, 'average_cpm')
     self.average_cpv = Column(int, 'average_cpv')
     self.all_conversion_rate = Column(str, 'all_conversion_rate')
     self.average_page_view = Column(float, 'average_page_view')
     self.average_position = Column(float, 'average_position')
     self.currency = Column(str, 'currency')
     self.account_name = Column(str, 'account_name')
     self.mobile_modifier = Column(str, 'mobile_modifier')
     self.network = Column(str, 'network')
     self.all_conversions = Column(float, 'all_conversions')
     self.average_time_on_site = Column(float, 'average_time_on_site')
     self.bounce_rate = Column(str, 'bounce_rate')
     self.campaign_name = Column(str, 'campaign_name')
     self.campaign_status = Column(str, 'campaign_status')
     self.campaign_assisted_conversions = Column(
         float, 'campaign_assisted_conversions')
     self.content_impression_share = Column(str, 'content_impression_share')
     self.conversions = Column(float, 'conversions')
     self.cost = Column(int, 'cost')
     self.cost_per_all_conversion = Column(int, 'cost_per_all_conversion')
     self.ctr = Column(str, 'ctr')
     self.impressions = Column(float, 'impressions')