Skip to content

Commit 54ef88c

Browse files
committed
[IMP] Test OLS05002 to OLS5012
1 parent ae796ac commit 54ef88c

File tree

9 files changed

+266
-0
lines changed

9 files changed

+266
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
3+
{
4+
'name' : 'Module for Diagnostics (Odoo Bikes Parts)',
5+
'version' : '1.0',
6+
'summary': 'Test Module for Diagnostics',
7+
'sequence': 100,
8+
'description': """
9+
Module for Diagnostics
10+
====================
11+
This is the description of the module for diagnostics
12+
""",
13+
'depends' : [],
14+
'installable': True,
15+
'application': True,
16+
'license': 'LGPL-3',
17+
"data": [
18+
"data/bikes.xml",
19+
"data/bike_parts.wheel.csv"
20+
],
21+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id,name,price
2+
bike_wheel_6,Road Bike Wheel2,200.0
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<odoo>
2+
<!-- Bike Wheels -->
3+
<record id="bike_wheel_1" model="bike_parts.wheel">
4+
<field name="name">Standard Wheel</field>
5+
<field name="price">100.0</field>
6+
</record>
7+
<record id="bike_wheel_2" model="bike_parts.wheel">
8+
<field name="name">Mountain Bike Wheel</field>
9+
<field name="price">150.0</field>
10+
</record>
11+
<record id="bike_wheel_3" model="bike_parts.wheel">
12+
<field name="name">Road Bike Wheel</field>
13+
<field name="price">200.0</field>
14+
</record>
15+
<!-- Bikes -->
16+
<record id="bike_1" model="bikes.bike">
17+
<field name="name">City Bike</field>
18+
<field name="wheel_id" ref="bike_wheel_1"/>
19+
</record>
20+
<record id="bike_2" model="bikes.bike">
21+
<field name="name">Mountain Bike</field>
22+
<field name="wheel_id" ref="bike_wheel_2"/>
23+
</record>
24+
<record id="bike_3" model="bikes.bike">
25+
<field name="name">Road Bike</field>
26+
<field name="wheel_id" ref="WRONG_MODULE.bike_wheel_6"/> <!-- OLS05003 -->
27+
</record>
28+
<record id="bike_3" model="bikes.bike">
29+
<field name="name">Road Bike</field>
30+
<field name="wheel_id" ref="bike_wheel_DOES_NOT_EXIST"/> <!-- OLS05001 -->
31+
</record>
32+
<record id="actie" model="ir.actions.act_window">
33+
<field name="name">Forward port batches</field>
34+
<field name="res_model">bikes.bike</field>
35+
<field name="context">{'active_test': False}</field>
36+
</record>
37+
<odoo oh="no"> <!-- OLS05004 -->
38+
</odoo>
39+
<invalid_tag/> <!-- OLS05005 -->
40+
<menuitem/> <!-- OLS05006 missing id-->
41+
<menuitem id="whoopla" invalid_attr="boom"/> <!-- OLS05007 -->
42+
<menuitem id="whoopla" sequence="not an integer"/> <!-- OLS05008 -->
43+
<menuitem id="whoopla_child" parent="whoopla" action="actie" web_icon="not_allowed"> <!-- OLS05010 -->
44+
<menuitem id="whoopla_child^2"/> <!-- OLS05009 -->
45+
<!-- / -->
46+
<invalid id="whoopla_child^2"/> <!-- OLS05011 -->
47+
</menuitem>
48+
<menuitem id="whoopla_child" action="actie" web_icon="not_allowed">
49+
<menuitem id="whoopla_child^2" parent="whoopla"/> <!-- OLS05012 -->
50+
</menuitem>
51+
</odoo>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<odoo>
2+
</odoo>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import bike_parts_wheel
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 1. Imports are resolved
2+
from odoo import api, fields, models
3+
4+
class BikePartsWheel(models.Model):
5+
_name = 'bike_parts.wheel'
6+
_description = 'Bike Wheel'
7+
8+
name = fields.Char(string='Wheel Name', required=True)
9+
price = fields.Float(string='Price', required=True)
10+
available = fields.Boolean(string='Available', default=True)
11+
description = fields.Text(string='Description')
12+
13+
class BikesBike(models.Model):
14+
_name = 'bikes.bike'
15+
16+
name = fields.Char(string='Wheel Name', required=True)
17+
wheel_id = fields.Many2one('bike_parts.wheel', string='Wheel')
18+
bike_weight = fields.Float(string='Bike Weight (kg)', compute='_compute_bike_weight', store=True)
19+
20+
@api.depends('wheel_id.price')
21+
def _compute_bike_weight(self):
22+
for bike in self:
23+
if bike.wheel_id:
24+
bike.bike_weight = bike.wheel_id.price * 0.5
25+
else:
26+
bike.bike_weight = 0.0
27+
self.env.ref('module_for_diagnostics.bike_wheel_DOES_NOT_EXIST') # TODO: OLS05001
28+
self.env.ref('bike_wheel_DOES_NOT_EXIST') # OLS05002
29+
self.env.ref('module_for_diagnostics.bike_wheel_6') # Ok
30+
self.env.ref('WRONG_MODULE.bike_wheel_6') # OLS05003

server/tests/diagnostics/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ pub mod ols01004;
77
pub mod ols01005;
88
pub mod ols01006;
99
pub mod ols01007;
10+
pub mod ols0500_00_12;
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
use std::path::PathBuf;
2+
3+
use lsp_types::{DiagnosticSeverity, NumberOrString};
4+
use odoo_ls_server::{S, utils::PathSanitizer};
5+
6+
use crate::{setup::setup::*, test_utils::{diag_on_line, verify_diagnostics_against_doc}};
7+
8+
#[test]
9+
fn test_ols05000_2_3_py_file() {
10+
let (mut odoo, config) = setup_server(true);
11+
let mut session = create_init_session(&mut odoo, config);
12+
let test_addons_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests").join("data").join("addons");
13+
let bikes_py_path = test_addons_path.join("module_for_diagnostics").join("models").join("bike_parts_wheel.py");
14+
assert!(PathBuf::from(&bikes_py_path).exists(), "Test file does not exist: {}", bikes_py_path.display());
15+
let bikes_py_diagnostics = get_diagnostics_for_path(&mut session, &bikes_py_path.sanitize());
16+
let doc_diags = get_diagnostics_test_comments(&mut session, &bikes_py_path.sanitize());
17+
verify_diagnostics_against_doc(bikes_py_diagnostics, doc_diags); // OLS05002 & OLS05003
18+
}
19+
#[test]
20+
fn test_ols050000_to50012_xml_file() {
21+
let (mut odoo, config) = setup_server(true);
22+
let mut session = create_init_session(&mut odoo, config);
23+
let test_addons_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests").join("data").join("addons");
24+
let bikes_xml_path = test_addons_path.join("module_for_diagnostics").join("data").join("bikes.xml");
25+
assert!(PathBuf::from(&bikes_xml_path).exists(), "Test file does not exist: {}", bikes_xml_path.display());
26+
let bikes_xml_diagnostics = get_diagnostics_for_path(&mut session, &bikes_xml_path.sanitize());
27+
// OLS05001 - Disabled TODO: Re-enable when OLS05001 is implemented
28+
// OLS05003
29+
let ols50003_diagnostics = diag_on_line(&bikes_xml_diagnostics, 25);
30+
assert_eq!(ols50003_diagnostics.len(), 1);
31+
let diag = &ols50003_diagnostics[0];
32+
assert!(diag.code.is_some());
33+
let code = match &diag.code {
34+
Some(NumberOrString::String(code)) => code,
35+
Some(NumberOrString::Number(num)) => panic!("Unexpected numeric code: {}", num),
36+
None => panic!("Diagnostic code is None"),
37+
};
38+
assert!(code == &S!("OLS05003"));
39+
assert!(diag.severity.is_some_and(|s| s == DiagnosticSeverity::ERROR));
40+
41+
// OLS05004
42+
let ols50004_diagnostics = diag_on_line(&bikes_xml_diagnostics, 36);
43+
assert_eq!(ols50004_diagnostics.len(), 1);
44+
let diag = &ols50004_diagnostics[0];
45+
assert!(diag.code.is_some());
46+
let code = match &diag.code {
47+
Some(NumberOrString::String(code)) => code,
48+
Some(NumberOrString::Number(num)) => panic!("Unexpected numeric code: {}", num),
49+
None => panic!("Diagnostic code is None"),
50+
};
51+
assert!(code == &S!("OLS05004"));
52+
assert!(diag.severity.is_some_and(|s| s == DiagnosticSeverity::ERROR));
53+
54+
// OLS05005
55+
let ols50005_diagnostics = diag_on_line(&bikes_xml_diagnostics, 38);
56+
assert_eq!(ols50005_diagnostics.len(), 1);
57+
let diag = &ols50005_diagnostics[0];
58+
assert!(diag.code.is_some());
59+
let code = match &diag.code {
60+
Some(NumberOrString::String(code)) => code,
61+
Some(NumberOrString::Number(num)) => panic!("Unexpected numeric code: {}", num),
62+
None => panic!("Diagnostic code is None"),
63+
};
64+
assert!(code == &S!("OLS05005"));
65+
assert!(diag.severity.is_some_and(|s| s == DiagnosticSeverity::ERROR));
66+
67+
// OLS05006
68+
let ols50006_diagnostics = diag_on_line(&bikes_xml_diagnostics, 39);
69+
assert_eq!(ols50006_diagnostics.len(), 1);
70+
let diag = &ols50006_diagnostics[0];
71+
assert!(diag.code.is_some());
72+
let code = match &diag.code {
73+
Some(NumberOrString::String(code)) => code,
74+
Some(NumberOrString::Number(num)) => panic!("Unexpected numeric code: {}", num),
75+
None => panic!("Diagnostic code is None"),
76+
};
77+
assert!(code == &S!("OLS05006"));
78+
assert!(diag.severity.is_some_and(|s| s == DiagnosticSeverity::ERROR));
79+
80+
// OLS05007
81+
let ols50007_diagnostics = diag_on_line(&bikes_xml_diagnostics, 40);
82+
assert_eq!(ols50007_diagnostics.len(), 1);
83+
let diag = &ols50007_diagnostics[0];
84+
assert!(diag.code.is_some());
85+
let code = match &diag.code {
86+
Some(NumberOrString::String(code)) => code,
87+
Some(NumberOrString::Number(num)) => panic!("Unexpected numeric code: {}", num),
88+
None => panic!("Diagnostic code is None"),
89+
};
90+
assert!(code == &S!("OLS05007"));
91+
assert!(diag.severity.is_some_and(|s| s == DiagnosticSeverity::ERROR));
92+
93+
// OLS05008
94+
let ols50008_diagnostics = diag_on_line(&bikes_xml_diagnostics, 41);
95+
assert_eq!(ols50008_diagnostics.len(), 1);
96+
let diag = &ols50008_diagnostics[0];
97+
assert!(diag.code.is_some());
98+
let code = match &diag.code {
99+
Some(NumberOrString::String(code)) => code,
100+
Some(NumberOrString::Number(num)) => panic!("Unexpected numeric code: {}", num),
101+
None => panic!("Diagnostic code is None"),
102+
};
103+
assert!(code == &S!("OLS05008"));
104+
assert!(diag.severity.is_some_and(|s| s == DiagnosticSeverity::ERROR));
105+
106+
// OLS05009
107+
let ols50009_diagnostics = diag_on_line(&bikes_xml_diagnostics, 43);
108+
assert_eq!(ols50009_diagnostics.len(), 1);
109+
let diag = &ols50009_diagnostics[0];
110+
assert!(diag.code.is_some());
111+
let code = match &diag.code {
112+
Some(NumberOrString::String(code)) => code,
113+
Some(NumberOrString::Number(num)) => panic!("Unexpected numeric code: {}", num),
114+
None => panic!("Diagnostic code is None"),
115+
};
116+
assert!(code == &S!("OLS05009"));
117+
assert!(diag.severity.is_some_and(|s| s == DiagnosticSeverity::ERROR));
118+
119+
// OLS05010
120+
let ols50010_diagnostics = diag_on_line(&bikes_xml_diagnostics, 42);
121+
assert_eq!(ols50010_diagnostics.len(), 1);
122+
let diag = &ols50010_diagnostics[0];
123+
assert!(diag.code.is_some());
124+
let code = match &diag.code {
125+
Some(NumberOrString::String(code)) => code,
126+
Some(NumberOrString::Number(num)) => panic!("Unexpected numeric code: {}", num),
127+
None => panic!("Diagnostic code is None"),
128+
};
129+
assert!(code == &S!("OLS05010"));
130+
assert!(diag.severity.is_some_and(|s| s == DiagnosticSeverity::ERROR));
131+
132+
// OLS05011
133+
let ols50011_diagnostics = diag_on_line(&bikes_xml_diagnostics, 45);
134+
assert_eq!(ols50011_diagnostics.len(), 1);
135+
let diag = &ols50011_diagnostics[0];
136+
assert!(diag.code.is_some());
137+
let code = match &diag.code {
138+
Some(NumberOrString::String(code)) => code,
139+
Some(NumberOrString::Number(num)) => panic!("Unexpected numeric code: {}", num),
140+
None => panic!("Diagnostic code is None"),
141+
};
142+
assert!(code == &S!("OLS05011"));
143+
assert!(diag.severity.is_some_and(|s| s == DiagnosticSeverity::ERROR));
144+
145+
// OLS05012
146+
let ols50012_diagnostics = diag_on_line(&bikes_xml_diagnostics, 48);
147+
assert_eq!(ols50012_diagnostics.len(), 1);
148+
let diag = &ols50012_diagnostics[0];
149+
assert!(diag.code.is_some());
150+
let code = match &diag.code {
151+
Some(NumberOrString::String(code)) => code,
152+
Some(NumberOrString::Number(num)) => panic!("Unexpected numeric code: {}", num),
153+
None => panic!("Diagnostic code is None"),
154+
};
155+
assert!(code == &S!("OLS05012"));
156+
assert!(diag.severity.is_some_and(|s| s == DiagnosticSeverity::ERROR));
157+
}

0 commit comments

Comments
 (0)