File size: 22,778 Bytes
cc036ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
"""
Comprehensive database constraint testing covering all database models.

Tests database-level constraints including:
- Unique constraints (email, subdomain, composite keys)
- Not null constraints (required fields)
- Foreign key constraints (referential integrity)
- Check constraints (enum values, range validation)
- JSON field constraints and validations

Purpose: Database constraints are the last line of defense for data integrity.
These tests validate SQLAlchemy configurations match database schema and
constraint behaviors work correctly.

Tests use pytest fixtures for database sessions (db_session from conftest.py)
and Factory Boy factories for test data creation.
"""

import pytest
from datetime import datetime, timedelta
from sqlalchemy.orm import Session
from sqlalchemy.exc import IntegrityError

from tests.factories.user_factory import UserFactory
from tests.factories.workspace_factory import WorkspaceFactory, TeamFactory
from tests.factories.core_factory import (
    TenantFactory,
    UserAccountFactory,
)
from tests.factories.accounting_factory import (
    AccountFactory,
    TransactionFactory,
    JournalEntryFactory,
    EntityFactory,
)
from tests.factories.sales_factory import (
    LeadFactory,
    DealFactory,
)
from tests.factories.service_factory import (
    ProjectFactory,
    MilestoneFactory,
)

from core.models import (
    Workspace,
    Team,
    Tenant,
    User,
    UserAccount,
    UserRole,
    UserStatus,
    WorkspaceStatus,
    AgentStatus,
    TransactionStatus,
    AccountType,
    EntryType,
    EntityType,
)

# ============================================================================
# Unique Constraint Tests
# ============================================================================

class TestUniqueConstraints:
    """Test unique constraints across all models."""

    def test_user_email_unique(self, db_session: Session):
        """Test User.email must be unique (IntegrityError on duplicate)."""
        UserFactory(email="test@example.com", _session=db_session)
        db_session.commit()

        # Attempt to create second user with same email
        with pytest.raises(IntegrityError):
            UserFactory(email="test@example.com", _session=db_session)
            db_session.commit()

        db_session.rollback()

    def test_tenant_subdomain_unique(self, db_session: Session):
        """Test Tenant.subdomain must be unique (IntegrityError on duplicate)."""
        TenantFactory(subdomain="acme", _session=db_session)
        db_session.commit()

        # Attempt duplicate subdomain
        with pytest.raises(IntegrityError):
            TenantFactory(subdomain="acme", _session=db_session)
            db_session.commit()

        db_session.rollback()

    def test_tenant_api_key_unique(self, db_session: Session):
        """Test Tenant.api_key must be unique (when set)."""
        TenantFactory(api_key="sk_test_12345", _session=db_session)
        db_session.commit()

        # Attempt duplicate api_key
        with pytest.raises(IntegrityError):
            TenantFactory(api_key="sk_test_12345", _session=db_session)
            db_session.commit()

        db_session.rollback()

    def test_account_workspace_code_unique(self, db_session: Session):
        """Test Account has composite unique (workspace_id, code)."""
        workspace = WorkspaceFactory(_session=db_session)
        db_session.commit()

        # Create first account with workspace_id=1, code="1000"
        AccountFactory(
            workspace_id=workspace.id,
            code="1000",
            _session=db_session
        )
        db_session.commit()

        # Attempt duplicate with same workspace and code
        with pytest.raises(IntegrityError):
            AccountFactory(
                workspace_id=workspace.id,
                code="1000",  # Same code in same workspace
                _session=db_session
            )
            db_session.commit()

        db_session.rollback()

        # Verify different workspace with same code works
        workspace2 = WorkspaceFactory(_session=db_session)
        AccountFactory(
            workspace_id=workspace2.id,
            code="1000",  # Same code, different workspace
            _session=db_session
        )
        db_session.commit()
        assert db_session.query(AccountFactory._meta.model).count() == 2

    def test_user_account_platform_platform_user_unique(self, db_session: Session):
        """Test UserAccount composite unique (platform, platform_user_id)."""
        user1 = UserFactory(_session=db_session)
        user2 = UserFactory(_session=db_session)
        tenant = TenantFactory(_session=db_session)
        db_session.commit()

        # Create first UserAccount
        UserAccountFactory(
            user_id=user1.id,
            tenant_id=tenant.id,
            platform="telegram",
            platform_user_id="123",
            _session=db_session
        )
        db_session.commit()

        # Attempt duplicate with same platform and platform_user_id (different user)
        with pytest.raises(IntegrityError):
            UserAccountFactory(
                user_id=user2.id,  # Different user
                tenant_id=tenant.id,
                platform="telegram",  # Same platform
                platform_user_id="123",  # Same platform_user_id - violation!
                _session=db_session
            )
            db_session.commit()

        db_session.rollback()

    def test_categorization_rule_workspace_merchant_unique(self, db_session: Session):
        """Test CategorizationRule composite unique (workspace_id, merchant_pattern)."""
        from accounting.models import CategorizationRule

        workspace = WorkspaceFactory(_session=db_session)
        account = AccountFactory(_session=db_session)
        db_session.commit()

        # Create first rule
        rule1 = CategorizationRule(
            id=str(int(1e9)),
            workspace_id=workspace.id,
            merchant_pattern="Amazon",
            target_account_id=account.id,
            confidence_weight=5.0,
            is_active=True
        )
        db_session.add(rule1)
        db_session.commit()

        # Attempt duplicate with same workspace and merchant
        with pytest.raises(IntegrityError):
            rule2 = CategorizationRule(
                id=str(int(1e9 + 1)),
                workspace_id=workspace.id,
                merchant_pattern="Amazon",  # Same merchant in same workspace
                target_account_id=account.id,
                confidence_weight=5.0,
                is_active=True
            )
            db_session.add(rule2)
            db_session.commit()

        db_session.rollback()

    def test_tenant_setting_workspace_key_unique(self, db_session: Session):
        """Test TenantSetting composite unique (tenant_id, setting_key)."""
        from core.models import TenantSetting

        tenant = TenantFactory(_session=db_session)
        db_session.commit()

        # Create first setting
        setting1 = TenantSetting(
            id=str(int(1e9)),
            tenant_id=tenant.id,
            setting_key="theme",
            setting_value="dark"
        )
        db_session.add(setting1)
        db_session.commit()

        # Attempt duplicate with same tenant and key
        with pytest.raises(IntegrityError):
            setting2 = TenantSetting(
                id=str(int(1e9 + 1)),
                tenant_id=tenant.id,
                setting_key="theme",  # Same key for same tenant
                setting_value="light"
            )
            db_session.add(setting2)
            db_session.commit()

        db_session.rollback()


# ============================================================================
# Not Null Constraint Tests
# ============================================================================

class TestNotNullConstraints:
    """Test not null constraints across all models."""

    def test_workspace_name_not_null(self, db_session: Session):
        """Test Workspace.name is required."""
        with pytest.raises(IntegrityError):
            workspace = WorkspaceFactory(name=None, _session=db_session)
            db_session.commit()
        db_session.rollback()

    def test_user_email_not_null(self, db_session: Session):
        """Test User.email is required."""
        with pytest.raises((IntegrityError, ValueError)):
            UserFactory(email=None, _session=db_session)
            db_session.commit()
        db_session.rollback()

    def test_account_type_not_null(self, db_session: Session):
        """Test Account.type enum is required."""
        workspace = WorkspaceFactory(_session=db_session)
        db_session.commit()

        # Account.type is nullable=False with enum
        # Factory should provide valid type by default
        account = AccountFactory(
            workspace_id=workspace.id,
            type=AccountType.ASSET,
            _session=db_session
        )
        db_session.commit()
        assert account.type is not None

    def test_transaction_category_not_null(self, db_session: Session):
        """Test Transaction.category is required (cost attribution enforcement)."""
        workspace = WorkspaceFactory(_session=db_session)
        db_session.commit()

        # Transaction.category is nullable=False for cost attribution
        transaction = TransactionFactory(
            workspace_id=workspace.id,
            category="llm_tokens",
            _session=db_session
        )
        db_session.commit()
        assert transaction.category == "llm_tokens"

    def test_deal_name_not_null(self, db_session: Session):
        """Test Deal.name is required."""
        from sales.models import Deal

        workspace = WorkspaceFactory(_session=db_session)
        db_session.commit()

        # Deal name should be required
        deal = DealFactory(
            workspace_id=workspace.id,
            name="Enterprise Deal",
            _session=db_session
        )
        db_session.commit()
        assert deal.name is not None

    def test_project_name_not_null(self, db_session: Session):
        """Test Project.name is required."""
        from service_delivery.models import Project

        workspace = WorkspaceFactory(_session=db_session)
        db_session.commit()

        # Project name should be required
        project = Project(
            id=str(int(1e9)),
            workspace_id=workspace.id,
            name="Website Redesign",
            planned_start_date=datetime.utcnow(),
            planned_end_date=datetime.utcnow() + timedelta(days=90)
        )
        db_session.add(project)
        db_session.commit()
        assert project.name is not None


# ============================================================================
# Foreign Key Constraint Tests
# ============================================================================

class TestForeignKeyConstraints:
    """Test foreign key relationships and referential integrity.

    Note: SQLite doesn't enforce FK constraints by default.
    These tests verify ORM behavior and relationship configuration.
    """

    def test_workspace_tenant_fk(self, db_session: Session):
        """Test Workspace.tenant_id must reference valid tenant."""
        tenant = TenantFactory(_session=db_session)
        db_session.commit()

        # Valid FK reference
        workspace = WorkspaceFactory(
            tenant_id=tenant.id,
            _session=db_session
        )
        db_session.commit()
        assert workspace.tenant_id == tenant.id

    def test_team_workspace_fk(self, db_session: Session):
        """Test Team.workspace_id must reference valid workspace."""
        workspace = WorkspaceFactory(_session=db_session)
        db_session.commit()

        # Valid FK reference
        team = TeamFactory(
            workspace_id=workspace.id,
            _session=db_session
        )
        db_session.commit()
        assert team.workspace_id == workspace.id

    def test_user_tenant_fk(self, db_session: Session):
        """Test User.tenant_id is nullable but must be valid if set."""
        tenant = TenantFactory(_session=db_session)
        db_session.commit()

        # Valid FK reference
        user = UserFactory(tenant_id=tenant.id, _session=db_session)
        db_session.commit()
        assert user.tenant_id == tenant.id

    def test_transaction_project_fk(self, db_session: Session):
        """Test Transaction.project_id is nullable but must be valid."""
        from service_delivery.models import Project

        workspace = WorkspaceFactory(_session=db_session)
        # Create project directly without factory to avoid field name issues
        project = Project(
            id=str(int(1e9)),
            workspace_id=workspace.id,
            name="Test Project",
            planned_start_date=datetime.utcnow(),
            planned_end_date=datetime.utcnow() + timedelta(days=90)
        )
        db_session.add(project)
        db_session.commit()

        # Valid FK reference
        transaction = TransactionFactory(
            workspace_id=workspace.id,
            project_id=project.id,
            _session=db_session
        )
        db_session.commit()
        assert transaction.project_id == project.id

    def test_bill_vendor_fk(self, db_session: Session):
        """Test Bill.vendor_id must reference valid Entity."""
        from accounting.models import Bill, Entity

        workspace = WorkspaceFactory(_session=db_session)
        vendor = EntityFactory(
            workspace_id=workspace.id,
            type=EntityType.VENDOR,
            _session=db_session
        )
        db_session.commit()

        # Valid FK reference
        bill = Bill(
            id=str(int(1e9)),
            workspace_id=workspace.id,
            vendor_id=vendor.id,
            issue_date=datetime.utcnow(),
            due_date=datetime.utcnow() + timedelta(days=30),
            amount=1500.00
        )
        db_session.add(bill)
        db_session.commit()
        assert bill.vendor_id == vendor.id

    def test_invoice_customer_fk(self, db_session: Session):
        """Test Invoice.customer_id must reference valid Entity."""
        from accounting.models import Invoice, Entity

        workspace = WorkspaceFactory(_session=db_session)
        customer = EntityFactory(
            workspace_id=workspace.id,
            type=EntityType.CUSTOMER,
            _session=db_session
        )
        db_session.commit()

        # Valid FK reference
        invoice = Invoice(
            id=str(int(1e9)),
            workspace_id=workspace.id,
            customer_id=customer.id,
            issue_date=datetime.utcnow(),
            due_date=datetime.utcnow() + timedelta(days=30),
            amount=2500.00
        )
        db_session.add(invoice)
        db_session.commit()
        assert invoice.customer_id == customer.id

    def test_milestone_project_fk(self, db_session: Session):
        """Test Milestone.project_id must reference valid Project."""
        from service_delivery.models import Milestone

        workspace = WorkspaceFactory(_session=db_session)
        project = ProjectFactory(workspace_id=workspace.id, _session=db_session)
        db_session.commit()

        # Valid FK reference
        milestone = MilestoneFactory(
            project_id=project.id,
            _session=db_session
        )
        db_session.commit()
        assert milestone.project_id == project.id


# ============================================================================
# Check Constraint Tests
# ============================================================================

class TestCheckConstraints:
    """Test check constraints and range validation.

    Note: Range validation is typically application-level, not database check.
    These tests verify ORM validation logic.
    """

    def test_agent_confidence_score_range(self, db_session: Session):
        """Test Agent.confidence_score should be 0.0-1.0 (application-level)."""
        from core.models import AgentRegistry, AgentStatus

        # Test valid values at boundaries
        agent1 = AgentRegistry(
            id=str(int(1e9)),
            name="Agent Min",
            category="testing",
            module_path="test.module",
            class_name="TestAgent",
            status=AgentStatus.STUDENT.value,
            confidence_score=0.0  # Minimum valid
        )
        db_session.add(agent1)
        db_session.commit()

        agent2 = AgentRegistry(
            id=str(int(1e9 + 1)),
            name="Agent Mid",
            category="testing",
            module_path="test.module",
            class_name="TestAgent",
            status=AgentStatus.INTERN.value,
            confidence_score=0.5  # Mid range
        )
        db_session.add(agent2)
        db_session.commit()

        agent3 = AgentRegistry(
            id=str(int(1e9 + 2)),
            name="Agent Max",
            category="testing",
            module_path="test.module",
            class_name="TestAgent",
            status=AgentStatus.AUTONOMOUS.value,
            confidence_score=1.0  # Maximum valid
        )
        db_session.add(agent3)
        db_session.commit()

        # Verify all agents created successfully
        agents = db_session.query(AgentRegistry).all()
        assert len(agents) == 3
        assert all(0.0 <= a.confidence_score <= 1.0 for a in agents)

    def test_project_guardrail_thresholds(self, db_session: Session):
        """Test Project budget guardrails: warn < pause < block (application-level)."""
        from service_delivery.models import Project

        workspace = WorkspaceFactory(_session=db_session)

        # Valid guardrail thresholds (using percentage fields)
        project = Project(
            id=str(int(1e9)),
            workspace_id=workspace.id,
            name="Test Project",
            warn_threshold_pct=80,
            pause_threshold_pct=90,
            block_threshold_pct=100,
            planned_start_date=datetime.utcnow(),
            planned_end_date=datetime.utcnow() + timedelta(days=90)
        )
        db_session.add(project)
        db_session.commit()

        # Verify thresholds are ordered correctly
        assert project.warn_threshold_pct < project.pause_threshold_pct
        assert project.pause_threshold_pct < project.block_threshold_pct


# ============================================================================
# Enum Constraint Tests
# ============================================================================

class TestEnumConstraints:
    """Test enum constraints across all models.

    Note: SQLAlchemy enum constraints are enforced at ORM level for SQLite.
    """

    def test_agent_status_enum_valid(self, db_session: Session):
        """Test AgentStatus must use valid enum value."""
        from core.models import AgentRegistry, AgentStatus

        # Test all valid enum values
        for status in AgentStatus:
            agent = AgentRegistry(
                id=str(int(1e9) + hash(status.value)),
                name=f"Agent {status.value}",
                category="testing",
                module_path="test.module",
                class_name="TestAgent",
                status=status.value,
                confidence_score=0.5
            )
            db_session.add(agent)
        db_session.commit()

        # Verify all agents created
        agents = db_session.query(AgentRegistry).filter(
            AgentRegistry.name.like("Agent %")
        ).all()
        assert len(agents) == len(AgentStatus)

    def test_user_role_enum_valid(self, db_session: Session):
        """Test UserRole must use valid enum value."""
        # Test all valid enum values
        for role in UserRole:
            user = UserFactory(
                email=f"user_{role.value}@test.com",
                role=role.value,
                _session=db_session
            )
        db_session.commit()

        # Verify all users created
        users = db_session.query(User).filter(
            User.email.like("user_%@test.com")
        ).all()
        assert len(users) == len(UserRole)

    def test_transaction_status_enum_valid(self, db_session: Session):
        """Test TransactionStatus must use valid enum value."""
        workspace = WorkspaceFactory(_session=db_session)

        # Test all valid enum values
        for status in TransactionStatus:
            transaction = TransactionFactory(
                id=str(int(1e9) + hash(status.value)),
                workspace_id=workspace.id,
                status=status.value,
                _session=db_session
            )
        db_session.commit()

        # Verify all transactions created
        transactions = db_session.query(TransactionFactory._meta.model).filter(
            TransactionFactory._meta.model.workspace_id == workspace.id
        ).all()
        assert len(transactions) == len(TransactionStatus)

    def test_account_type_enum_valid(self, db_session: Session):
        """Test AccountType must use valid enum value."""
        workspace = WorkspaceFactory(_session=db_session)

        # Test all valid enum values
        for account_type in AccountType:
            account = AccountFactory(
                id=str(int(1e9) + hash(account_type.value)),
                workspace_id=workspace.id,
                type=account_type.value,
                _session=db_session
            )
        db_session.commit()

        # Verify all accounts created
        from accounting.models import Account
        accounts = db_session.query(Account).filter(
            Account.workspace_id == workspace.id
        ).all()
        assert len(accounts) == len(AccountType)

    def test_project_status_enum_valid(self, db_session: Session):
        """Test ProjectStatus must use valid enum value."""
        from service_delivery.models import Project, ProjectStatus

        workspace = WorkspaceFactory(_session=db_session)

        # Test all valid enum values
        for status in ProjectStatus:
            project = Project(
                id=str(int(1e9) + hash(status.value)),
                workspace_id=workspace.id,
                name=f"Project {status.value}",
                status=status.value,
                planned_start_date=datetime.utcnow(),
                planned_end_date=datetime.utcnow() + timedelta(days=90)
            )
            db_session.add(project)
        db_session.commit()

        # Verify all projects created
        projects = db_session.query(Project).filter(
            Project.workspace_id == workspace.id
        ).all()
        assert len(projects) == len(ProjectStatus)