aboutsummaryrefslogtreecommitdiffstats
path: root/servo/tests
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-08-04 10:11:24 +0300
committerFilipp Lepalaan <filipp@mac.com>2015-08-04 10:11:24 +0300
commit63b0fc6269b38edf7234b9f151b80d81f614c0a3 (patch)
tree555de3068f33f8dddb4619349bbea7d9b7c822fd /servo/tests
downloadServo-63b0fc6269b38edf7234b9f151b80d81f614c0a3.tar.gz
Servo-63b0fc6269b38edf7234b9f151b80d81f614c0a3.tar.bz2
Servo-63b0fc6269b38edf7234b9f151b80d81f614c0a3.zip
Initial commit
First public commit
Diffstat (limited to 'servo/tests')
-rw-r--r--servo/tests/__init__.py0
-rw-r--r--servo/tests/create_order.json19
-rw-r--r--servo/tests/test_functional.py135
-rwxr-xr-xservo/tests/test_unit.py66
4 files changed, 220 insertions, 0 deletions
diff --git a/servo/tests/__init__.py b/servo/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/servo/tests/__init__.py
diff --git a/servo/tests/create_order.json b/servo/tests/create_order.json
new file mode 100644
index 0000000..c9baf4d
--- /dev/null
+++ b/servo/tests/create_order.json
@@ -0,0 +1,19 @@
+{
+ "problem": "Problem description goes here",
+ "customer": {
+ "name": "Filipp Lepalaan",
+ "email": "support@servoapp.com",
+ "city": "Helsinki",
+ "zip_code": "00500",
+ "street_address": "Somestreet 19"
+ },
+ "attachment": {
+ "name": "receipt.pdf",
+ "data": "JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvYmoKPDwgL0xlbmd0aCA1IDAgUiAvRmlsdGVyIC9GbGF0ZURlY29kZSA+PgpzdHJlYW0KeAErVAgEAAHnAOMKZW5kc3RyZWFtCmVuZG9iago1IDAgb2JqCjExCmVuZG9iagoyIDAgb2JqCjw8IC9UeXBlIC9QYWdlIC9QYXJlbnQgMyAwIFIgL1Jlc291cmNlcyA2IDAgUiAvQ29udGVudHMgNCAwIFIgL01lZGlhQm94IFswIDAgNTk1ID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wMDAwNDI2IDAwMDAwIG4gCjAwMDAwMDA0NzcgMDAwMDAgbiAKMDAwMDAwMDUxMSAwMDAwMCBuIAowMDAwMDAwNTMwIDAwMDAwIG4gCjAwMDAwMDA1NTcgMDAwMDAgbiAKMDAwMDAwMDU5OSAwMDAwMCBuIAowMDAwMDAwNjE4IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgMTYgL1Jvb3QgNyAwIFIgL0luZm8gMSAwIFIgL0lEIFsgPDRlMGI4Y2UyZmEzNjdkZjU4MThjOGE4ZjBiYTczZDM1Pgo8NGUwYjhjZTJmYTM2N2RmNTgxOGM4YThmMGJhNzNkMzU+IF0gPj4Kc3RhcnR4cmVmCjgxNAolJUVPRgo="
+ },
+ "device": {
+ "sn": "11112222333344445555",
+ "description": "MacBook Pro",
+ "accessories": ["Power adapter"]
+ }
+}
diff --git a/servo/tests/test_functional.py b/servo/tests/test_functional.py
new file mode 100644
index 0000000..b20da20
--- /dev/null
+++ b/servo/tests/test_functional.py
@@ -0,0 +1,135 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2013, First Party Software
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+import os
+import unittest
+from selenium import webdriver
+from selenium.webdriver.common.keys import Keys
+
+
+class NewVisitorTest(unittest.TestCase):
+ def setUp(self):
+ self.url = 'http://localhost:8000/checkin/'
+ self.browser = webdriver.Firefox()
+ self.browser.implicitly_wait(3)
+ self.browser.get(self.url)
+
+ def tearDown(self):
+ self.browser.quit()
+
+ def fill_device_details(self):
+ self.browser.find_element_by_id('id_username').send_keys('username')
+ self.browser.find_element_by_id('id_password').send_keys('password')
+ self.browser.find_element_by_id("id_pop").send_keys("/tmp/image.png")
+
+ def fill_checklist(self):
+ btn = self.browser.find_element_by_class_name('btn-default')
+ btn.click()
+ btn = self.browser.find_element_by_class_name('btn-default')
+ btn.click()
+ btn = self.browser.find_element_by_class_name('btn-default')
+ btn.click()
+
+ def fill_problem_description(self):
+ problem_field = self.browser.find_element_by_id('id_issue_description')
+ problem_field.send_keys("Mary had a little lamb")
+ self.browser.find_element_by_id("id_pop").send_keys("/tmp/image.png")
+
+ def fill_contact_fields(self):
+ field = self.browser.find_element_by_id('id_fname')
+ field.send_keys('Filipp')
+ field = self.browser.find_element_by_id('id_lname')
+ field.send_keys('Lepalaan')
+ field = self.browser.find_element_by_id('id_email')
+ field.send_keys('filipp@mac.com')
+ field = self.browser.find_element_by_id('id_phone')
+ field.send_keys('358451202717')
+ field = self.browser.find_element_by_id('id_city')
+ field.send_keys('Helsinki')
+ field = self.browser.find_element_by_id('id_postal_code')
+ field.send_keys('00500')
+ field = self.browser.find_element_by_id('id_address')
+ field.send_keys('Kustaankatu 2 C 96')
+ field = self.browser.find_element_by_id('id_agree_to_terms')
+ field.click()
+
+ def _test_visitor_can_check_status(self):
+ btn = self.browser.find_element_by_class_name('btn-default')
+ btn.click()
+ field = self.browser.find_element_by_id('id_code')
+ field.send_keys("12019537")
+ field.send_keys(Keys.ENTER)
+ self.assertEqual("Repair Status", self.browser.title)
+
+ def _test_can_checkin_wo_sn(self):
+ self.browser.find_element_by_class_name('btn-primary').click()
+ # customer has no serial number, chooses device
+ self.browser.find_element_by_id('id_choose_device').click()
+ self.browser.find_element_by_id('id_macbookpro').click()
+ self.fill_device_details()
+ self.next()
+ self.fill_problem_description()
+ self.next()
+ #self.fill_checklist()
+ #self.next()
+ self.fill_contact_fields()
+ # Submit the repair
+ self.next()
+ # Check that it actually worked
+ btn = self.browser.find_element_by_class_name('btn-large')
+ self.assertEqual(btn.text, 'Print')
+
+ def test_can_checkin_sn(self):
+ # Customer logs in to check-in
+ self.assertIn('Service Order Check-In', self.browser.title)
+
+ # customer checks warranty status...
+ snfield = self.browser.find_element_by_id('id_sn')
+ snfield.send_keys('C02GV550DJWV')
+ snfield.send_keys(Keys.ENTER)
+ self.fill_device_details()
+
+ # ... enters problem description
+ self.fill_problem_description()
+
+ # Customer fills out her contact details
+ self.fill_contact_fields()
+
+ # Customer fills in the condition
+ field = self.browser.find_element_by_id('id_condition')
+ field.send_keys('Like new')
+
+ # Submit the repair
+ submit_button = self.browser.find_element_by_id('id_btn_submit')
+ submit_button.click()
+
+ # Check that it actually worked
+ btn = self.browser.find_element_by_class_name('btn-large')
+ self.assertEqual(btn.text, 'Print')
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/servo/tests/test_unit.py b/servo/tests/test_unit.py
new file mode 100755
index 0000000..e758798
--- /dev/null
+++ b/servo/tests/test_unit.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2013, First Party Software
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+import unittest
+from django.test import TestCase
+from django.http import HttpRequest
+from django.core.urlresolvers import resolve
+from django.test.simple import DjangoTestSuiteRunner
+
+from servo.views import checkin
+
+
+class NoDbTestRunner(DjangoTestSuiteRunner):
+ """ A test runner to test without database creation """
+
+ def setup_databases(self, **kwargs):
+ """ Override the database creation defined in parent class """
+ pass
+
+ def teardown_databases(self, old_config, **kwargs):
+ """ Override the database teardown defined in parent class """
+ pass
+
+
+class ApiTest(TestCase):
+ pass
+
+
+class CheckinTest(TestCase):
+ def test_checkin_url_resolves(self):
+ found = resolve('/checkin/')
+ self.assertEqual(found.func, checkin.home)
+
+ def test_homepage_error_without_cookies(self):
+ request = HttpRequest()
+ response = checkin.home(request)
+ self.assertTrue(response.content.startswith("<!DOCTYPE html>"), response.content)
+ self.assertIn('<title>An error occurred', response.content)
+ self.assertTrue(response.content.endswith('</html>'))
+
+
+if __name__ == '__main__':
+ unittest.main()