wozwize commited on
Commit
d30e475
·
1 Parent(s): 163d201

updating test_supabase, updating dockerfile and requirements.txt

Browse files
Files changed (3) hide show
  1. Dockerfile +1 -2
  2. requirements.txt +1 -0
  3. tests/test_supabase.py +66 -26
Dockerfile CHANGED
@@ -10,9 +10,8 @@ RUN apt-get update && apt-get install -y git
10
  # Create a writable cache directory for Hugging Face
11
  RUN mkdir -p /app/.cache/huggingface/hub && chmod -R 777 /app/.cache
12
 
13
- # Install supabase-py directly from GitHub
14
  RUN pip install --upgrade pip
15
- RUN pip install git+https://github.com/supabase/supabase-py.git
16
 
17
  # Copy dependencies
18
  COPY requirements.txt .
 
10
  # Create a writable cache directory for Hugging Face
11
  RUN mkdir -p /app/.cache/huggingface/hub && chmod -R 777 /app/.cache
12
 
13
+ # Upgrade pip
14
  RUN pip install --upgrade pip
 
15
 
16
  # Copy dependencies
17
  COPY requirements.txt .
requirements.txt CHANGED
@@ -12,4 +12,5 @@ numpy==1.26.3
12
  pytest==7.4.3
13
  pytest-asyncio==0.21.1
14
  httpx==0.25.2
 
15
  configparser>=6.0.0
 
12
  pytest==7.4.3
13
  pytest-asyncio==0.21.1
14
  httpx==0.25.2
15
+ supabase==2.13.0
16
  configparser>=6.0.0
tests/test_supabase.py CHANGED
@@ -1,5 +1,6 @@
1
  import configparser
2
- from supabase import create_client, AsyncClient
 
3
 
4
  # Read the properties file
5
  config = configparser.ConfigParser()
@@ -13,18 +14,65 @@ SUPABASE_KEY = config.get('DEFAULT', 'SUPABASE_KEY')
13
  supabase = AsyncClient(SUPABASE_URL, SUPABASE_KEY)
14
 
15
  # Test data to insert and update
16
- test_url = "https://www.straitstimes.com/world/united-states/us-senate-confirms-trump-loyalist-kash-patel-to-head-fbi"
17
- test_headline = "US Senate confirms Trump loyalist Kash Patel to head FBI"
18
- test_content = "This is some test content for the article."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  # 1. Insert data into the 'article_analysis' table
21
- def insert_data():
 
 
 
 
 
 
 
 
 
 
22
  try:
23
- response = supabase.table('article_analysis').upsert({
 
 
24
  'url': test_url,
 
25
  'headline': test_headline,
26
  'content': test_content,
27
- 'sentiment': 'Neutral',
28
  'bias': 'Neutral',
29
  'bias_score': 0.0,
30
  'bias_percentage': 0.0,
@@ -39,29 +87,16 @@ def insert_data():
39
  'evidence_analysis': {'evidence_based_score': 80.0}
40
  }
41
  }
42
- }).execute()
43
- print("Data inserted successfully")
44
- print(f"Response data: {response.data}")
45
- except Exception as e:
46
- print(f"Error inserting data: {str(e)}")
47
-
48
- # 2. Update data (e.g., changing the sentiment)
49
- def update_data():
50
- try:
51
- updated_sentiment = "Positive"
52
- response = supabase.table('article_analysis').upsert({
53
- 'url': test_url,
54
- 'sentiment': updated_sentiment # Update only the sentiment field
55
- }).execute()
56
  print("Data updated successfully")
57
  print(f"Response data: {response.data}")
58
  except Exception as e:
59
  print(f"Error updating data: {str(e)}")
60
 
61
  # 3. Retrieve data by URL
62
- def retrieve_data():
63
  try:
64
- result = supabase.table('article_analysis').select('*').eq('url', test_url).execute()
65
  if result.data:
66
  print(f"Retrieved data: {result.data}")
67
  else:
@@ -70,6 +105,11 @@ def retrieve_data():
70
  print(f"Error retrieving data: {str(e)}")
71
 
72
  # Run the tests: Insert, Update, and Retrieve data
73
- insert_data()
74
- update_data()
75
- retrieve_data()
 
 
 
 
 
 
1
  import configparser
2
+ import asyncio
3
+ from supabase import AsyncClient
4
 
5
  # Read the properties file
6
  config = configparser.ConfigParser()
 
14
  supabase = AsyncClient(SUPABASE_URL, SUPABASE_KEY)
15
 
16
  # Test data to insert and update
17
+ test_url = "https://apnews.com/article/trump-air-force-one-boeing-plane-355ed87b00d7d82a061297f68c4ed89b"
18
+ test_headline = "Trump says he’s considering buying used planes to serve as Air Force One amid Boeing delays"
19
+ test_content = "WASHINGTON (AP) — President Donald Trump said Wednesday he is considering buying used Boeing aircraft — perhaps from an overseas seller — to use as Air Force One when he’s aboard, as he fumes over the U.S. plane-maker’s delays in producing two specially modified ones for presidential use."
20
+
21
+ # Full test data with all fields
22
+ test_data = {
23
+ "url": test_url,
24
+ "headline": test_headline,
25
+ "content": test_content,
26
+ "sentiment": "Neutral",
27
+ "bias": "Strongly Left",
28
+ "bias_score": -1.0,
29
+ "bias_percentage": 100.0,
30
+ "flagged_phrases": [],
31
+ "media_score": {
32
+ "media_unmasked_score": 49.6,
33
+ "rating": "Misleading",
34
+ "details": {
35
+ "headline_analysis": {
36
+ "headline_vs_content_score": 38.5,
37
+ "contradictory_phrases": []
38
+ },
39
+ "sentiment_analysis": {
40
+ "sentiment": "Neutral",
41
+ "manipulation_score": 0.0,
42
+ "flagged_phrases": []
43
+ },
44
+ "bias_analysis": {
45
+ "bias": "Strongly Left",
46
+ "bias_score": -1.0,
47
+ "bias_percentage": 100.0
48
+ },
49
+ "evidence_analysis": {
50
+ "evidence_based_score": 60.0
51
+ }
52
+ }
53
+ }
54
+ }
55
 
56
  # 1. Insert data into the 'article_analysis' table
57
+ async def insert_data():
58
+ try:
59
+ # Use upsert with conflict on the 'url' field
60
+ response = await supabase.table('article_analysis').upsert(test_data, on_conflict=['url']).execute()
61
+ print("Data inserted or updated successfully")
62
+ print(f"Response data: {response.data}")
63
+ except Exception as e:
64
+ print(f"Error inserting or updating data: {str(e)}")
65
+
66
+ # 2. Update data (e.g., changing the sentiment)
67
+ async def update_data():
68
  try:
69
+ updated_sentiment = "Positive"
70
+ # Ensure that we are not leaving any required fields as null
71
+ response = await supabase.table('article_analysis').upsert({
72
  'url': test_url,
73
+ 'sentiment': updated_sentiment,
74
  'headline': test_headline,
75
  'content': test_content,
 
76
  'bias': 'Neutral',
77
  'bias_score': 0.0,
78
  'bias_percentage': 0.0,
 
87
  'evidence_analysis': {'evidence_based_score': 80.0}
88
  }
89
  }
90
+ }, on_conflict=['url']).execute() # Use on_conflict to handle the conflict by updating the existing URL row
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  print("Data updated successfully")
92
  print(f"Response data: {response.data}")
93
  except Exception as e:
94
  print(f"Error updating data: {str(e)}")
95
 
96
  # 3. Retrieve data by URL
97
+ async def retrieve_data():
98
  try:
99
+ result = await supabase.table('article_analysis').select('*').eq('url', test_url).execute()
100
  if result.data:
101
  print(f"Retrieved data: {result.data}")
102
  else:
 
105
  print(f"Error retrieving data: {str(e)}")
106
 
107
  # Run the tests: Insert, Update, and Retrieve data
108
+ async def run_tests():
109
+ await insert_data()
110
+ await update_data()
111
+ await retrieve_data()
112
+
113
+ # Execute the async function using asyncio
114
+ if __name__ == "__main__":
115
+ asyncio.run(run_tests())