Skip to content

Commit fe6ef0f

Browse files
Fix primary keys tests
1 parent 5146aa2 commit fe6ef0f

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

pymysqlreplication/column.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __parse_column_definition(self, column_type, column_schema, packet):
2424
self.data["comment"] = column_schema["COLUMN_COMMENT"]
2525
self.data["unsigned"] = False
2626
self.data["type_is_bool"] = False
27-
if "COLUMN_KEY" in column_schema and column_schema["COLUMN_KEY"] == "PRI":
27+
if column_schema["COLUMN_KEY"] == "PRI":
2828
self.data["is_primary"] = True
2929
else:
3030
self.data["is_primary"] = False

pymysqlreplication/tests/test_data_objects.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,36 @@
99

1010

1111
class TestDataObjects(base.PyMySQLReplicationTestCase):
12-
def test_column(self):
12+
def test_column_is_primary(self):
1313
col = Column(1,
1414
{"COLUMN_NAME": "test",
1515
"COLLATION_NAME": "utf8_general_ci",
1616
"CHARACTER_SET_NAME": "UTF8",
1717
"COLUMN_COMMENT": "",
18-
"COLUMN_TYPE": "tinyint(2)"},
18+
"COLUMN_TYPE": "tinyint(2)",
19+
"COLUMN_KEY": "PRI"},
20+
None)
21+
self.assertEqual(True, col.is_primary)
22+
23+
def test_column_not_primary(self):
24+
col = Column(1,
25+
{"COLUMN_NAME": "test",
26+
"COLLATION_NAME": "utf8_general_ci",
27+
"CHARACTER_SET_NAME": "UTF8",
28+
"COLUMN_COMMENT": "",
29+
"COLUMN_TYPE": "tinyint(2)",
30+
"COLUMN_KEY": ""},
31+
None)
32+
self.assertEqual(False, col.is_primary)
33+
34+
def test_column_serializable(self):
35+
col = Column(1,
36+
{"COLUMN_NAME": "test",
37+
"COLLATION_NAME": "utf8_general_ci",
38+
"CHARACTER_SET_NAME": "UTF8",
39+
"COLUMN_COMMENT": "",
40+
"COLUMN_TYPE": "tinyint(2)",
41+
"COLUMN_KEY": "PRI"},
1942
None)
2043

2144
serialized = col.serializable_data()
@@ -26,6 +49,7 @@ def test_column(self):
2649
self.assertIn("comment", serialized)
2750
self.assertIn("unsigned", serialized)
2851
self.assertIn("type_is_bool", serialized)
52+
self.assertIn("is_primary", serialized)
2953

3054
self.assertEqual(col, Column(**serialized))
3155

0 commit comments

Comments
 (0)