Ofono template: Add missing properties to SimManager interface #21

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Contributor

pete-woods commented Jun 2, 2016

No description provided.

dbusmock/templates/ofono.py
@@ -47,6 +49,19 @@ def load(mock, parameters):
mock.AddModem(parameters.get('ModemName', 'ril_0'), {})
+def newSimSerial():
@martinpitt

martinpitt Jun 5, 2016

Owner

python_style, not camelCase please. This isn't a D-Bus method.

dbusmock/templates/ofono.py
@@ -47,6 +49,19 @@ def load(mock, parameters):
mock.AddModem(parameters.get('ModemName', 'ril_0'), {})
+def newSimSerial():
+ global _simSerialCounter
+ serial = 'ed752c5f-f723-437e-bc6c-' + ('%012d' % _simSerialCounter)
@martinpitt

martinpitt Jun 5, 2016

Owner

This this serial magic in any way? I. e. does ofono do something special for this prefix? If so, please add a comment. If it's just a random number, maybe 12345..abcd? (but that's just a nitpick)

dbusmock/templates/ofono.py
+
+def newImsi():
+ global _imsiCounter
+ imsi = '310150' + ('%09d' % _imsiCounter)
@martinpitt

martinpitt Jun 5, 2016

Owner

same two issues/questions.

dbusmock/templates/ofono.py
@@ -79,6 +94,7 @@ def AddModem(self, name, properties):
'Manufacturer': dbus.String('Fakesys', variant_level=1),
'Model': dbus.String('Mock Modem', variant_level=1),
'Revision': dbus.String('0815.42', variant_level=1),
+ 'Serial': dbus.String(newSimSerial(), variant_level=1),
@martinpitt

martinpitt Jun 5, 2016

Owner

So newSimSerial() is only being called once, ever. Why the overhead with the function and counter instead of just setting it to a static value and letting the test case drive/set it? Mocks shouldn't be doing unnecessary things by themselves, especially not if the "real thing" doesn't do the same. And I doubt that the serial number changes?

dbusmock/templates/ofono.py
'Present': _parameters.get('Present', dbus.Boolean(True)),
'Retries': _parameters.get('Retries', dbus.Dictionary([["pin", dbus.Byte(3)], ["puk", dbus.Byte(10)]])),
'PinRequired': _parameters.get('PinRequired', "none"),
'SubscriberNumbers': _parameters.get('SubscriberNumbers', ['123456789', '234567890']),
- 'SubscriberIdentity': _parameters.get('SubscriberIdentity', "23456"),
+ 'SubscriberIdentity': _parameters.get('SubscriberIdentity', newImsi()),
@martinpitt

martinpitt Jun 5, 2016

Owner

Same question here as for Serial.

@martinpitt

martinpitt Jun 5, 2016

Owner

If you do need some dynamic stuff here, please add a simple test case.

Contributor

pete-woods commented Jun 6, 2016

Okay, I've tried to address all your comments.

  • I used snake_casing throughout now.
  • Added comments to make it clear why we are generating the IMSI / modem serial.
  • Made the counters be member variables so they get reset for each test case.
  • Added a basic that shows the counter increments as we add new modems + SIMs.
+# Use a counter so that the result is predictable for tests.
+def new_modem_serial(mock):
+ serial = '12345678-1234-1234-1234-' + ('%012d' % mock.modem_serial_counter)
+ mock.modem_serial_counter = mock.modem_serial_counter + 1
@martinpitt

martinpitt Jun 6, 2016

Owner

+= 1 please, to avoid the repetition of the long var, and easier to read.

+# Use a counter so that the result is predictable for tests.
+def new_imsi(mock):
+ imsi = '310150' + ('%09d' % mock.imsi_counter)
+ mock.imsi_counter = mock.imsi_counter + 1
@@ -11,7 +11,7 @@
__email__ = 'martin.pitt@ubuntu.com'
__copyright__ = '(c) 2012 Canonical Ltd.'
__license__ = 'LGPL 3+'
-__version__ = '0.16.3'
+__version__ = '0.16.4'
@martinpitt

martinpitt Jun 6, 2016

Owner

This gets done automatically on release, commits shouldn't touch this. Please revert.

Owner

martinpitt commented Jun 6, 2016

Very nice, thanks! Only three nitpicks, but I'm happy to do them myself during merging, unless you beat me to them. Will merge/test/release tomorrow morning (sorry, running late today).

Owner

martinpitt commented Jun 7, 2016

Merged with the above nitpick changes. Thanks!

@martinpitt martinpitt closed this Jun 7, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment