Skip to content

Commit

Permalink
Fix tests and reverse mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Gaudin committed Jan 17, 2018
1 parent ca666d5 commit 9dcb6dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
15 changes: 14 additions & 1 deletion mongo_connector/doc_managers/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ def validate_mapping(mappings):

for collection in dbmapping:
mapping = dbmapping[collection]
reversed_pk_mapping = get_reversed_pk_mapping(mapping)

if mapping['pk'] not in mapping:
if (reversed_pk_mapping is None or reversed_pk_mapping not in mapping) and \
mapping['pk'] not in mapping:
# look for a linked table
for linked_collection in dbmapping:
if linked_collection != collection:
Expand Down Expand Up @@ -207,3 +209,14 @@ def validate_mapping(mappings):
dest
)
)


def get_reversed_pk_mapping(mapping):
if 'pk' not in mapping:
return None

for field in mapping:
if 'dest' in mapping[field] and mapping[field]['dest'] == mapping['pk']:
return field

return None
5 changes: 1 addition & 4 deletions mongo_connector/doc_managers/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def sql_add_foreign_keys(cursor, foreign_keys):


def unique_list(input_list):
return list(set(input_list))
return sorted(list(set(input_list)))


def sql_bulk_insert(cursor, mappings, namespace, documents):
Expand Down Expand Up @@ -198,9 +198,6 @@ def sql_bulk_insert(cursor, mappings, namespace, documents):

LOG.error(u"Traceback:\n%s", traceback.format_exc())

def unique_list(input_list):
return list(set(input_list))

def _sql_bulk_insert(query, mappings, namespace, documents):
if not documents:
return
Expand Down
5 changes: 2 additions & 3 deletions tests/test_postgresql_manager.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# -*- coding: utf-8 -*-

from time import time
from unittest import TestCase, main

from mock import MagicMock, patch, mock_open, call
from time import time
import json

from mongo_connector.doc_managers import postgresql_manager
from .fixtures import *


MAPPING_RAW = '''{
"db": {
"col": {
Expand Down

0 comments on commit 9dcb6dc

Please sign in to comment.