Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod Zeep service to allow basic authentication #27

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions primestg/service.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
# -*- coding: UTF-8 -*-

from zeep import Client
from zeep.transports import Transport
from requests import Session
from requests.auth import HTTPBasicAuth
import primestg


class Service(object):
def __init__(self, fact_id, cnc_url, sync=True, source=None):
self.cnc_url = cnc_url
self.fact_id = fact_id
self.sync = sync
if not source:
def __init__(self, dc_vals):
self.cnc_url = dc_vals['url']
self.fact_id = dc_vals['request_id']
self.sync = dc_vals['sync']
if dc_vals.get('source', False):
self.source = dc_vals['source']
else:
self.source = 'DCF' # By default it doesn't look to the meter for data
if dc_vals.get('user', False) and dc_vals.get('password', False):
self.auth = True
self.user = dc_vals['user']
self.password = dc_vals['password']
else:
self.source = source
self.auth = False
self.DC_service = self.create_service()

def send(self, report_id, meters, date_from='', date_to=''):
Expand All @@ -29,7 +38,13 @@ def send(self, report_id, meters, date_from='', date_to=''):

def create_service(self):
binding = '{http://www.asais.fr/ns/Saturne/DC/ws}WS_DCSoap'
client = Client(wsdl=primestg.get_data('WS_DC.wsdl'))
if self.auth:
session = Session()
session.auth = HTTPBasicAuth(self.user, self.password)
client = Client(wsdl=primestg.get_data('WS_DC.wsdl'),
transport=Transport(session=session))
else:
client = Client(wsdl=primestg.get_data('WS_DC.wsdl'))
client.set_ns_prefix(None, 'http://www.asais.fr/ns/Saturne/DC/ws')
return client.create_service(binding, self.cnc_url)

Expand Down
6 changes: 2 additions & 4 deletions spec/Report_S02_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,5 @@
with open(result_filename) as result_file:
result_string = result_file.read()
expected_result = literal_eval(result_string)

result = self.report[key].values

expect(result).to(equal(expected_result))
result = self.report[key].values
expect(result).to(equal(expected_result))
8 changes: 7 additions & 1 deletion spec/web_service_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

with description('Web services run'):
with before.all:
self.s = Service(1, 'http://cct.gisce.lan:8080/')
vals = {
'url': 'http://cct.gisce.lan:8080/',
'request_id': 12,
'sync': False,
'source': 'DCF',
}
self.s = Service(vals)

with it('asking for S02 report with mocked connection'):
with responses.RequestsMock() as rsps:
Expand Down