Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Running of Tests On Pull Request #1123

Merged
merged 37 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bc3ac6b
t1
Dec 5, 2024
2e26672
Update test-on-pr.yml
saifrk Dec 5, 2024
e9f4bdb
Fixes #1111
Dec 5, 2024
168eccc
Modifications1
Dec 9, 2024
348a207
Modifications2
Dec 9, 2024
5ee9087
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 9, 2024
74e5130
Mod3
Dec 9, 2024
b1192e5
Mod4
Dec 9, 2024
818158b
new
Dec 10, 2024
8416cc5
new
Dec 10, 2024
aa72027
Merge branch 'feature/add-github-actions' of https://github.com/NASA-…
Dec 10, 2024
07161d7
Merge branch 'dev' of https://github.com/NASA-IMPACT/COSMOS into feat…
Dec 10, 2024
97e7174
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 10, 2024
ce978c5
tst5
Dec 10, 2024
bc961ef
latest
Dec 10, 2024
bba9e0e
changes1
Jan 10, 2025
3d6ae59
changes2
Jan 10, 2025
3cdadf3
changes3
Jan 10, 2025
af8aa3d
changes4
Jan 10, 2025
fa7180c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2025
aec1172
changes5
Jan 10, 2025
5b6b1bd
Merge branch 'feature/add-github-actions' of https://github.com/NASA-…
Jan 10, 2025
0fd2f49
changes6
Jan 10, 2025
3897f3f
changes6.1
Jan 10, 2025
c258803
6.3
Jan 10, 2025
6d0f670
Resolved merge conflicts
Jan 10, 2025
342f7dc
6.4
Jan 10, 2025
30a4354
6.6
Jan 10, 2025
a17e468
6.7
Jan 10, 2025
5ae4b43
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2025
0ab6854
6.8
Jan 10, 2025
d4d8886
Merge branch 'feature/add-github-actions' of https://github.com/NASA-…
Jan 10, 2025
bbe8794
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2025
7db25dc
Update .github/workflows/run_full_test_suite.yml
CarsonDavis Jan 24, 2025
2a92a48
remove extra github mock from test_workflow_status_triggers
CarsonDavis Jan 24, 2025
befc54a
Merge branch 'dev' into feature/add-github-actions
CarsonDavis Jan 24, 2025
22bde3b
add back in saif's magic code
CarsonDavis Jan 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/run_full_test_suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Django Test Suite on PR

on:
pull_request:
branches:
- dev

jobs:
run-tests:
runs-on: ubuntu-latest

services:
docker:
image: docker:24.0.5
options: --privileged
ports:
- 5432:5432

steps:
- name: Check out merged code
uses: actions/checkout@v2

- name: Set up Docker Compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

- name: Build the Docker environment
run: docker-compose -f local.yml build

- name: Run test suite
env:
DJANGO_ENV: test
run: docker-compose -f local.yml run --rm django bash ./init.sh

- name: Cleanup
run: docker-compose -f local.yml down --volumes
31 changes: 31 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
echo "Running all test cases across the project..."

# Initialize a failure counter
failure_count=0

# Exclude tests in `document_classifier` and `functional_tests` directories
excluded_dirs="document_classifier functional_tests"

# Find all test files except those in excluded directories
test_files=$(find . -type f -name "test_*.py" | grep -Ev "$(echo $excluded_dirs | sed 's/ /|/g')")

# Run each test file
for test_file in $test_files; do
echo "Running $test_file..."
pytest "$test_file"

# Check the exit status of pytest
if [ $? -ne 0 ]; then
echo "Test failed: $test_file"
failure_count=$((failure_count + 1))
fi
done

# Report the results
if [ $failure_count -ne 0 ]; then
echo "$failure_count test(s) failed."
exit 1
else
echo "All tests passed successfully!"
fi
12 changes: 0 additions & 12 deletions sde_collections/tests/test_models_collections.py

This file was deleted.

14 changes: 14 additions & 0 deletions sde_collections/tests/test_workflow_status_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ def test_quality_check_perfect_triggers_public_query(self, mock_add):

class TestReindexingStatusTransitions(TestCase):
def setUp(self):
# Mock the GitHubHandler to return valid XML content
self.mock_github_handler = patch("sde_collections.models.collection.GitHubHandler").start()

self.mock_github_handler.return_value._get_file_contents.return_value.decoded_content = (
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b"<Sinequa>\n"
b" <KeepHashFragmentInUrl>false</KeepHashFragmentInUrl>\n"
b" <CollectionSelection>Sample Collection</CollectionSelection>\n"
b"</Sinequa>"
)

self.addCleanup(patch.stopall)

# Create the collection with the mock applied
Comment on lines +66 to +79
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you take a look and see what this chunk of the code is actually doing so that I can understand it better? It doesn't seem like it interacts with the other test cases.

self.collection = CollectionFactory(
workflow_status=WorkflowStatusChoices.QUALITY_CHECK_PERFECT,
reindexing_status=ReindexingStatusChoices.REINDEXING_NOT_NEEDED,
Expand Down
52 changes: 37 additions & 15 deletions sde_indexing_helper/users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from sde_indexing_helper.users.forms import UserAdminChangeForm
from sde_indexing_helper.users.models import User
from sde_indexing_helper.users.tests.factories import UserFactory
from sde_indexing_helper.users.views import (
UserRedirectView,
UserUpdateView,
Expand All @@ -22,39 +21,45 @@

class TestUserUpdateView:
"""
TODO:
extracting view initialization code as class-scoped fixture
would be great if only pytest-django supported non-function-scoped
fixture db access -- this is a work-in-progress for now:
https://github.com/pytest-dev/pytest-django/pull/258
Tests for the UserUpdateView.
"""

def dummy_get_response(self, request: HttpRequest):
@staticmethod
def dummy_get_response(request: HttpRequest):
"""Dummy get_response method for middleware testing."""
return None

def test_get_success_url(self, user: User, rf: RequestFactory):
"""
Test that UserUpdateView redirects to the correct success URL.
"""
view = UserUpdateView()
request = rf.get("/fake-url/")
request.user = user

view.request = request

assert view.get_success_url() == f"/users/{user.username}/"
expected_url = f"/users/{user.username}/"
assert view.get_success_url() == expected_url, f"Expected {expected_url}, got {view.get_success_url()}"

def test_get_object(self, user: User, rf: RequestFactory):
"""
Test that UserUpdateView retrieves the correct user object.
"""
view = UserUpdateView()
request = rf.get("/fake-url/")
request.user = user

view.request = request

assert view.get_object() == user

def test_form_valid(self, user: User, rf: RequestFactory):
"""
Test that form submission in UserUpdateView processes correctly.
"""
view = UserUpdateView()
request = rf.get("/fake-url/")

# Add the session/message middleware to the request
# Add session and message middleware
SessionMiddleware(self.dummy_get_response).process_request(request)
MessageMiddleware(self.dummy_get_response).process_request(request)
request.user = user
Expand All @@ -72,26 +77,43 @@ def test_form_valid(self, user: User, rf: RequestFactory):


class TestUserRedirectView:
"""
Tests for the UserRedirectView.
"""

def test_get_redirect_url(self, user: User, rf: RequestFactory):
"""
Test that UserRedirectView redirects to the "sde_collections:list" URL.
"""
view = UserRedirectView()
request = rf.get("/fake-url")
request = rf.get("/fake-url/")
request.user = user

view.request = request

assert view.get_redirect_url() == f"/users/{user.username}/"
expected_url = reverse("sde_collections:list")
assert view.get_redirect_url() == expected_url, f"Expected {expected_url}, got {view.get_redirect_url()}"


class TestUserDetailView:
"""
Tests for the user_detail_view function.
"""

def test_authenticated(self, user: User, rf: RequestFactory):
"""
Test that an authenticated user can access their detail view.
"""
request = rf.get("/fake-url/")
request.user = UserFactory()
request.user = user

response = user_detail_view(request, username=user.username)

assert response.status_code == 200

def test_not_authenticated(self, user: User, rf: RequestFactory):
"""
Test that an unauthenticated user is redirected to the login page.
"""
request = rf.get("/fake-url/")
request.user = AnonymousUser()

Expand Down
Loading