def init_table(self, view_count): try: App.language_stats_db_handler().table.delete() except: pass App.language_stats_db_handler().resource.create_table( TableName=App.language_stats_table_name, KeySchema=[ { 'AttributeName': 'lang_code', 'KeyType': 'HASH' } ], AttributeDefinitions=[ { 'AttributeName': 'lang_code', 'AttributeType': 'S' } ], ProvisionedThroughput={ 'ReadCapacityUnits': 5, 'WriteCapacityUnits': 5 }, ) lang_stats_data = { 'lang_code': ViewCountTest.LANG_CODE.lower(), 'last_updated': datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"), 'manifest': '{}', 'views': view_count } lang_stats = LanguageStats(lang_stats_data).insert() App.logger.debug("new language: " + lang_stats.lang_code)
def init_table(self): try: handler = App.language_stats_db_handler() handler.table.delete() except Exception as e: pass App.language_stats_db_handler().resource.create_table( TableName=App.language_stats_table_name, KeySchema=[ { 'AttributeName': 'lang_code', 'KeyType': 'HASH' }, ], AttributeDefinitions=[ { 'AttributeName': 'lang_code', 'AttributeType': 'S' }, ], ProvisionedThroughput={ 'ReadCapacityUnits': 5, 'WriteCapacityUnits': 5 }, GlobalSecondaryIndexes=[ { 'IndexName': 'search_type-views-index', 'KeySchema': [ { 'AttributeName': 'search_type', 'KeyType': 'HASH' }, ], 'Projection': { 'ProjectionType': 'ALL' }, 'ProvisionedThroughput': { 'ReadCapacityUnits': 123, 'WriteCapacityUnits': 123 } }, ], ) lang_stats_data = { 'lang_code': '?lc=en', 'last_updated': datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"), 'search_type': 'Y', 'views': SearchCountTest.INITIAL_VIEW_COUNT } lang_stats = LanguageStats(lang_stats_data).insert()
def init_table(self): try: handler = App.language_stats_db_handler() handler.table.delete() except Exception as e: pass App.language_stats_db_handler().resource.create_table( TableName=App.language_stats_table_name, KeySchema=[ { 'AttributeName': 'lang_code', 'KeyType': 'HASH' }, ], AttributeDefinitions=[ { 'AttributeName': 'lang_code', 'AttributeType': 'S' }, ], ProvisionedThroughput={ 'ReadCapacityUnits': 5, 'WriteCapacityUnits': 5 }, GlobalSecondaryIndexes=[ { 'IndexName': 'search_type-views-index', 'KeySchema': [ { 'AttributeName': 'search_type', 'KeyType': 'HASH' }, ], 'Projection': { 'ProjectionType': 'ALL' }, 'ProvisionedThroughput': { 'ReadCapacityUnits': 123, 'WriteCapacityUnits': 123 } }, ], ) lang_stats_data = { 'lang_code': '?lc=en', 'last_updated': datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"), 'search_type': 'Y', 'views': SearchCountTest.INITIAL_VIEW_COUNT } lang_stats = LanguageStats(lang_stats_data).insert()
def setUp(self): """Runs before each test.""" App(prefix='{0}-'.format(self._testMethodName), db_connection_string='sqlite:///:memory:') self.tx_manager = TxManager() self.searches = None self.language_views = None try: App.language_stats_db_handler().table.delete() except: pass App.language_stats_db_handler().resource.create_table( TableName=App.language_stats_table_name, KeySchema=[ { 'AttributeName': 'lang_code', 'KeyType': 'HASH' }, ], AttributeDefinitions=[ { 'AttributeName': 'lang_code', 'AttributeType': 'S' }, ], ProvisionedThroughput={ 'ReadCapacityUnits': 5, 'WriteCapacityUnits': 5 }, GlobalSecondaryIndexes=[ { 'IndexName': 'search_type-views-index', 'KeySchema': [ { 'AttributeName': 'search_type', 'KeyType': 'HASH' }, ], 'Projection': { 'ProjectionType': 'ALL' }, 'ProvisionedThroughput': { 'ReadCapacityUnits': 123, 'WriteCapacityUnits': 123 } }, ], )
def __init__(self, *args, **kwargs): # Init attributes self.lang_code = None self.views = 0 self.last_updated = None self.monitor = True self.search_type = 'N' if 'db_handler' not in kwargs or not kwargs['db_handler']: kwargs['db_handler'] = App.language_stats_db_handler() super(LanguageStats, self).__init__(*args, **kwargs)
def list_language_table_entries(self, reverse_sort=True, max_count=20, search_type=False): """ get list of all the language table records filtered by type :return: """ search_key = 'N' if search_type is False else 'Y' params = { 'IndexName': 'search_type-views-index', 'KeyConditionExpression': Key('search_type').eq(search_key), 'ScanIndexForward': not reverse_sort } if max_count > 0: params['Limit'] = max_count db_handler = App.language_stats_db_handler() results = db_handler.query_raw(**params) items = results['Items'] return items
def list_language_table_entries(self, reverse_sort=True, max_count=20, search_type=False): """ get list of all the language table records filtered by type :return: """ search_key = 'N' if search_type is False else 'Y' params = { 'IndexName': 'search_type-views-index', 'KeyConditionExpression': Key('search_type').eq(search_key), 'ScanIndexForward': not reverse_sort } if max_count > 0: params['Limit'] = max_count db_handler = App.language_stats_db_handler() results = db_handler.query_raw(**params) items = results['Items'] return items
def test_dynamodb_handler(self): self.assertIsNotNone(App.language_stats_db_handler())