File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 13
13
UNSIGNED_64BIT_INT_MAX_VALUE = 2 ** 64 - 1
14
14
15
15
16
- hex_re = re .compile (r"^(([0-9A-f])|(0x [0-9A -f])) +$" )
16
+ hex_re = re .compile (r"^(0x)?( [0-9a -f])+$" , re . I )
17
17
signed_integer_vendors = [
18
18
"postgresql" ,
19
19
"sqlite" ,
Original file line number Diff line number Diff line change
1
+ from django .core .exceptions import ValidationError
2
+ from django .test import SimpleTestCase
3
+
4
+ from push_notifications .fields import HexadecimalField
5
+
6
+
7
+ class HexadecimalFieldTestCase (SimpleTestCase ):
8
+ _INVALID_HEX_VALUES = [
9
+ "foobar" ,
10
+ "GLUTEN" ,
11
+ "HeLLo WoRLd" ,
12
+ "international" ,
13
+ "°!#€%&/()[]{}=?" ,
14
+ "0x" ,
15
+ ]
16
+
17
+ _VALID_HEX_VALUES = {
18
+ "babe" : "babe" ,
19
+ "BEEF" : "BEEF" ,
20
+ " \n feed \t " : "feed" ,
21
+ "0x012345789abcdef" : "0x012345789abcdef" ,
22
+ "012345789aBcDeF" : "012345789aBcDeF" ,
23
+ }
24
+
25
+ def test_clean_invalid_values (self ):
26
+ """Passing invalid values raises ValidationError."""
27
+ f = HexadecimalField ()
28
+ for invalid in self ._INVALID_HEX_VALUES :
29
+ self .assertRaisesMessage (
30
+ ValidationError ,
31
+ "'Enter a valid hexadecimal number'" ,
32
+ f .clean ,
33
+ invalid ,
34
+ )
35
+
36
+ def test_clean_valid_values (self ):
37
+ """Passing valid values returns the expected output."""
38
+ f = HexadecimalField ()
39
+ for valid , expected in self ._VALID_HEX_VALUES .items ():
40
+ self .assertEqual (expected , f .clean (valid ))
You can’t perform that action at this time.
0 commit comments