• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gcivil-nyu-org / Wednesday-Fall2023-Team-1 / #614980386

13 Dec 2023 12:50AM UTC coverage: 86.973%. First build
#614980386

Pull #257

travis-ci

Pull Request #257: Final sprint

702 of 804 new or added lines in 23 files covered. (87.31%)

1382 of 1589 relevant lines covered (86.97%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.96
/vibematch/tests/test_vibe_match.py
1
import os
1✔
2
import pandas as pd
1✔
3
from django.conf import settings
1✔
4
from django.test import TestCase, RequestFactory
1✔
5
from django.urls import reverse
1✔
6
from django.contrib.messages.storage.fallback import FallbackStorage
1✔
7
from unittest.mock import patch
1✔
8
from dashboard.models import EmotionVector
1✔
9
from user_profile.models import Vibe, User
1✔
10
from vibematch.views import vibe_match
1✔
11
import json
1✔
12

13
# Mock data and functions
14
mock_user_info = {"id": "31riwbvwvrsgadgrerv6llzlmbpi", "display_name": "boyan"}
1✔
15
mock_spotify_data = {
1✔
16
    "track": {},
17
    "tracks": {},
18
    "artists": {},
19
}  # Mock responses for Spotify API calls
20

21

22
def mock_get_spotify_token(*args, **kwargs):
1✔
NEW
23
    return {"access_token": "test_token"}
×
24

25

26
class VibeMatchTests(TestCase):
1✔
27
    def setUp(self):
1✔
28
        # Assuming 'assets_path' is defined and points to the directory containing the CSV files
29
        assets_path = os.path.join(settings.BASE_DIR, "assets")
1✔
30

31
        # Constructing file paths
32
        emotionvector_file_path = os.path.join(
1✔
33
            assets_path, "test_dashboard_emotionvector_rows.csv"
34
        )
35
        vibe_file_path = os.path.join(assets_path, "test_user_profile_vibe_rows.csv")
1✔
36
        user_file_path = os.path.join(assets_path, "test_user_profile_user_rows.csv")
1✔
37

38
        # Loading the data from CSV files into pandas dataframes
39
        emotionvector_df = pd.read_csv(emotionvector_file_path)
1✔
40
        vibe_df = pd.read_csv(vibe_file_path)
1✔
41
        user_df = pd.read_csv(user_file_path)
1✔
42

43
        # Displaying the first few rows of each dataframe for inspection
44
        emotionvector_df.head(), vibe_df.head()
1✔
45

46
        self.factory = RequestFactory()
1✔
47
        # Load EmotionVector data
48
        for _, row in emotionvector_df.iterrows():
1✔
49
            EmotionVector.objects.create(emotion=row["emotion"], vector=row["vector"])
1✔
50

51
        # Load Vibe data
52
        for _, row in vibe_df.iterrows():
1✔
53
            Vibe.objects.create(
1✔
54
                user_id=row["user_id"],
55
                user_lyrics_vibe=row["user_lyrics_vibe"],
56
                user_audio_vibe=row["user_audio_vibe"],
57
                user_acousticness=row["user_acousticness"],
58
                user_danceability=row["user_danceability"],
59
                user_energy=row["user_energy"],
60
                user_valence=row["user_valence"],
61
                recent_track=json.loads(row["recent_track"].replace("'", '"')),
62
                vibe_time=pd.to_datetime(row["vibe_time"]),
63
                description=row["description"],
64
            )
65

66
        # Load User data
67
        for _, row in user_df.iterrows():
1✔
68
            if not User.objects.filter(username=row["username"]).exists():
1✔
69
                User.objects.create(
1✔
70
                    username=row["username"],
71
                    user_id=row["user_id"],
72
                    total_followers=row["total_followers"],
73
                    profile_image_url=row["profile_image_url"],
74
                    user_country=row["user_country"],
75
                    user_last_login=row["user_last_login"],
76
                    user_bio=row["user_bio"],
77
                    user_city=row["user_city"],
78
                    user_total_friends=0,
79
                    track_id=row["track_id"],
80
                )
81

82
    def _add_messages_storage_to_request(self, request):
1✔
83
        setattr(request, "session", "session")
1✔
84
        messages = FallbackStorage(request)
1✔
85
        setattr(request, "_messages", messages)
1✔
86
        return request
1✔
87

88
    @patch("spotipy.Spotify")
1✔
89
    def test_vibe_match_success(self, MockSpotify):
1✔
90
        mock_sp = MockSpotify()
1✔
91
        mock_sp.current_user.return_value = mock_user_info
1✔
92
        mock_sp.track.side_effect = lambda track_id: {"id": track_id}  # Mock track data
1✔
93
        mock_sp.artists.side_effect = lambda artist_ids: {
1✔
94
            "ids": artist_ids
95
        }  # Mock artist data
96

97
        request = self.factory.get(reverse("vibematch:vibe_match"))
1✔
98
        request = self._add_messages_storage_to_request(request)
1✔
99
        request.user = User.objects.get(user_id="31riwbvwvrsgadgrerv6llzlmbpi")
1✔
100
        response = vibe_match(request)
1✔
101

102
        self.assertEqual(response.status_code, 200)
1✔
103
        # Assertions to check the response content
104
        # e.g., self.assertIn("neighbors", response.context)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc