def test_connection_id_setter(self, model_new): model = copy.deepcopy(model_new) connection = make_connection(model) cid = str(uuid.uuid4()) connection.connection_id = cid assert connection.connection_id == cid assert connection.model['connection_id'] == cid
def add(self, request, connection_id=None): if 'connection_id' in request: raise ValueError( f'Invalid argument: connection_id. Expected empty but actual {request["connection_id"]}' ) connection = make_connection(self.enhanced_request(request)) now = datetime.datetime.utcnow() connection.metadata.created = now connection.metadata.updated = now self.repo.save(connection) sqs.publish(str(to_json(vars(ConnectionCreated(connection.model))))) return {'connection_id': connection.connection_id}
def run(self, logger=None): while True: try: for message in sqs.receive(): if 'Body' in message: print(message['Body']) connection = make_connection( from_json(message['Body'])['body']) print(connection) ConnectionService().connection_created(connection) sqs.delete(message) except Exception as e: logger.exception(e) sleep(1)
def tally_main(self, cr, uid, ids, context=None): form_obj = self.pool.get('tally.connection') obj = form_obj.browse(cr, uid, ids[0], context=context) conn = connection.make_connection(obj.url) company = obj.company daybook = obj.daybook def _processData(s): f = self.createTempFile(s) configdict = etree_parser.ConvertXmlToDict(f.name) if not configdict: return {} tallyData = dict(configdict) obj_migrator = migrator.migrator() obj_migrator.insertData(cr, uid, company, tallyData) self.deleteTempFile() if obj.ledgers: s = self.getData("Ledgers", conn) _processData(s) elif obj.groups: s = self.getData("Groups", conn) _processData(s) if obj.vouchers: s = self.getData("Ledgers", conn) _processData(s) try: configdict = etree_parser.ConvertXmlToDict(daybook) except Exception, e: raise osv.except_osv(('No such file or directory'), str(e)) if not configdict: return {} tallyData = dict(configdict) obj_voucher = voucher.voucher(cr) obj_voucher.insertVoucherData(cr, uid, company, tallyData)
def test_connection_serialization(self, model_valid): dumps = json.dumps(make_connection(model_valid).model).encode() print(dumps) assert dumps
def test_name_required(self, model_valid): model = copy.deepcopy(model_valid) del model['name'] with pytest.raises(KeyError) as err: make_connection(model)
def test_connection_id_is_uuid(self, model_valid): model_valid['connection_id'] = '5ee7dcd0-54' with pytest.raises(ValueError) as err: make_connection(model_valid)
def test_resource_created_when_valid_request(self, model_valid): connection = make_connection(model_valid) assert connection.name == model_valid['name'] assert connection.connector_type == model_valid['connector_type']
def list(self): return [make_connection(item) for item in self.table.scan()['Items']]
def get(self, connection_id): response = self.table.get_item(Key={'connection_id': connection_id}) if 'Item' not in response: return None return make_connection(response['Item'])
def test_resource_created_when_valid_request(self, model_valid): connection = make_connection(model_valid) assert connection
def test_profile_id_required(self, model_valid): del model_valid['parameters']['profile_id'] with pytest.raises(KeyError) as err: make_connection(model_valid)