Skip to content

Commit 5a1a021

Browse files
committed
Fixes tests
1 parent fb11196 commit 5a1a021

File tree

6 files changed

+45
-26
lines changed

6 files changed

+45
-26
lines changed

photonix/classifiers/runners.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def get_or_create_tag(library, name, type, source, parent=None, ordering=None):
1919
return tag
2020

2121

22-
def get_photo_by_any_type(photo_id):
22+
def get_photo_by_any_type(photo_id, model=None):
2323
is_photo_instance = False
2424
photo = None
2525

@@ -33,7 +33,7 @@ def get_photo_by_any_type(photo_id):
3333

3434
# Is an individual filename so return the prediction
3535
if not is_photo_instance:
36-
return None, model.predict(photo_id)
36+
return None
3737

3838
# Is a Photo model instance so needs saving
3939
if not photo:
@@ -50,6 +50,9 @@ def get_photo_by_any_type(photo_id):
5050

5151

5252
def results_for_model_on_photo(model, photo_id):
53-
photo = get_photo_by_any_type(photo_id)
54-
results = model.predict(photo.base_image_path)
53+
photo = get_photo_by_any_type(photo_id, model)
54+
if photo:
55+
results = model.predict(photo.base_image_path)
56+
else:
57+
results = model.predict(photo_id)
5558
return photo, results

tests/factories.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ class Meta:
2424
model = Library
2525

2626
name = factory.Sequence(lambda n: f'Test Library {n}')
27+
classification_color_enabled = True
2728
classification_location_enabled = True
29+
classification_style_enabled = True
2830
classification_object_enabled = True
2931
classification_face_enabled = True
32+
setup_stage_completed = True
33+
3034

3135
class LibraryUserFactory(factory.django.DjangoModelFactory):
3236
class Meta:
@@ -36,6 +40,7 @@ class Meta:
3640
user = factory.SubFactory(UserFactory)
3741
owner = True
3842

43+
3944
class PhotoFactory(factory.django.DjangoModelFactory):
4045
class Meta:
4146
model = Photo
@@ -76,3 +81,4 @@ class Meta:
7681

7782
type = 'classify.style'
7883
status = 'P'
84+
library = factory.SubFactory(LibraryFactory)

tests/test_classifier_batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_classifier_batch():
2222
photo = PhotoFactory()
2323
PhotoFileFactory(photo=photo)
2424

25-
for i in range(4):
25+
for _ in range(4):
2626
TaskFactory(subject_id=photo.id)
2727

2828
start = time()

tests/test_graphql.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def test_library_setting_data(self):
193193
classificationStyleEnabled
194194
classificationObjectEnabled
195195
classificationLocationEnabled
196+
classificationFaceEnabled
196197
}
197198
sourceFolder
198199
}
@@ -202,14 +203,15 @@ def test_library_setting_data(self):
202203
data = get_graphql_content(response)
203204
assert response.status_code == 200
204205
self.assertEqual(data['data']['librarySetting']['library']['name'], self.defaults['library'].name)
205-
self.assertFalse(data['data']['librarySetting']['library']['classificationColorEnabled'])
206-
self.assertFalse(data['data']['librarySetting']['library']['classificationStyleEnabled'])
207-
assert data['data']['librarySetting']['library']['classificationObjectEnabled']
208-
assert data['data']['librarySetting']['library']['classificationLocationEnabled']
206+
self.assertTrue(data['data']['librarySetting']['library']['classificationColorEnabled'])
207+
self.assertTrue(data['data']['librarySetting']['library']['classificationStyleEnabled'])
208+
self.assertTrue(data['data']['librarySetting']['library']['classificationObjectEnabled'])
209+
self.assertTrue(data['data']['librarySetting']['library']['classificationLocationEnabled'])
210+
self.assertTrue(data['data']['librarySetting']['library']['classificationFaceEnabled'])
209211
self.assertEqual(data['data']['librarySetting']['sourceFolder'], self.defaults['library'].paths.all()[0].path)
210212

211-
def test_library_update_style_enabled_mutaion(self):
212-
"""Test library updateStyleEnabled mutaion response."""
213+
def test_library_update_style_enabled_mutation(self):
214+
"""Test library updateStyleEnabled mutation response."""
213215
mutation = """
214216
mutation updateStyleEnabled(
215217
$classificationStyleEnabled: Boolean!
@@ -230,8 +232,8 @@ def test_library_update_style_enabled_mutaion(self):
230232
assert response.status_code == 200
231233
assert tuple(tuple(data.values())[0].values())[0].get('classificationStyleEnabled')
232234

233-
def test_library_update_color_enabled_mutaion(self):
234-
"""Test library updateColorEnabled mutaion response."""
235+
def test_library_update_color_enabled_mutation(self):
236+
"""Test library updateColorEnabled mutation response."""
235237
mutation = """
236238
mutation updateColorEnabled(
237239
$classificationColorEnabled: Boolean!
@@ -252,8 +254,8 @@ def test_library_update_color_enabled_mutaion(self):
252254
assert response.status_code == 200
253255
assert tuple(tuple(data.values())[0].values())[0].get('classificationColorEnabled')
254256

255-
def test_library_update_location_enabled_mutaion(self):
256-
"""Test library updateLocationEnabled mutaion response."""
257+
def test_library_update_location_enabled_mutation(self):
258+
"""Test library updateLocationEnabled mutation response."""
257259
mutation = """
258260
mutation updateLocationEnabled(
259261
$classificationLocationEnabled: Boolean!
@@ -274,8 +276,8 @@ def test_library_update_location_enabled_mutaion(self):
274276
assert response.status_code == 200
275277
self.assertFalse(tuple(tuple(data.values())[0].values())[0].get('classificationLocationEnabled'))
276278

277-
def test_library_update_object_enabled_mutaion(self):
278-
"""Test library updateObjectEnabled mutaion response."""
279+
def test_library_update_object_enabled_mutation(self):
280+
"""Test library updateObjectEnabled mutation response."""
279281
mutation = """
280282
mutation updateObjectEnabled(
281283
$classificationObjectEnabled: Boolean!
@@ -296,8 +298,8 @@ def test_library_update_object_enabled_mutaion(self):
296298
assert response.status_code == 200
297299
self.assertFalse(tuple(tuple(data.values())[0].values())[0].get('classificationObjectEnabled'))
298300

299-
def test_library_update_source_folder_mutaion(self):
300-
"""Test library updateSourceFolder mutaion response."""
301+
def test_library_update_source_folder_mutation(self):
302+
"""Test library updateSourceFolder mutation response."""
301303
mutation = """
302304
mutation updateSourceFolder($sourceFolder: String!, $libraryId: ID) {
303305
updateSourceFolder(
@@ -313,7 +315,7 @@ def test_library_update_source_folder_mutaion(self):
313315
self.assertEqual(tuple(tuple(data.values())[0].values())[0].get('sourceFolder'),self.defaults['library'].paths.all()[0].path)
314316

315317
def test_change_password_mutation(self):
316-
"""Test change password mutaion response."""
318+
"""Test change password mutation response."""
317319
mutation = """
318320
mutation changePassword (
319321
$oldPassword: String!,
@@ -831,15 +833,20 @@ def test_onboarding_steps(self):
831833
assert User.objects.first().has_configured_importing
832834
self.assertFalse(User.objects.first().has_configured_image_analysis)
833835
mutation = """
834-
mutation ($classificationColorEnabled: Boolean!,$classificationStyleEnabled: Boolean!,
835-
$classificationObjectEnabled: Boolean!,$classificationLocationEnabled: Boolean!,
836+
mutation (
837+
$classificationColorEnabled: Boolean!,
838+
$classificationStyleEnabled: Boolean!,
839+
$classificationObjectEnabled: Boolean!,
840+
$classificationLocationEnabled: Boolean!,
841+
$classificationFaceEnabled: Boolean!,
836842
$userId: ID!,$libraryId: ID!,
837843
) {
838844
imageAnalysis(input:{
839845
classificationColorEnabled:$classificationColorEnabled,
840846
classificationStyleEnabled:$classificationStyleEnabled,
841847
classificationObjectEnabled:$classificationObjectEnabled,
842848
classificationLocationEnabled:$classificationLocationEnabled,
849+
classificationFaceEnabled:$classificationFaceEnabled,
843850
userId:$userId,
844851
libraryId:$libraryId,
845852
}) {
@@ -851,8 +858,11 @@ def test_onboarding_steps(self):
851858
library_id = data['data']['PhotoImporting']['libraryId']
852859
response = self.api_client.post_graphql(
853860
mutation, {
854-
'classificationColorEnabled': True, 'classificationStyleEnabled': True,
855-
'classificationObjectEnabled': False, 'classificationLocationEnabled': False,
861+
'classificationColorEnabled': True,
862+
'classificationStyleEnabled': True,
863+
'classificationObjectEnabled': False,
864+
'classificationLocationEnabled': False,
865+
'classificationFaceEnabled': False,
856866
'userId': data['data']['PhotoImporting']['userId'],
857867
'libraryId': data['data']['PhotoImporting']['libraryId'],
858868
})

tests/test_task_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_tasks_created_updated(photo_fixture_snow):
7474
process_classify_images_tasks()
7575
task = Task.objects.get(type='classify_images', subject_id=photo_fixture_snow.id)
7676
assert task.status == 'S'
77-
assert task.children.count() == 4
77+
assert task.children.count() == 6
7878
assert task.complete_with_children == True
7979

8080
# Completing all the child processes should set the parent task to completed

tests/test_thumbnails.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_view(photo_fixture_snow):
5959
# Now we should get the actual thumbnail image file
6060
assert response.status_code == 200
6161
assert response.content[:10] == b'\xff\xd8\xff\xe0\x00\x10JFIF'
62-
assert response._headers['content-type'][1] == 'image/jpeg'
62+
assert response.headers['Content-Type'] == 'image/jpeg'
6363
response_length = len(response.content)
6464
assert response_length > 5929 * 0.8
6565
assert response_length < 5929 * 1.2

0 commit comments

Comments
 (0)