]> git.aero2k.de Git - sirius.git/commitdiff
Tests are green! So many warnings, but progress
authorJoshua May <notjosh@gmail.com>
Tue, 10 Sep 2019 18:19:22 +0000 (11:19 -0700)
committerJoshua May <notjosh@gmail.com>
Tue, 10 Sep 2019 18:19:22 +0000 (11:19 -0700)
Makefile
docker-compose.test.yml
docker-compose.yml
sirius/coding/claiming.py
sirius/coding/encoders.py
sirius/coding/image_encoding.py
sirius/coding/test_image_coding.py
sirius/testing/base.py
sirius/web/test_friends.py
sirius/web/test_printing.py

index 33eee6b9c6843ddf560b8727b14405b1f656a95a..76c2a72cb0e9e5ffccfdc220bb89cd2a990a29c9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,4 +3,4 @@ run-development:
 
 run-test:
        docker rm -v sirius-database-test || true
-       docker-compose -f docker-compose.yml -f docker-compose.test.yml up
\ No newline at end of file
+       docker-compose -f docker-compose.yml -f docker-compose.test.yml up --build
\ No newline at end of file
index 15e4baf22e3ac5721a03ee061290e95dc62791f0..b998f7456ab5dde0c484c6f39a49ce1b79c18734 100644 (file)
@@ -4,8 +4,9 @@ services:
   sirius:
     depends_on:
       - sirius-database-test
+    command: "bin/wait-for-it.sh sirius-database-test:5432 -- bin/docker-entrypoint.sh"
     environment:
-      - DATABASE_URL=postgresql://postgres:plop@sirius-database/sirius-test
+      - DATABASE_URL=postgresql://postgres:plop@sirius-database-test/sirius-test
 
   sirius-database-test:
     container_name: sirius-database-test
@@ -15,3 +16,8 @@ services:
     environment:
       - POSTGRES_DB=sirius-test
       - POSTGRES_PASSWORD=plop
+
+  sirius-web:
+    ports:
+      - "8880:80"
+      - "8443:443"
index 2c4133d3fd75e3b10168bb6d4a34df8d1b4c5133..fb324831e12049ecf3c22cea8254a313943c4459 100644 (file)
@@ -7,13 +7,7 @@ services:
       dockerfile: ./Dockerfile
     depends_on:
       - sirius-web
-    command:
-      [
-        "bin/wait-for-it.sh",
-        "sirius-database:5432",
-        "--",
-        "bin/docker-entrypoint.sh",
-      ]
+    command: "bin/wait-for-it.sh sirius-database:5432 -- bin/docker-entrypoint.sh"
     environment:
       - OPENSSL_CONF=/etc/ssl/
 
index 8950917358fb872a78fd0538833519684743cd4d..a3784e1e244aca8142244b1d14bc339e345cea20 100755 (executable)
@@ -100,30 +100,30 @@ def generate_link_key(input):
 
         # Pad with the original length encoded as a 16bit int
         # Python3
-        #input = input + bytes( [((input_length * 8) >> 8 & 0xff)] )
-        #input = input + bytes( [((input_length * 8) >> 0 & 0xff)] )
+        input = input + bytes( [((input_length * 8) >> 8 & 0xff)] )
+        input = input + bytes( [((input_length * 8) >> 0 & 0xff)] )
         # Python2
-        input = input + chr((input_length * 8) >> 8 & 0xff)
-        input = input + chr((input_length * 8) >> 0 & 0xff)
+        # input = input + chr((input_length * 8) >> 8 & 0xff)
+        # input = input + chr((input_length * 8) >> 0 & 0xff)
 
     elif input_length != ZBEE_SEC_CONST_BLOCKSIZE:
         raise InvalidClaimCode("cannot handle input size %d" % input_length)
 
     # We encrypt the salt and the input bytes
-    # blocks = [bytes(CLAIM_CODE_SALT), input] # Python3
-    blocks = [str(bytearray(CLAIM_CODE_SALT)), input] # Python2
+    blocks = [bytes(CLAIM_CODE_SALT), input] # Python3
+    # blocks = [str(bytearray(CLAIM_CODE_SALT)), input] # Python2
 
-    #output = bytes(16) # Works in Python3
-    output = bytearray(16) # Works in Python2
+    output = bytes(16) # Works in Python3
+    # output = bytearray(16) # Works in Python2
 
     for block in blocks:
-        # aes_encoder = AES.new(output, AES.MODE_ECB) # Python3
-        aes_encoder = AES.new(str(output), AES.MODE_ECB) # Python2
+        aes_encoder = AES.new(output, AES.MODE_ECB) # Python3
+        # aes_encoder = AES.new(str(output), AES.MODE_ECB) # Python2
         h = aes_encoder.encrypt(block)
         output = bytearray(16)
         for i in range(len(output)):
-            # output[i] = h[i] ^ block[i] # Python3
-            output[i] = ord(h[i]) ^ ord(block[i]) # Python2
+            output[i] = h[i] ^ block[i] # Python3
+            # output[i] = ord(h[i]) ^ ord(block[i]) # Python2
         output = bytes(output)
 
     return output
@@ -142,8 +142,8 @@ def process_claim_code(claim_code):
 
     # Generate our own CRC from the raw_value, and confirm it matches the extracted crc
     data_for_crc = struct.pack("<Q", raw_value & 0xffffffffffffffff)
-    #server_crc = crc16(data_for_crc) # this works in Python3
-    server_crc = crc16( bytearray(data_for_crc) ) # this works in Python2
+    server_crc = crc16(data_for_crc) # this works in Python3
+    # server_crc = crc16( bytearray(data_for_crc) ) # this works in Python2
 
     if server_crc != crc:
         raise InvalidClaimCode("CRC problem")
index 6e9d3836a4966ba3a237374ec3b6bc27ddd6c5d7..a0748021a7b02d47cd49e57bcc9305b67993ffab 100644 (file)
@@ -96,7 +96,9 @@ def encode_bridge_command(bridge_address, command, command_id, timestamp):
                 'name': 'add_device_encryption_key',
                 'params': {
                     'device_address': command.device_address,
-                    'encryption_key': claiming.key_from_claim_code(command.claim_code),
+                    'encryption_key': base64.b64encode(
+                        claiming.key_from_claim_code(command.claim_code)
+                    ).decode('utf-8'),
                 },
             },
         })
@@ -104,7 +106,7 @@ def encode_bridge_command(bridge_address, command, command_id, timestamp):
     elif type(command) == messages.SetDeliveryAndPrint:
         return make({
             'binary_payload': base64.b64encode(_encode_printer_message(
-                0x1, _payload_from_pixels(command.pixels), command_id)),
+                0x1, _payload_from_pixels(command.pixels), command_id)).decode('utf-8'),
             'device_address': command.device_address,
             'type': 'DeviceCommand',
         })
@@ -112,7 +114,7 @@ def encode_bridge_command(bridge_address, command, command_id, timestamp):
     elif type(command) == messages.SetDelivery:
         return make({
             'binary_payload': base64.b64encode(_encode_printer_message(
-                0x2, _payload_from_pixels(command.pixels), command_id)),
+                0x2, _payload_from_pixels(command.pixels), command_id)).decode('utf-8'),
             'device_address': command.device_address,
             'type': 'DeviceCommand',
         })
@@ -120,7 +122,7 @@ def encode_bridge_command(bridge_address, command, command_id, timestamp):
     elif type(command) == messages.SetDeliveryAndPrintNoFace:
         return make({
             'binary_payload': base64.b64encode(_encode_printer_message(
-                0x11, _payload_from_pixels(command.pixels), command_id)),
+                0x11, _payload_from_pixels(command.pixels), command_id)).decode('utf-8'),
             'device_address': command.device_address,
             'type': 'DeviceCommand',
         })
@@ -128,7 +130,7 @@ def encode_bridge_command(bridge_address, command, command_id, timestamp):
     elif type(command) == messages.SetDeliveryNoFace:
         return make({
             'binary_payload': base64.b64encode(_encode_printer_message(
-                0x12, _payload_from_pixels(command.pixels), command_id)),
+                0x12, _payload_from_pixels(command.pixels), command_id)).decode('utf-8'),
             'device_address': command.device_address,
             'type': 'DeviceCommand',
         })
@@ -142,7 +144,7 @@ def encode_bridge_command(bridge_address, command, command_id, timestamp):
 
         return make({
             'binary_payload': base64.b64encode(_encode_printer_message(
-                0x0102, payload, command_id)),
+                0x0102, payload, command_id)).decode('utf-8'),
             'device_address': command.device_address,
             'type': 'DeviceCommand',
         })
@@ -157,7 +159,7 @@ def encode_bridge_command(bridge_address, command, command_id, timestamp):
 
         return make({
             'binary_payload': base64.b64encode(_encode_printer_message(
-                0x0101, payload, command_id)),
+                0x0101, payload, command_id)).decode('utf-8'),
             'device_address': command.device_address,
             'type': 'DeviceCommand',
         })
@@ -170,7 +172,7 @@ def encode_bridge_command(bridge_address, command, command_id, timestamp):
 
         return make({
             'binary_payload': base64.b64encode(_encode_printer_message(
-                0x202, payload, command_id)),
+                0x202, payload, command_id)).decode('utf-8'),
             'device_address': command.device_address,
             'type': 'DeviceCommand',
         })
index 3299daffc51697d6dc926c3f8bab949cef903dc1..62625bbaa88a34d533c504ebf4ff8562483639a5 100644 (file)
@@ -118,7 +118,7 @@ def html_to_png(html):
         # note that the .html suffix is required to make phantomjs
         # pick up the mime-type and render correctly.
         with tempfile.NamedTemporaryFile(suffix='.html') as f:
-            if isinstance(html, unicode):
+            if isinstance(html, str):
                 f.write(html.encode('utf8'))
             else:
                 f.write(html)
index 502f425d74ab210f7314de97a45d7f0645174ccf..eb69291da19abd6b285bd8c9e8185164b31f35d9 100644 (file)
@@ -31,7 +31,7 @@ class PipeTestCase(unittest.TestCase):
 
         image = Image.open(data)
         image = image_encoding.crop_384(image)
-        image = image_encoding.threshold(image)
+        # image = image_encoding.threshold(image)
 
         n_bytes, _ = image_encoding.rle_from_bw(image)
         self.assertEquals(n_bytes, 3072)
index f2cf7939de514a1ab0181453e31b4bdc3cf246ae..a256da386968755a349a70ac8ad8702bf1b1a4c0 100644 (file)
@@ -29,6 +29,8 @@ class Base(testing.TestCase):
             )
         )
         db.session.add(self.testuser)
+        db.session.flush()
+        db.session.refresh(self.testuser)
 
     def tearDown(self):
         db.session.rollback()
index afbe16250d0a6348cbee9404a8900d1db081d690..1c7b69166c6db892b3ae7b691ef4c78607d19deb 100644 (file)
@@ -48,11 +48,11 @@ class TestFriends(base.Base):
         f0, _ = self.u0.signed_up_friends()
         f1, _ = self.u1.signed_up_friends()
 
-        self.assertItemsEqual(f0, [
+        self.assertCountEqual(f0, [
             user.Friend('twitter1', 't1', ''),
             user.Friend('twitter2', 't2', '')])
 
-        self.assertItemsEqual(f1, [
+        self.assertCountEqual(f1, [
             user.Friend('twitter2', 't2', '')])
 
 
index 748e6301cc9a4d0deb343477217ebf1bed2d187d..9898749378a740e37cc651ecebe918e387ae3087 100644 (file)
@@ -26,12 +26,17 @@ class TestPrinting(base.Base):
 
     def test_print_ok(self):
         r = self.client.post(self.get_print_url(), data=dict(
-            target_printer=self.printer.id, message='hello'))
-        print(r.headers)
+            target_printer=self.printer.id, 
+            face='default',
+            message='hello'
+        ))
         self.assertRedirects(r, '/printer/1')
 
     def test_print_wrong_printer(self):
         r = self.client.post(self.get_print_url(), data=dict(
-            target_printer='10', message='hello2'))
-        self.assertIn('Not a valid choice', r.data)
+            target_printer='10',
+            face='default',
+            message='hello2'
+        ))
+        self.assertIn('Not a valid choice', r.data.decode('utf-8'))
         self.assert200(r)