mirror of
https://github.com/inventree/inventree-app.git
synced 2026-11-19 20:28:38 +00:00
Fix unit tests in CI (#895)
* use demo data rather than simple fixtures * Remove admin creation in CI * Adjust unit tests * Remove token data from debug log
This commit is contained in:
1 parent
23abf50145
commit
7554bbdfa2
6 files changed
+53
-34
No files matched your search
@@ -16,11 +16,8 @@ env:
|
||||
INVENTREE_MEDIA_ROOT: ../test_inventree_media
|
||||
INVENTREE_STATIC_ROOT: ../test_inventree_static
|
||||
INVENTREE_BACKUP_DIR: ../test_inventree_backup
|
||||
INVENTREE_ADMIN_USER: testuser
|
||||
INVENTREE_ADMIN_PASSWORD: testpassword
|
||||
INVENTREE_ADMIN_EMAIL: test@test.com
|
||||
jobs:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -78,7 +75,7 @@ jobs:
|
||||
cd inventree_server
|
||||
invoke install
|
||||
invoke migrate
|
||||
invoke dev.import-fixtures
|
||||
invoke dev.setup-test -i
|
||||
invoke dev.server -a 127.0.0.1:8000 &
|
||||
invoke wait
|
||||
sleep 30
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# Test files share a single server account, and each requests an API token
|
||||
# with the same name - which revokes any token previously issued under that name.
|
||||
# Run test files sequentially to prevent them invalidating each other's tokens
|
||||
concurrency: 1
|
||||
+12
-1
@@ -590,6 +590,17 @@ class InvenTreeAPI {
|
||||
platform_name += "-" + (deviceInfo["systemVersion"] as String);
|
||||
}
|
||||
|
||||
// The token endpoint depends on the server API version, which may not be
|
||||
// known yet (first login), or may belong to a different server profile.
|
||||
// Note: newer servers will not re-issue an existing token via the legacy endpoint
|
||||
final infoResponse = await get(_makeUrl("/api/", base: userProfile.server));
|
||||
|
||||
if (!infoResponse.successful()) {
|
||||
return infoResponse;
|
||||
}
|
||||
|
||||
serverInfo = {...infoResponse.asMap()};
|
||||
|
||||
// Construct auth header from username and password
|
||||
String authHeader =
|
||||
"Basic " + base64Encode(utf8.encode("${username}:${password}"));
|
||||
@@ -644,7 +655,7 @@ class InvenTreeAPI {
|
||||
// Save the token to the user profile
|
||||
userProfile.token = (data["token"] ?? "") as String;
|
||||
|
||||
debug("Received token from server: ${userProfile.token}");
|
||||
debug("Received token from server");
|
||||
|
||||
await UserProfileDBManager().updateProfile(userProfile);
|
||||
|
||||
|
||||
+13
-6
@@ -69,12 +69,14 @@ void main() {
|
||||
// Tests for scanning a stock item into a location
|
||||
|
||||
test("Scan Into Location", () async {
|
||||
final item = await InvenTreeStockItem().get(1) as InvenTreeStockItem?;
|
||||
final item = await InvenTreeStockItem().get(2) as InvenTreeStockItem?;
|
||||
assert(item != null);
|
||||
|
||||
assert(item!.pk == 1);
|
||||
assert(item!.pk == 2);
|
||||
|
||||
var handler = StockItemScanIntoLocationHandler(item!);
|
||||
final int originalLocation = item!.locationId;
|
||||
|
||||
var handler = StockItemScanIntoLocationHandler(item);
|
||||
|
||||
await handler.processBarcode('{"stocklocation": 7}');
|
||||
// Check the location has been updated
|
||||
@@ -87,6 +89,11 @@ void main() {
|
||||
await handler.processBarcode('{"stocklocation": 1}');
|
||||
await item.reload();
|
||||
assert(item.locationId == 1);
|
||||
|
||||
// Return to the original location
|
||||
await handler.processBarcode('{"stocklocation": ${originalLocation}}');
|
||||
await item.reload();
|
||||
assert(item.locationId == originalLocation);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -103,7 +110,7 @@ void main() {
|
||||
var handler = StockLocationScanInItemsHandler(location!);
|
||||
|
||||
// Scan multiple items into this location
|
||||
for (int id in [1, 2, 11]) {
|
||||
for (int id in [2, 3, 11]) {
|
||||
await handler.processBarcode('{"stockitem": ${id}}');
|
||||
|
||||
var item = await InvenTreeStockItem().get(id) as InvenTreeStockItem?;
|
||||
@@ -120,10 +127,10 @@ void main() {
|
||||
|
||||
test("Scan Parent", () async {
|
||||
final location =
|
||||
await InvenTreeStockLocation().get(7) as InvenTreeStockLocation?;
|
||||
await InvenTreeStockLocation().get(5) as InvenTreeStockLocation?;
|
||||
|
||||
assert(location != null);
|
||||
assert(location!.pk == 7);
|
||||
assert(location!.pk == 5);
|
||||
assert(location!.parentId == 4);
|
||||
|
||||
var handler = ScanParentLocationHandler(location!);
|
||||
|
||||
+20
-20
@@ -27,16 +27,16 @@ void main() {
|
||||
|
||||
// List *all* categories
|
||||
results = await InvenTreePartCategory().list();
|
||||
assert(results.length == 8);
|
||||
expect(results.length, greaterThanOrEqualTo(28));
|
||||
|
||||
for (var result in results) {
|
||||
assert(result is InvenTreePartCategory);
|
||||
}
|
||||
|
||||
// Filter by parent category
|
||||
// Filter by parent category ("Electronics")
|
||||
results = await InvenTreePartCategory().list(filters: {"parent": "1"});
|
||||
|
||||
assert(results.length == 3);
|
||||
expect(results.length, equals(6));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,21 +50,21 @@ void main() {
|
||||
|
||||
// List *all* parts
|
||||
results = await InvenTreePart().list();
|
||||
expect(results.length, equals(14));
|
||||
expect(results.length, greaterThanOrEqualTo(438));
|
||||
|
||||
// List with active filter
|
||||
results = await InvenTreePart().list(filters: {"active": "true"});
|
||||
expect(results.length, greaterThanOrEqualTo(13));
|
||||
expect(results.length, greaterThanOrEqualTo(410));
|
||||
|
||||
for (var result in results) {
|
||||
// results must be InvenTreePart instances
|
||||
assert(result is InvenTreePart);
|
||||
}
|
||||
|
||||
// Filter by category
|
||||
results = await InvenTreePart().list(filters: {"category": "2"});
|
||||
// Filter by category ("Enclosures")
|
||||
results = await InvenTreePart().list(filters: {"category": "15"});
|
||||
|
||||
assert(results.length == 2);
|
||||
expect(results.length, equals(5));
|
||||
});
|
||||
|
||||
test("Part Detail", () async {
|
||||
@@ -77,17 +77,17 @@ void main() {
|
||||
InvenTreePart part = result as InvenTreePart;
|
||||
|
||||
// Check some basic properties of the part
|
||||
assert(part.name == "M2x4 LPHS");
|
||||
assert(part.fullname == "M2x4 LPHS");
|
||||
assert(part.description == "M2x4 low profile head screw");
|
||||
assert(part.categoryId == 8);
|
||||
assert(part.categoryName == "Fasteners");
|
||||
assert(part.image == part.thumbnail);
|
||||
assert(part.thumbnail == "/static/img/blank_image.thumbnail.png");
|
||||
assert(part.name == "R_10R_0402_1%");
|
||||
assert(part.fullname == "R_10R_0402_1%");
|
||||
assert(part.description == "10R resistor in 0402 SMD package");
|
||||
assert(part.categoryId == 5);
|
||||
assert(part.categoryName == "Resistors");
|
||||
assert(part.image == "/media/part_images/0402.jpg");
|
||||
assert(part.thumbnail == "/media/part_images/0402.thumbnail.jpg");
|
||||
|
||||
// Stock information
|
||||
assert(part.unallocatedStockString == "9000");
|
||||
assert(part.inStockString == "9000");
|
||||
assert(part.inStock > 0);
|
||||
assert(part.unallocatedStock <= part.inStock);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -102,7 +102,7 @@ void main() {
|
||||
|
||||
if (result != null) {
|
||||
InvenTreePart part = result as InvenTreePart;
|
||||
assert(part.name == "M2x4 LPHS");
|
||||
assert(part.name == "R_10R_0402_1%");
|
||||
|
||||
// Change the name to something else
|
||||
|
||||
@@ -115,13 +115,13 @@ void main() {
|
||||
assert(part.name == "Woogle");
|
||||
|
||||
// And change it back again
|
||||
response = await part.update(values: {"name": "M2x4 LPHS"});
|
||||
response = await part.update(values: {"name": "R_10R_0402_1%"});
|
||||
|
||||
assert(response.isValid());
|
||||
assert(response.statusCode == 200);
|
||||
|
||||
assert(await part.reload());
|
||||
assert(part.name == "M2x4 LPHS");
|
||||
assert(part.name == "R_10R_0402_1%");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
+2
-2
@@ -63,8 +63,8 @@ void setupTestEnv() {
|
||||
// Accessors for default testing values
|
||||
const String testServerAddress = "http://localhost:8000/";
|
||||
const String testServerName = "Test Server";
|
||||
const String testUsername = "testuser";
|
||||
const String testPassword = "testpassword";
|
||||
const String testUsername = "admin";
|
||||
const String testPassword = "inventree";
|
||||
|
||||
/*
|
||||
* Request an API token for the given profile
|
||||
|
||||
Reference in new issue
Block a user