Skip to content

Commit

Permalink
Source folder renamed as longitude.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dani Ramirez committed Feb 2, 2019
1 parent ba494a3 commit 78bc949
Show file tree
Hide file tree
Showing 43 changed files with 56 additions and 54 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
image: python:3.6.3-onbuild
command: bash
volumes:
- .:/usr/src/app
- .:/usr/longitude/app

cache:
image: redis:alpine
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/core/caches/base.py → longitude/core/caches/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import pickle

from src.core.common.query_response import LongitudeQueryResponse
from longitude.core.common.query_response import LongitudeQueryResponse
from ..common.config import LongitudeConfigurable


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src.core.data_sources.base import DataSource
from longitude.core.data_sources.base import DataSource


class DisabledCache:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from .common import psycopg2_type_as_string
from src.core.common.query_response import LongitudeQueryResponse
from src.core.data_sources.base import DataSource
from longitude.core.common.query_response import LongitudeQueryResponse
from longitude.core.data_sources.base import DataSource


class SQLAlchemyDataSource(DataSource):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import TestCase, mock

from src.core.common.query_response import LongitudeQueryResponse
from longitude.core.common.query_response import LongitudeQueryResponse
from ..caches.base import LongitudeCache


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import TestCase, mock

from src.core.common.query_response import LongitudeQueryResponse
from longitude.core.common.query_response import LongitudeQueryResponse
from ..caches.ram import RamCache


Expand All @@ -11,7 +11,7 @@ def setUp(self):
self.cache = RamCache()

def test_setup_must_clean_cache(self):
with mock.patch('src.core.caches.ram.RamCache.flush') as fake_flush:
with mock.patch('longitude.core.caches.ram.RamCache.flush') as fake_flush:
self.cache.setup()
fake_flush.assert_called_once()
self.assertTrue(self.cache.is_ready)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import redis.exceptions

from src.core.common.query_response import LongitudeQueryResponse
from longitude.core.common.query_response import LongitudeQueryResponse
from ..caches.redis import RedisCache


@mock.patch('src.core.caches.redis.redis.Redis')
@mock.patch('longitude.core.caches.redis.redis.Redis')
class TestRedisCache(TestCase):
cache = None

Expand Down Expand Up @@ -39,7 +39,7 @@ def test_is_not_ready_if_redis_fails_ping_because_of_connection_error(self, redi
with self.assertLogs(level='ERROR') as log_test:
self.assertFalse(self.cache.is_ready)
expected_log = [
'ERROR:src.core.caches.redis:Cannot connect to Redis server at some_host:666.'
'ERROR:longitude.core.caches.redis:Cannot connect to Redis server at some_host:666.'
]

self.assertEqual(expected_log, log_test.output)
Expand All @@ -54,18 +54,18 @@ def test_is_not_ready_because_no_password(self, redis_mock):
self.cache.setup()
with self.assertLogs(level='ERROR') as log_test:
self.assertFalse(self.cache.is_ready)
self.assertEqual(['ERROR:src.core.caches.redis:Redis password required.'], log_test.output)
self.assertEqual(['ERROR:longitude.core.caches.redis:Redis password required.'], log_test.output)

def test_is_not_ready_because_wrong_password(self, redis_mock):
redis_mock.return_value.ping.side_effect = redis.exceptions.ResponseError('invalid password')
self.cache.setup()
with self.assertLogs(level='ERROR') as log_test:
self.assertFalse(self.cache.is_ready)
self.assertEqual(['ERROR:src.core.caches.redis:Redis password is wrong.'], log_test.output)
self.assertEqual(['ERROR:longitude.core.caches.redis:Redis password is wrong.'], log_test.output)

def test_is_not_ready_because_of_generic_response_error(self, redis_mock):
redis_mock.return_value.ping.side_effect = redis.exceptions.ResponseError('some error text')
self.cache.setup()
with self.assertLogs(level='ERROR') as log_test:
self.assertFalse(self.cache.is_ready)
self.assertEqual(['ERROR:src.core.caches.redis:some error text'], log_test.output)
self.assertEqual(['ERROR:longitude.core.caches.redis:some error text'], log_test.output)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import TestCase

from src.core.common.config import LongitudeConfigurable
from src.core.common.exceptions import LongitudeConfigError
from longitude.core.common.config import LongitudeConfigurable
from longitude.core.common.exceptions import LongitudeConfigError


class TestConfig(TestCase):
Expand All @@ -20,8 +20,8 @@ def test_config(self):
ds = LongitudeConfigurable(config)
self.assertEqual(log_test.output,
[
'WARNING:src.core.common.config:some_another_config_value is an unexpected config value',
'WARNING:src.core.common.config:some_config_value is an unexpected config value'])
'WARNING:longitude.core.common.config:some_another_config_value is an unexpected config value',
'WARNING:longitude.core.common.config:some_config_value is an unexpected config value'])

# Values in the config can be retrieved using get_config. If no default or config is defined, None is returned.
ds._default_config['some_config_value'] = 42
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def test_cache_hit(self):
# but we do not care, in the abstract class, about what content is generated there.
self.assertTrue(ds.query('some_query_in_cache').comes_from_cache)

@mock.patch('src.core.data_sources.base.DataSource.parse_response')
@mock.patch('src.core.data_sources.base.DataSource.execute_query')
@mock.patch('longitude.core.data_sources.base.DataSource.parse_response')
@mock.patch('longitude.core.data_sources.base.DataSource.execute_query')
def test_cache_miss(self, execute_query_mock, parse_response_mock):
ds = DataSource({}, cache_class=self._cache_class)
ds.setup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestCartoDataSource(TestCase):
def test_default_configuration_loads(self):
with self.assertLogs(level='INFO') as log_test:
carto_ds = CartoDataSource()
module_name = 'src.core.common.config'
module_name = 'longitude.core.common.config'
self.assertEqual(log_test.output,
['INFO:%s:api_key key is using default value' % module_name,
'INFO:%s:api_version key is using default value' % module_name,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from unittest import TestCase, mock
from ..data_sources.postgres.sqlalchemy import SQLAlchemyDataSource

TESTED_MODULE_PATH = 'src.core.data_sources.postgres.sqlalchemy.%s'
TESTED_MODULE_PATH = 'longitude.core.data_sources.postgres.sqlalchemy.%s'


class TestSQLAlchemyDataSource(TestCase):

def test_default_configuration_loads(self):
with self.assertLogs(level='INFO') as log_test:
carto_ds = SQLAlchemyDataSource()
module_name = 'src.core.common.config'
module_name = 'longitude.core.common.config'
self.assertEqual(log_test.output,
['INFO:%s:db key is using default value' % module_name,
'INFO:%s:host key is using default value' % module_name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from unittest import TestCase, mock
from src.core.common.config import EnvironmentConfiguration
from longitude.core.common.config import EnvironmentConfiguration

fake_environment = {
'PATATUELA_RULES': 'my_root_value'
Expand All @@ -8,7 +8,7 @@

class TestConfigurationDictionary(TestCase):

@mock.patch.dict('src.core.common.config.os.environ', fake_environment)
@mock.patch.dict('longitude.core.common.config.os.environ', fake_environment)
def test_base(self):
d = EnvironmentConfiguration({
'root_patatuela': '=PATATUELA_RULES',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from unittest import TestCase, mock
from src.core.common.helpers import DisabledCache
from src.core.data_sources.base import DataSource
from longitude.core.common.helpers import DisabledCache
from longitude.core.data_sources.base import DataSource


class TestHelpers(TestCase):

@mock.patch('src.core.data_sources.base.DataSource', spec=DataSource)
@mock.patch('longitude.core.data_sources.base.DataSource', spec=DataSource)
def test_disable_cache_context_manager_triggers_cache(self, fake_data_source):
fake_data_source.enable_cache.return_value = None
fake_data_source.disable_cache.return_value = None
with DisabledCache(fake_data_source):
fake_data_source.disable_cache.assert_called_once()
fake_data_source.enable_cache.assert_called_once()

@mock.patch('src.core.data_sources.base.DataSource')
@mock.patch('longitude.core.data_sources.base.DataSource')
def test_disable_cache_context_manager_must_receive_a_data_source(self, fake_data_source):
with self.assertRaises(TypeError):
with DisabledCache(fake_data_source):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from src.core.data_sources.base import LongitudeRetriesExceeded
from src.core.data_sources.carto import CartoDataSource
from src.samples.carto_sample_config import CARTO_API_KEY, CARTO_USER, CARTO_TABLE_NAME
from longitude.core.data_sources.base import LongitudeRetriesExceeded
from longitude.core.data_sources.carto import CartoDataSource
from longitude.samples.carto_sample_config import CARTO_API_KEY, CARTO_USER, CARTO_TABLE_NAME

if __name__ == "__main__":
config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from src.core.caches.ram import RamCache
from src.core.data_sources.base import LongitudeRetriesExceeded
from src.core.data_sources.carto import CartoDataSource
from src.samples.carto_sample_config import CARTO_API_KEY, CARTO_USER, CARTO_TABLE_NAME
from longitude.core.caches.ram import RamCache
from longitude.core.data_sources.base import LongitudeRetriesExceeded
from longitude.core.data_sources.carto import CartoDataSource
from longitude.samples.carto_sample_config import CARTO_API_KEY, CARTO_USER, CARTO_TABLE_NAME

if __name__ == "__main__":
config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from src.core.common.helpers import DisabledCache
from src.core.caches.redis import RedisCache
from src.core.common.exceptions import LongitudeRetriesExceeded
from src.core.data_sources.carto import CartoDataSource
from src.samples.carto_sample_config import CARTO_API_KEY, CARTO_USER, CARTO_TABLE_NAME
from longitude.core.common.helpers import DisabledCache
from longitude.core.caches.redis import RedisCache
from longitude.core.common.exceptions import LongitudeRetriesExceeded
from longitude.core.data_sources.carto import CartoDataSource
from longitude.samples.carto_sample_config import CARTO_API_KEY, CARTO_USER, CARTO_TABLE_NAME

if __name__ == "__main__":
config = {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))

from src.core.caches.redis import RedisCache
from src.core.data_sources.postgres.default import DefaultPostgresDataSource
from src.core.data_sources.carto import CartoDataSource
from src.core.common.config import EnvironmentConfiguration
from longitude.core.caches.redis import RedisCache
from longitude.core.data_sources.postgres.default import DefaultPostgresDataSource
from longitude.core.data_sources.carto import CartoDataSource
from longitude.core.common.config import EnvironmentConfiguration


def import_table_values_from_carto(limit):
# First, we read from CARTO our 'county_population'
# If you execute this script twice fast, you will make use of the cache.
# After 3 seconds, the Carto query will be executed again if requested.
carto_data = carto.query('select * from county_population limit %d' % limit, use_cache=True, expiration_time_s=3)
print(carto_data.comes_from_cache)
# Then, we create a local table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from src.core.caches.ram import RamCache
from src.core.data_sources.base import LongitudeRetriesExceeded
from src.core.data_sources.postgres.default import DefaultPostgresDataSource
from src.samples.postgres_sample_config import POSTGRES_DB, POSTGRES_PORT, POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASS
from longitude.core.caches.ram import RamCache
from longitude.core.data_sources.base import LongitudeRetriesExceeded
from longitude.core.data_sources.postgres.default import DefaultPostgresDataSource
from longitude.samples.postgres_sample_config import POSTGRES_DB, POSTGRES_PORT, POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASS

if __name__ == "__main__":
config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

from sqlalchemy import text

from src.core.caches.ram import RamCache
from longitude.core.caches.ram import RamCache

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from src.core.data_sources.postgres.sqlalchemy import SQLAlchemyDataSource
from src.samples.sqlalchemy_sample_config import POSTGRES_DB, POSTGRES_PORT, POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASS
from longitude.core.data_sources.postgres.sqlalchemy import SQLAlchemyDataSource
from longitude.samples.sqlalchemy_sample_config import POSTGRES_DB, POSTGRES_PORT, POSTGRES_HOST, POSTGRES_USER, POSTGRES_PASS


def prepare_sample_table(engine):
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"Company": 'https://geographica.gs',
"Source Code": "https://github.com/GeographicaGS/Longitude"
},
package_dir={'': 'src'},
package_dir={'': 'longitude'},
# Choose your license
license='MIT',

Expand Down Expand Up @@ -66,7 +66,7 @@
# What does your project relate to?
keywords='carto longitude',

packages=find_packages(where='src', exclude=['test*']),
packages=find_packages(where='longitude', exclude=['test*']),

install_requires=[
'carto==1.4.0',
Expand Down

0 comments on commit 78bc949

Please sign in to comment.