Skip to content

Commit cedf3d2

Browse files
Mireille NiwemuhuzaMireille Niwemuhuza
Mireille Niwemuhuza
authored and
Mireille Niwemuhuza
committed
CV3-77-story(base.py): clean up base.py test file
- clean up this file by putting test data in a separate data file that is loaded by base.py [Delivers CV3-77]
1 parent bac40b8 commit cedf3d2

File tree

5 files changed

+212
-194
lines changed

5 files changed

+212
-194
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ virtualenv==15.2.0
3636
Flask-Testing==0.7.1
3737
typing==3.6.4
3838
flake8==3.5.0
39-
coveralls
39+
coveralls==1.8.2
4040
validators==0.12.4

tests/base.py

Lines changed: 14 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,20 @@
55

66
from flask_testing import TestCase
77
from graphene.test import Client
8-
from datetime import datetime
98
from alembic import command, config
109
from unittest.mock import patch
1110

1211
from app import create_app
1312
from schema import schema
1413
from helpers.database import engine, db_session, Base
1514
from api.location.models import Location
16-
from api.room.models import Room
17-
from api.room_resource.models import Resource
1815
from api.user.models import User
1916
from api.role.models import Role
20-
from api.events.models import Events
21-
from api.devices.models import Devices
22-
from api.question.models import Question
23-
from api.response.models import Response
24-
from api.tag.models import Tag
25-
from api.structure.models import Structure
26-
from api.office_structure.models import OfficeStructure
2717
from fixtures.token.token_fixture import (
2818
ADMIN_TOKEN, USER_TOKEN, ADMIN_NIGERIA_TOKEN)
19+
import tests.test_data as test_data
20+
from tests.test_data import save_data
21+
# from tests.save_test_data import save_files_in_database
2922

3023
sys.path.append(os.getcwd())
3124

@@ -51,185 +44,16 @@ def setUp(self, mock_verify_calendar_id):
5144
command.downgrade(self.alembic_configuration, '-1')
5245
command.upgrade(self.alembic_configuration, 'head')
5346

54-
admin_user = User(email="[email protected]",
55-
name="Peter Walugembe",
56-
picture="https://www.andela.com/walugembe")
57-
admin_user.location = "Kampala"
58-
admin_user.save()
59-
lagos_admin = User(email="[email protected]",
60-
location="Lagos", name="Peter Adeoye",
61-
picture="https://www.andela.com/adeoye")
62-
lagos_admin.save()
63-
global role
64-
role = Role(role="Admin")
65-
role.save()
66-
role_2 = Role(role="Test")
67-
role_2.save()
68-
role_3 = Role(role="Super Admin")
69-
role_3.save()
70-
admin_user.roles.append(role)
71-
lagos_admin.roles.append(role)
72-
tag = Tag(name='Block-B',
73-
color='green',
74-
description='The description')
75-
tag.save()
47+
# save test data in the database
48+
49+
save_data(db_session)
50+
# files = ['roles_data.json' , 'users_data.json',
51+
# 'tags_data.json', 'locations_data.json', 'rooms_data.json',
52+
# 'resources_data.json', 'devices_data.json', 'questions_data.json',
53+
# 'events_data.json', 'responses_data.json', 'structures_data.json',
54+
# 'office_structures_data.json']
7655

77-
location = Location(name='Kampala',
78-
abbreviation='KLA')
79-
location.save()
80-
location_two = Location(name='Nairobi',
81-
abbreviation='NBO')
82-
location_two.save()
83-
location_three = Location(name='Lagos',
84-
abbreviation='LOS')
85-
location_three.save()
86-
tag_two = Tag(name='Block-C',
87-
color='blue',
88-
description='The description')
89-
tag_two.save()
90-
room = Room(name='Entebbe',
91-
room_type='meeting',
92-
capacity=6,
93-
location_id=location.id,
94-
structure_id='851ae8b3-48dd-46b5-89bc-ca3f8111ad87',
95-
calendar_id='[email protected]', # noqa: E501
96-
image_url="https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", # noqa: E501
97-
room_labels=["1st Floor", "Wing A"])
98-
room.save()
99-
room.room_tags.append(tag)
100-
room_2 = Room(name='Tana',
101-
room_type='meeting',
102-
capacity=14,
103-
location_id=location.id,
104-
structure_id='851ae8b3-48dd-46b5-89bc-ca3f8111ad87',
105-
calendar_id='[email protected]', # noqa: E501
106-
image_url="https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", # noqa: E501
107-
room_labels=["1st Floor", "Wing B"])
108-
room_2.save()
109-
room_2.room_tags.append(tag)
110-
resource = Resource(name='Markers',
111-
quantity=3)
112-
resource.save()
113-
device = Devices(
114-
last_seen="2018-06-08T11:17:58.785136",
115-
date_added="2018-06-08T11:17:58.785136",
116-
name="Samsung",
117-
location="Kampala",
118-
device_type="External Display",
119-
room_id=1,
120-
state="active"
121-
)
122-
device.save()
123-
question_1 = Question(
124-
question_type="rate",
125-
question_title="Rating Feedback",
126-
question="How will you rate the brightness of the room",
127-
start_date="20 Nov 2018",
128-
end_date="28 Nov 2018",
129-
is_active=True
130-
)
131-
question_1.save()
132-
question_2 = Question(
133-
question_type="check",
134-
question_title="check Feedback",
135-
question="Is there anything missing in the room",
136-
check_options=['apple tv', 'whiteboard', 'maker pen'],
137-
start_date="20 Nov 2018",
138-
end_date="30 Nov 2018",
139-
is_active=True
140-
)
141-
event = Events(
142-
event_id="test_id5",
143-
room_id=1,
144-
event_title="Onboarding",
145-
start_time="2018-07-11T09:00:00Z",
146-
end_time="2018-07-11T09:45:00Z",
147-
number_of_participants=4,
148-
checked_in=False,
149-
cancelled=False)
150-
event.save()
151-
question_2.save()
152-
question_3 = Question(
153-
question_type="input",
154-
question_title="input Feedback",
155-
question="Any other suggestion",
156-
start_date="20 Nov 2018",
157-
end_date="28 Nov 2018"
158-
)
159-
question_3.save()
160-
question_4 = Question(
161-
question_type="check",
162-
question_title="Missing item",
163-
question="Anything missing in the room?",
164-
check_options=['duster'],
165-
start_date="20 Nov 2018",
166-
end_date="30 Nov 2018",
167-
is_active=True
168-
)
169-
question_4.save()
170-
response_1 = Response(
171-
question_id=1,
172-
room_id=1,
173-
question_type="rate",
174-
created_date=datetime.now(),
175-
response="1",
176-
resolved=False,
177-
)
178-
response_1.save()
179-
180-
response_2 = Response(
181-
question_id=question_2.id,
182-
room_id=room.id,
183-
question_type="check",
184-
created_date=datetime.now(),
185-
response=['marker pen', 'apple tv'],
186-
resolved=True,
187-
)
188-
response_2.save()
189-
response_2.missing_resources.append(resource)
190-
191-
response_3 = Response(
192-
question_id=question_4.id,
193-
room_id=room_2.id,
194-
question_type="check",
195-
created_date=datetime.now(),
196-
response=['duster'],
197-
resolved=True,
198-
state="archived"
199-
)
200-
response_3.save()
201-
202-
structure = Structure(
203-
structure_id='b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968',
204-
level=1,
205-
name='Epic tower',
206-
parent_id="1",
207-
parent_title="parent_title",
208-
tag='Building',
209-
location_id=1,
210-
position=1,
211-
)
212-
structure.save()
213-
parent_node = OfficeStructure(
214-
id='C56A4180-65AA-42EC-A945-5FD21DEC0518',
215-
name='Epic Tower',
216-
tag='Lagos Building',
217-
location_id=1
218-
)
219-
parent_node.save()
220-
child_node = OfficeStructure(
221-
id='C56A4180-65AA-42EC-A945-5FD21DEC0519',
222-
name='Gold Coast',
223-
tag='First Floor',
224-
parent_id='C56A4180-65AA-42EC-A945-5FD21DEC0518',
225-
location_id=1
226-
)
227-
child_node.save()
228-
db_session.commit()
229-
f = open('mrm.err.log', 'a+')
230-
f.write('[2019-08-06 13:22:32 +0000] [1574] [ERROR] Error /logs\r')
231-
f.write('Traceback (most recent call last):\r')
232-
f.write('if pattern.search(line):\r')
56+
# save_files_in_database(db_session, files)
23357

23458
def get_admin_location_id(self):
23559
payload = jwt.decode(ADMIN_TOKEN, verify=False)
@@ -366,7 +190,8 @@ def func_wrapper(self):
366190
user = User(email='[email protected]', name='this user',
367191
location="Nairobi", picture='www.andela.com/user')
368192
user.save()
369-
user.roles.append(role)
193+
admin_role = Role.query.filter_by(role='Admin').first()
194+
user.roles.append(admin_role)
370195
db_session().commit()
371196
return headers
372197
return func_wrapper

0 commit comments

Comments
 (0)